CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWTriggerTableViewTableManager.cc
Go to the documentation of this file.
1 // $Id: FWTriggerTableViewTableManager.cc,v 1.5 2012/09/27 16:51:25 eulisse Exp $
2 
3 #include <cassert>
4 #include "TGClient.h"
9 
11  : m_view(view),
12  m_graphicsContext(0),
13  m_renderer(0)
14 {
15  GCValues_t gc = *(m_view->m_tableWidget->GetWhiteGC().GetAttributes());
16  m_graphicsContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gc,kTRUE);
18 }
19 
21 {
22  delete m_renderer;
23 }
24 
25 int
27 {
28  if ( !m_view->m_columns.empty() )
29  return m_view->m_columns.front().values.size();
30  else
31  return 0;
32 }
33 
34 int
36 {
37  return m_view->m_columns.size();
38 }
39 
40 std::vector<std::string>
42 {
43  unsigned int n = numberOfColumns();
44  std::vector<std::string> ret;
45  ret.reserve(n);
46  for (unsigned int i = 0; i < n; ++i) {
47  ret.push_back(m_view->m_columns.at(i).title);
48  }
49  return ret;
50 }
51 
52 int
54 {
55  if (iSortedRowNumber >= (int)m_sortedToUnsortedIndices.size())
56  return 0;
57  return m_sortedToUnsortedIndices[iSortedRowNumber];
58 }
59 
62  int iCol) const
63 {
64  const int realRowNumber = unsortedRowNumber(iSortedRowNumber);
65  const int acceptColumn = 1;
66  if ( !m_view->m_columns.empty() &&
67  int(m_view->m_columns.size())>iCol &&
68  int(m_view->m_columns.front().values.size())>realRowNumber ) {
69  bool accepted = std::string(m_view->m_columns.at(acceptColumn).values.at(realRowNumber)) == "1";
70  if ((m_view->backgroundColor() == kBlack) == accepted)
71  m_graphicsContext->SetForeground(0xe0e0e0);
72  else
73  m_graphicsContext->SetForeground(0x404040);
74  m_renderer->setData(m_view->m_columns.at(iCol).values.at(realRowNumber), false);
75  } else {
76  m_renderer->setData("invalid", false);
77  }
78  return m_renderer;
79 }
80 
81 void
83 {
85  for ( int i=0; i< numberOfRows(); ++i)
86  m_sortedToUnsortedIndices.push_back(i);
88 }
89 
90 namespace {
91  template <typename TMap>
92  void doSort(int col,
93  const std::vector<FWTriggerTableView::Column>& iData,
94  TMap& iOrdered,
95  std::vector<int>& oRowToIndex)
96  {
97  unsigned int index=0;
98  for(std::vector<std::string>::const_iterator it = iData.at(col).values.begin(),
99  itEnd = iData.at(col).values.end(); it!=itEnd; ++it,++index) {
100  iOrdered.insert(std::make_pair(*it,index));
101  }
102  unsigned int row = 0;
103  for(typename TMap::iterator it = iOrdered.begin(),
104  itEnd = iOrdered.end();
105  it != itEnd;
106  ++it,++row) {
107  oRowToIndex[row]=it->second;
108  }
109  }
110 }
111 
112 void
114 {
115  if(sortOrder) {
116  std::multimap<std::string,int,std::greater<std::string> > ordered;
117  doSort(col, m_view->m_columns, ordered, m_sortedToUnsortedIndices);
118  } else {
119  std::multimap<std::string,int> ordered;
120  doSort(col, m_view->m_columns, ordered, m_sortedToUnsortedIndices);
121  }
122 }
123 
int i
Definition: DBlmapReader.cc:9
virtual void implSort(int iCol, bool iSortOrder)
std::vector< Column > m_columns
void dataChanged()
Classes which inherit from FWTableManagerBase must call this when their underlying data changes...
virtual int unsortedRowNumber(int iSortedRowNumber) const
when passed the index to the sorted order of the rows it returns the original row number from the und...
virtual int numberOfColumns() const
Number of columns in the table.
FWTableWidget * m_tableWidget
FWTriggerTableViewTableManager(const FWTriggerTableView *)
Color_t backgroundColor() const
void setData(const std::string &, bool isSelected)
virtual FWTableCellRendererBase * cellRenderer(int iSortedRowNumber, int iCol) const
virtual int numberOfRows() const
Number of rows in the table.
virtual std::vector< std::string > getTitles() const
returns the title names for each column
int col
Definition: cuy.py:1008