CMS 3D CMS Logo

FWTabularWidget.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TableWidget
4 // Class : FWTabularWidget
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Mon Feb 2 16:45:21 EST 2009
11 //
12 
13 // system include files
14 #include <cassert>
15 #include <climits>
16 #include <iostream>
17 #include "TGResourcePool.h"
18 
19 // user include files
23 
24 //
25 // constants, enums and typedefs
26 //
27 
28 //
29 // static data member definitions
30 //
31 
32 const int FWTabularWidget::kTextBuffer = 2;
34 
35 //
36 // constructors and destructor
37 //
38 FWTabularWidget::FWTabularWidget(FWTableManagerBase* iTable, const TGWindow* p, GContext_t context)
39  : TGFrame(p),
40  m_table(iTable),
41  m_widthOfTextInColumns(m_table->numberOfColumns(), static_cast<unsigned int>(0)),
42  m_vOffset(0),
43  m_hOffset(0),
44  m_normGC(context),
45  m_backgroundGC(ULONG_MAX),
46  m_growInWidth(true) {
47  m_textHeight = iTable->cellHeight();
49 
51  for (std::vector<unsigned int>::const_iterator it = m_widthOfTextInColumns.begin(),
52  itEnd = m_widthOfTextInColumns.end();
53  it != itEnd;
54  ++it) {
55  m_tableWidth += *it;
56  }
57  Resize();
58 
59  gVirtualX->GrabButton(fId, kAnyButton, kAnyModifier, kButtonPressMask | kButtonReleaseMask, kNone, kNone);
60  m_table->Connect("visualPropertiesChanged()", "FWTabularWidget", this, "needToRedraw()");
61 }
62 
63 // FWTabularWidget::FWTabularWidget(const FWTabularWidget& rhs)
64 // {
65 // // do actual copying here;
66 // }
67 
68 FWTabularWidget::~FWTabularWidget() { m_table->Disconnect("visualPropertiesChanged()", this, "needToRedraw()"); }
69 
70 //
71 // assignment operators
72 //
73 // const FWTabularWidget& FWTabularWidget::operator=(const FWTabularWidget& rhs)
74 // {
75 // //An exception safe implementation is
76 // FWTabularWidget temp(rhs);
77 // swap(rhs);
78 //
79 // return *this;
80 // }
81 
82 //
83 // member functions
84 //
88 }
89 
90 void FWTabularWidget::needToRedraw() { fClient->NeedRedraw(this); }
91 
92 void FWTabularWidget::setWidthOfTextInColumns(const std::vector<unsigned int>& iNew) {
93  assert(iNew.size() == static_cast<unsigned int>(m_table->numberOfColumns()));
94 
96  if (m_growInWidth) {
97  // with of columns grow to prevent resizing/flickering on next event
98  m_widthOfTextInColumnsMax.resize(iNew.size());
99  std::vector<unsigned int>::iterator k = m_widthOfTextInColumnsMax.begin();
100  for (std::vector<unsigned int>::iterator it = m_widthOfTextInColumns.begin(); it != m_widthOfTextInColumns.end();
101  ++it, ++k) {
102  if (*it < *k)
103  *it = *k;
104  else
105  *k = *it;
106  }
107  }
108 
109  m_tableWidth = 0;
110  for (std::vector<unsigned int>::const_iterator it = m_widthOfTextInColumns.begin(),
111  itEnd = m_widthOfTextInColumns.end();
112  it != itEnd;
113  ++it) {
115  }
117 }
118 
120  if (iV != m_vOffset) {
121  m_vOffset = iV;
122  fClient->NeedRedraw(this);
123  }
124 }
126  if (iH != m_hOffset) {
127  m_hOffset = iH;
128  fClient->NeedRedraw(this);
129  }
130 }
131 
133  if (event->fType == kButtonPress) {
134  Int_t row, col, relX, relY;
135  translateToRowColumn(event->fX, event->fY, row, col, relX, relY);
136  //std::cout <<"Press: "<<relX<<" "<<relY<<" "<<row<<" "<<col<<" "<<m_table->numberOfRows()<<" "<<m_table->numberOfColumns()<<std::endl;
137  if (row >= 0 && row < m_table->numberOfRows() && col >= 0 && col < m_table->numberOfColumns()) {
138  FWTableCellRendererBase* renderer = m_table->cellRenderer(row, col);
139  if (renderer) {
140  renderer->buttonEvent(event, relX, relY);
141  }
142  buttonPressed(row, col, event, relX, relY);
143  }
144  return true;
145  }
146  if (event->fType == kButtonRelease) {
147  Int_t row, col, relX, relY;
148  translateToRowColumn(event->fX, event->fY, row, col, relX, relY);
149  //std::cout <<"Release: "<<relX<<" "<<relY<<" "<<row<<" "<<col<<" "<<m_table->numberOfRows()<<" "<<m_table->numberOfColumns()<<std::endl;
150  if (row >= 0 && row < m_table->numberOfRows() && col >= 0 && col < m_table->numberOfColumns()) {
151  FWTableCellRendererBase* renderer = m_table->cellRenderer(row, col);
152  if (renderer) {
153  renderer->buttonEvent(event, relX, relY);
154  }
155  buttonReleased(row, col, event, relX, relY);
156  }
157  return true;
158  }
159  return false;
160 }
161 
163  Int_t iX, Int_t iY, Int_t& oRow, Int_t& oCol, Int_t& oRelX, Int_t& oRelY) const {
164  if (iX < 0) {
165  oCol = -1;
166  oRelX = 0;
167  } else {
168  if (iX + static_cast<Int_t>(m_hOffset) > static_cast<Int_t>(m_tableWidth)) {
169  oCol = m_widthOfTextInColumns.size();
170  oRelX = 0;
171  } else {
172  iX += m_hOffset;
173  oCol = 0;
174  for (std::vector<unsigned int>::const_iterator it = m_widthOfTextInColumns.begin(),
175  itEnd = m_widthOfTextInColumns.end();
176  it != itEnd;
177  ++it, ++oCol) {
178  oRelX = iX - kTextBuffer;
179  iX -= 2 * kTextBuffer + kSeperatorWidth + *it;
180  if (iX <= 0) {
181  break;
182  }
183  }
184  }
185  }
186  if (iY < 0) {
187  oRow = -1;
188  oRelY = 0;
189  } else {
190  oRow = (int)(float(iY + m_vOffset) / (m_textHeight + 2 * kTextBuffer + kSeperatorWidth));
191  oRelY = iY - oRow * (m_textHeight + 2 * kTextBuffer + kSeperatorWidth) + m_vOffset - kTextBuffer;
192  Int_t numRows = m_table->numberOfRows();
193  if (oRow > numRows) {
194  oRow = numRows;
195  oRelY = 0;
196  }
197  }
198 }
199 
200 void FWTabularWidget::buttonPressed(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY) {
201  //std::cout <<"buttonPressed "<<row<<" "<<column<<std::endl;
202  Long_t args[5];
203  args[0] = (Long_t)row;
204  args[1] = (Long_t)column;
205  args[2] = (Long_t)event;
206  args[3] = (Long_t)relX;
207  args[4] = (Long_t)relY;
208  Emit("buttonPressed(Int_t,Int_t,Event_t*,Int_t,Int_t)", args);
209 }
210 void FWTabularWidget::buttonReleased(Int_t row, Int_t column, Event_t* event, Int_t relX, Int_t relY) {
211  //std::cout <<"buttonReleased "<<row<<" "<<column<<std::endl;
212  Long_t args[6];
213  args[0] = (Long_t)row;
214  args[1] = (Long_t)column;
215  args[2] = (Long_t)event;
216  args[3] = (Long_t)relX;
217  args[4] = (Long_t)relY;
218  Emit("buttonReleased(Int_t,Int_t,Event_t*,Int_t,Int_t)", args);
219 }
220 
222  TGFrame::DoRedraw();
223 
224  //std::cout <<"DoRedraw "<<m_tableWidth<<std::endl;
225 
226  const int yOrigin = -m_vOffset;
227  const int xOrigin = -m_hOffset;
228  const int visibleWidth = m_tableWidth + xOrigin - kSeperatorWidth;
229  int y = yOrigin;
230  if (m_backgroundGC != ULONG_MAX) {
231  gVirtualX->FillRectangle(fId, m_backgroundGC, xOrigin, y, m_tableWidth, GetHeight());
232  }
233  gVirtualX->DrawLine(fId, m_normGC, xOrigin, y, visibleWidth, y);
234  //Draw data
235  const int numRows = m_table->numberOfRows();
236 
237  //figure out which rows and columns are visible
238  Int_t startRow, startColumn, relX, relY;
239  translateToRowColumn(0, 0, startRow, startColumn, relX, relY);
240  if (startRow < 0) {
241  startRow = 0;
242  }
243  if (startColumn < 0) {
244  startColumn = 0;
245  }
246  Int_t endRow, endColumn;
247  translateToRowColumn(GetWidth(), GetHeight(), endRow, endColumn, relX, relY);
248  if (endRow >= numRows) {
249  endRow = numRows - 1;
250  }
251  if (endColumn >= static_cast<Int_t>(m_widthOfTextInColumns.size())) {
252  endColumn = m_widthOfTextInColumns.size() - 1;
253  }
254  //std::cout <<"start "<<startRow<<" "<<startColumn<<" end "<<endRow<<" "<<endColumn<<std::endl;
255 
256  //calculate offset for rows and columns
257  Int_t rowOffset = (kSeperatorWidth + 2 * kTextBuffer + m_textHeight) * startRow;
258  Int_t columnOffset = kSeperatorWidth + kTextBuffer + xOrigin;
259  for (std::vector<unsigned int>::iterator itTextWidth = m_widthOfTextInColumns.begin(),
260  itEnd = m_widthOfTextInColumns.begin() + startColumn;
261  itTextWidth != itEnd;
262  ++itTextWidth) {
263  columnOffset += *itTextWidth + kTextBuffer + kSeperatorWidth + kTextBuffer;
264  }
265 
266  y += rowOffset;
267  for (int row = startRow; row <= endRow; ++row) {
268  std::vector<unsigned int>::iterator itTextWidth = m_widthOfTextInColumns.begin() + startColumn;
269  //int x=kSeperatorWidth+kTextBuffer+xOrigin;
270  int x = columnOffset;
272  for (int col = startColumn; col <= endColumn; ++col, ++itTextWidth) {
273  m_table->cellRenderer(row, col)->draw(fId, x, y, *itTextWidth, m_textHeight);
274  //UInt_t textWidth = font->TextWidth(itData->c_str(),-1);
275  x += *itTextWidth + kTextBuffer + kSeperatorWidth + kTextBuffer;
276  }
277  y += +m_textHeight + kTextBuffer;
278  gVirtualX->DrawLine(fId, m_normGC, xOrigin, y, visibleWidth, y);
279  }
280 
281  //draw column separators
282  int x = xOrigin;
283  gVirtualX->DrawLine(fId, m_normGC, x, 0, x, y);
284  x += kSeperatorWidth;
285  for (std::vector<unsigned int>::iterator itTextWidth = m_widthOfTextInColumns.begin();
286  itTextWidth != m_widthOfTextInColumns.end();
287  ++itTextWidth) {
288  x += 2 * kTextBuffer + *itTextWidth;
289  gVirtualX->DrawLine(fId, m_normGC, x, 0, x, y);
290  x += kSeperatorWidth;
291  }
292 }
293 
294 void FWTabularWidget::setLineContext(GContext_t iContext) { m_normGC = iContext; }
295 void FWTabularWidget::setBackgroundAreaContext(GContext_t iContext) { m_backgroundGC = iContext; }
296 
297 //
298 // const member functions
299 //
300 TGDimension FWTabularWidget::GetDefaultSize() const {
301  // returns default size
302 
303  UInt_t w = fWidth;
304  if (!(GetOptions() & kFixedWidth)) {
305  w = m_tableWidth;
306  }
307  UInt_t h = fHeight;
308  if (!(GetOptions() & kFixedHeight)) {
309  unsigned int numRows = m_table->numberOfRows();
310 
311  h = kSeperatorWidth + (m_textHeight + 2 * kTextBuffer + kSeperatorWidth) * (numRows);
312  }
313  return TGDimension(w, h);
314 }
315 
316 //
317 // static member functions
318 //
320  static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
321  return *s_default;
322 }
323 
FWTableManagerBase::cellRenderer
virtual FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const =0
writedatasetfile.args
args
Definition: writedatasetfile.py:18
FWTabularWidget::m_normGC
GContext_t m_normGC
Definition: FWTabularWidget.h:89
DDAxes::y
FWTabularWidget::buttonPressed
void buttonPressed(Int_t row, Int_t column, Event_t *event, Int_t relX, Int_t relY)
Definition: FWTabularWidget.cc:200
FWTabularWidget::m_widthOfTextInColumnsMax
std::vector< unsigned int > m_widthOfTextInColumnsMax
Definition: FWTabularWidget.h:82
FWTabularWidget::dataChanged
void dataChanged()
Definition: FWTabularWidget.cc:85
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
FWTabularWidget::setVerticalOffset
void setVerticalOffset(UInt_t)
Definition: FWTabularWidget.cc:119
cuy.col
col
Definition: cuy.py:1010
cms::cuda::assert
assert(be >=bs)
DDAxes::x
FWTableManagerBase::numberOfRows
virtual int numberOfRows() const =0
Number of rows in the table.
FWTabularWidget::setWidthOfTextInColumns
void setWidthOfTextInColumns(const std::vector< unsigned int > &)
Definition: FWTabularWidget.cc:92
FWTabularWidget::kTextBuffer
static const int kTextBuffer
Definition: FWTabularWidget.h:35
FWTabularWidget::setHorizontalOffset
void setHorizontalOffset(UInt_t)
Definition: FWTabularWidget.cc:125
FWTableCellRendererBase::draw
virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)=0
FWTabularWidget::GetDefaultSize
TGDimension GetDefaultSize() const override
Definition: FWTabularWidget.cc:300
ClassImp
ClassImp(FWTabularWidget)
w
const double w
Definition: UKUtility.cc:23
FWTabularWidget::m_textHeight
int m_textHeight
Definition: FWTabularWidget.h:83
FWTabularWidget::HandleButton
Bool_t HandleButton(Event_t *event) override
Definition: FWTabularWidget.cc:132
h
dqmdumpme.k
k
Definition: dqmdumpme.py:60
FWTabularWidget::m_table
FWTableManagerBase * m_table
Definition: FWTabularWidget.h:80
FWTabularWidget::setBackgroundAreaContext
void setBackgroundAreaContext(GContext_t iContext)
Definition: FWTabularWidget.cc:295
FWTableManagerBase
Definition: FWTableManagerBase.h:44
funct::true
true
Definition: Factorize.h:173
FWTabularWidget::setLineContext
void setLineContext(GContext_t iContext)
Definition: FWTabularWidget.cc:294
hcaldqm::fClient
Definition: DQModule.h:24
FWTabularWidget.h
FWTabularWidget::kSeperatorWidth
static const int kSeperatorWidth
Definition: FWTabularWidget.h:36
FWTableManagerBase::numberOfColumns
virtual int numberOfColumns() const =0
Number of columns in the table.
createfilelist.int
int
Definition: createfilelist.py:10
FWTableCellRendererBase
Definition: FWTableCellRendererBase.h:44
FWTabularWidget::m_growInWidth
bool m_growInWidth
Definition: FWTabularWidget.h:92
FWTabularWidget::needToRedraw
void needToRedraw()
Definition: FWTabularWidget.cc:90
FWTabularWidget::m_vOffset
unsigned int m_vOffset
Definition: FWTabularWidget.h:86
FWTabularWidget::DoRedraw
void DoRedraw() override
Definition: FWTabularWidget.cc:221
FWTabularWidget::buttonReleased
void buttonReleased(Int_t row, Int_t column, Event_t *event, Int_t relX, Int_t relY)
Definition: FWTabularWidget.cc:210
FWTabularWidget::m_tableWidth
int m_tableWidth
Definition: FWTabularWidget.h:84
WDecay::kNone
Definition: TopGenEvent.h:27
FWTabularWidget::translateToRowColumn
void translateToRowColumn(Int_t iX, Int_t iY, Int_t &oRow, Int_t &oCol, Int_t &oRelX, Int_t &oRelY) const
Definition: FWTabularWidget.cc:162
FWTabularWidget::m_backgroundGC
GContext_t m_backgroundGC
Definition: FWTabularWidget.h:90
FWTabularWidget::m_hOffset
unsigned int m_hOffset
Definition: FWTabularWidget.h:87
FWTabularWidget::~FWTabularWidget
~FWTabularWidget() override
Definition: FWTabularWidget.cc:68
FWTabularWidget::getDefaultGC
static const TGGC & getDefaultGC()
Definition: FWTabularWidget.cc:319
FWTabularWidget::m_widthOfTextInColumns
std::vector< unsigned int > m_widthOfTextInColumns
Definition: FWTabularWidget.h:81
FWTabularWidget::FWTabularWidget
FWTabularWidget(FWTableManagerBase *iManager, const TGWindow *p=nullptr, GContext_t context=getDefaultGC()())
Definition: FWTabularWidget.cc:38
FWTableCellRendererBase.h
event
Definition: event.py:1
FWTableCellRendererBase::buttonEvent
virtual void buttonEvent(Event_t *iClickEvent, int iRelClickX, int iRelClickY)
Definition: FWTableCellRendererBase.cc:53
FWTableManagerBase::cellHeight
virtual unsigned int cellHeight() const
require all cells to be the same height
Definition: FWTableManagerBase.cc:75
FWTabularWidget
Definition: FWTabularWidget.h:31
FWTableManagerBase::maxWidthForColumns
virtual std::vector< unsigned int > maxWidthForColumns() const
for each column in the table this returns the present maximum width for that column
Definition: FWTableManagerBase.cc:89
FWTableManagerBase.h