Go to the documentation of this file.00001
00002
00003 #include <cassert>
00004 #include "TGClient.h"
00005 #include "Fireworks/Core/interface/FWTriggerTableViewTableManager.h"
00006 #include "Fireworks/Core/interface/FWTriggerTableView.h"
00007 #include "Fireworks/Core/interface/FWColorManager.h"
00008 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
00009
00010 FWTriggerTableViewTableManager::FWTriggerTableViewTableManager (const FWTriggerTableView *view)
00011 : m_view(view),
00012 m_graphicsContext(0),
00013 m_renderer(0)
00014 {
00015 GCValues_t gc = *(m_view->m_tableWidget->GetWhiteGC().GetAttributes());
00016 m_graphicsContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gc,kTRUE);
00017 m_renderer = new FWTextTableCellRenderer(m_graphicsContext,m_graphicsContext);
00018 }
00019
00020 FWTriggerTableViewTableManager::~FWTriggerTableViewTableManager ()
00021 {
00022 delete m_renderer;
00023 }
00024
00025 int
00026 FWTriggerTableViewTableManager::numberOfRows() const
00027 {
00028 if ( !m_view->m_columns.empty() )
00029 return m_view->m_columns.front().values.size();
00030 else
00031 return 0;
00032 }
00033
00034 int
00035 FWTriggerTableViewTableManager::numberOfColumns() const
00036 {
00037 return m_view->m_columns.size();
00038 }
00039
00040 std::vector<std::string>
00041 FWTriggerTableViewTableManager::getTitles () const
00042 {
00043 unsigned int n = numberOfColumns();
00044 std::vector<std::string> ret;
00045 ret.reserve(n);
00046 for (unsigned int i = 0; i < n; ++i) {
00047 ret.push_back(m_view->m_columns.at(i).title);
00048 }
00049 return ret;
00050 }
00051
00052 int
00053 FWTriggerTableViewTableManager::unsortedRowNumber(int iSortedRowNumber) const
00054 {
00055 if (iSortedRowNumber >= (int)m_sortedToUnsortedIndices.size())
00056 return 0;
00057 return m_sortedToUnsortedIndices[iSortedRowNumber];
00058 }
00059
00060 FWTableCellRendererBase
00061 *FWTriggerTableViewTableManager::cellRenderer(int iSortedRowNumber,
00062 int iCol) const
00063 {
00064 const int realRowNumber = unsortedRowNumber(iSortedRowNumber);
00065 const int acceptColumn = 1;
00066 if ( !m_view->m_columns.empty() &&
00067 int(m_view->m_columns.size())>iCol &&
00068 int(m_view->m_columns.front().values.size())>realRowNumber ) {
00069 bool accepted = std::string(m_view->m_columns.at(acceptColumn).values.at(realRowNumber)) == "1";
00070 if ((m_view->backgroundColor() == kBlack) == accepted)
00071 m_graphicsContext->SetForeground(0xe0e0e0);
00072 else
00073 m_graphicsContext->SetForeground(0x404040);
00074 m_renderer->setData(m_view->m_columns.at(iCol).values.at(realRowNumber), false);
00075 } else {
00076 m_renderer->setData("invalid", false);
00077 }
00078 return m_renderer;
00079 }
00080
00081 void
00082 FWTriggerTableViewTableManager::dataChanged()
00083 {
00084 m_sortedToUnsortedIndices.clear();
00085 for ( int i=0; i< numberOfRows(); ++i)
00086 m_sortedToUnsortedIndices.push_back(i);
00087 FWTableManagerBase::dataChanged();
00088 }
00089
00090 namespace {
00091 template <typename TMap>
00092 void doSort(int col,
00093 const std::vector<FWTriggerTableView::Column>& iData,
00094 TMap& iOrdered,
00095 std::vector<int>& oRowToIndex)
00096 {
00097 unsigned int index=0;
00098 for(std::vector<std::string>::const_iterator it = iData.at(col).values.begin(),
00099 itEnd = iData.at(col).values.end(); it!=itEnd; ++it,++index) {
00100 iOrdered.insert(std::make_pair(*it,index));
00101 }
00102 unsigned int row = 0;
00103 for(typename TMap::iterator it = iOrdered.begin(),
00104 itEnd = iOrdered.end();
00105 it != itEnd;
00106 ++it,++row) {
00107 oRowToIndex[row]=it->second;
00108 }
00109 }
00110 }
00111
00112 void
00113 FWTriggerTableViewTableManager::implSort(int col, bool sortOrder)
00114 {
00115 if(sortOrder) {
00116 std::multimap<std::string,int,std::greater<std::string> > ordered;
00117 doSort(col, m_view->m_columns, ordered, m_sortedToUnsortedIndices);
00118 } else {
00119 std::multimap<std::string,int> ordered;
00120 doSort(col, m_view->m_columns, ordered, m_sortedToUnsortedIndices);
00121 }
00122 }
00123