Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:20

0001 
0002 #include <cassert>
0003 #include "TGClient.h"
0004 #include "Fireworks/Core/interface/FWTriggerTableViewTableManager.h"
0005 #include "Fireworks/Core/interface/FWTriggerTableView.h"
0006 #include "Fireworks/Core/interface/FWColorManager.h"
0007 #include "Fireworks/TableWidget/interface/FWTableWidget.h"
0008 
0009 FWTriggerTableViewTableManager::FWTriggerTableViewTableManager(const FWTriggerTableView* view)
0010     : m_view(view), m_graphicsContext(nullptr), m_renderer(nullptr) {
0011   GCValues_t gc = *(m_view->m_tableWidget->GetWhiteGC().GetAttributes());
0012   m_graphicsContext = gClient->GetResourcePool()->GetGCPool()->GetGC(&gc, kTRUE);
0013   m_renderer = new FWTextTableCellRenderer(m_graphicsContext, m_graphicsContext);
0014 }
0015 
0016 FWTriggerTableViewTableManager::~FWTriggerTableViewTableManager() { delete m_renderer; }
0017 
0018 int FWTriggerTableViewTableManager::numberOfRows() const {
0019   if (!m_view->m_columns.empty())
0020     return m_view->m_columns.front().values.size();
0021   else
0022     return 0;
0023 }
0024 
0025 int FWTriggerTableViewTableManager::numberOfColumns() const { return m_view->m_columns.size(); }
0026 
0027 std::vector<std::string> FWTriggerTableViewTableManager::getTitles() const {
0028   unsigned int n = numberOfColumns();
0029   std::vector<std::string> ret;
0030   ret.reserve(n);
0031   for (unsigned int i = 0; i < n; ++i) {
0032     ret.push_back(m_view->m_columns.at(i).title);
0033   }
0034   return ret;
0035 }
0036 
0037 int FWTriggerTableViewTableManager::unsortedRowNumber(int iSortedRowNumber) const {
0038   if (iSortedRowNumber >= (int)m_sortedToUnsortedIndices.size())
0039     return 0;
0040   return m_sortedToUnsortedIndices[iSortedRowNumber];
0041 }
0042 
0043 FWTableCellRendererBase* FWTriggerTableViewTableManager::cellRenderer(int iSortedRowNumber, int iCol) const {
0044   const int realRowNumber = unsortedRowNumber(iSortedRowNumber);
0045   const int acceptColumn = 1;
0046   if (!m_view->m_columns.empty() && int(m_view->m_columns.size()) > iCol &&
0047       int(m_view->m_columns.front().values.size()) > realRowNumber) {
0048     bool accepted = std::string(m_view->m_columns.at(acceptColumn).values.at(realRowNumber)) == "1";
0049     if ((m_view->backgroundColor() == kBlack) == accepted)
0050       m_graphicsContext->SetForeground(0xe0e0e0);
0051     else
0052       m_graphicsContext->SetForeground(0x404040);
0053     m_renderer->setData(m_view->m_columns.at(iCol).values.at(realRowNumber), false);
0054   } else {
0055     m_renderer->setData("invalid", false);
0056   }
0057   return m_renderer;
0058 }
0059 
0060 void FWTriggerTableViewTableManager::dataChanged() {
0061   m_sortedToUnsortedIndices.clear();
0062   for (int i = 0; i < numberOfRows(); ++i)
0063     m_sortedToUnsortedIndices.push_back(i);
0064   FWTableManagerBase::dataChanged();
0065 }
0066 
0067 namespace {
0068   template <typename TMap>
0069   void doSort(int col,
0070               const std::vector<FWTriggerTableView::Column>& iData,
0071               TMap& iOrdered,
0072               std::vector<int>& oRowToIndex) {
0073     unsigned int index = 0;
0074     for (std::vector<std::string>::const_iterator it = iData.at(col).values.begin(), itEnd = iData.at(col).values.end();
0075          it != itEnd;
0076          ++it, ++index) {
0077       iOrdered.insert(std::make_pair(*it, index));
0078     }
0079     unsigned int row = 0;
0080     for (typename TMap::iterator it = iOrdered.begin(), itEnd = iOrdered.end(); it != itEnd; ++it, ++row) {
0081       oRowToIndex[row] = it->second;
0082     }
0083   }
0084 }  // namespace
0085 
0086 void FWTriggerTableViewTableManager::implSort(int col, bool sortOrder) {
0087   if (sortOrder) {
0088     std::multimap<std::string, int, std::greater<std::string> > ordered;
0089     doSort(col, m_view->m_columns, ordered, m_sortedToUnsortedIndices);
0090   } else {
0091     std::multimap<std::string, int> ordered;
0092     doSort(col, m_view->m_columns, ordered, m_sortedToUnsortedIndices);
0093   }
0094 }