Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWCollectionSummaryTableManager
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Sun Feb 22 10:13:39 CST 2009
0011 //
0012 
0013 // system include files
0014 #include <sstream>
0015 #include <functional>
0016 #include "TClass.h"
0017 
0018 // user include files
0019 #include "Fireworks/Core/src/FWCollectionSummaryTableManager.h"
0020 #include "Fireworks/Core/interface/FWEventItem.h"
0021 #include "Fireworks/Core/interface/FWItemValueGetter.h"
0022 #include "Fireworks/Core/src/FWCollectionSummaryWidget.h"
0023 
0024 //
0025 // constants, enums and typedefs
0026 //
0027 
0028 //
0029 // static data member definitions
0030 //
0031 
0032 //
0033 // constructors and destructor
0034 //
0035 FWCollectionSummaryTableManager::FWCollectionSummaryTableManager(FWEventItem* iItem,
0036                                                                  const TGGC* iContext,
0037                                                                  const TGGC* iHighlightContext,
0038                                                                  FWCollectionSummaryWidget* iWidget)
0039     : m_collection(iItem),
0040       m_renderer(iContext, iHighlightContext),
0041       m_bodyRenderer(iContext, iHighlightContext, FWTextTableCellRenderer::kJustifyRight),
0042       m_widget(iWidget) {
0043   m_collection->changed_.connect(std::bind(&FWTableManagerBase::dataChanged, this));
0044   m_collection->itemChanged_.connect(std::bind(&FWCollectionSummaryTableManager::dataChanged, this));
0045 
0046   //try to find the default columns
0047   std::vector<std::pair<std::string, std::string> > s_names;
0048   edm::TypeWithDict type(*(m_collection->modelType()->GetTypeInfo()));
0049 
0050   dataChanged();
0051 }
0052 
0053 // FWCollectionSummaryTableManager::FWCollectionSummaryTableManager(const FWCollectionSummaryTableManager& rhs)
0054 // {
0055 //    // do actual copying here;
0056 // }
0057 
0058 FWCollectionSummaryTableManager::~FWCollectionSummaryTableManager() {}
0059 
0060 //
0061 // assignment operators
0062 //
0063 // const FWCollectionSummaryTableManager& FWCollectionSummaryTableManager::operator=(const FWCollectionSummaryTableManager& rhs)
0064 // {
0065 //   //An exception safe implementation is
0066 //   FWCollectionSummaryTableManager temp(rhs);
0067 //   swap(rhs);
0068 //
0069 //   return *this;
0070 // }
0071 
0072 //
0073 // member functions
0074 //
0075 namespace {
0076   template <typename S>
0077   void doSort(const FWEventItem& iItem,
0078               const FWItemValueGetter& iGetter,
0079               int iCol,
0080               std::multimap<double, int, S>& iMap,
0081               std::vector<int>& oNewSort) {
0082     int size = iItem.size();
0083     for (int index = 0; index < size; ++index) {
0084       iMap.insert(std::make_pair(iGetter.valueFor(iItem.modelData(index), iCol), index));
0085     }
0086     std::vector<int>::iterator itVec = oNewSort.begin();
0087     for (typename std::map<double, int, S>::iterator it = iMap.begin(), itEnd = iMap.end(); it != itEnd;
0088          ++it, ++itVec) {
0089       *itVec = it->second;
0090     }
0091   }
0092 }  // namespace
0093 
0094 void FWCollectionSummaryTableManager::implSort(int iCol, bool iSortOrder) {
0095   if (iSortOrder) {
0096     std::multimap<double, int, std::greater<double> > s;
0097     doSort(*m_collection, m_collection->valueGetter(), iCol, s, m_sortedToUnsortedIndicies);
0098   } else {
0099     std::multimap<double, int, std::less<double> > s;
0100     doSort(*m_collection, m_collection->valueGetter(), iCol, s, m_sortedToUnsortedIndicies);
0101   }
0102 }
0103 
0104 void FWCollectionSummaryTableManager::buttonReleasedInRowHeader(Int_t row, Event_t* event, Int_t relX, Int_t relY) {
0105   Int_t realRow = unsortedRowNumber(row);
0106   int hit = m_renderer.clickHit(relX, relY);
0107   if (hit == FWCollectionSummaryModelCellRenderer::kMiss) {
0108     return;
0109   }
0110   if (hit == FWCollectionSummaryModelCellRenderer::kHitColor) {
0111     m_widget->itemColorClicked(realRow, event->fXRoot, event->fYRoot + 12 - relY);
0112     return;
0113   }
0114   FWEventItem::ModelInfo mi = m_collection->modelInfo(realRow);
0115   FWDisplayProperties dp = mi.displayProperties();
0116   if (hit == FWCollectionSummaryModelCellRenderer::kHitCheck) {
0117     dp.setIsVisible(!dp.isVisible());
0118   }
0119   m_collection->setDisplayProperties(realRow, dp);
0120 }
0121 
0122 //
0123 // const member functions
0124 //
0125 int FWCollectionSummaryTableManager::numberOfRows() const { return m_collection->size(); }
0126 
0127 int FWCollectionSummaryTableManager::numberOfColumns() const { return m_collection->valueGetter().numValues(); }
0128 
0129 std::vector<std::string> FWCollectionSummaryTableManager::getTitles() const {
0130   //return titles;
0131   return m_collection->valueGetter().getTitles();
0132 }
0133 
0134 int FWCollectionSummaryTableManager::unsortedRowNumber(int iSortedRowNumber) const {
0135   return m_sortedToUnsortedIndicies[iSortedRowNumber];
0136 }
0137 
0138 FWTableCellRendererBase* FWCollectionSummaryTableManager::cellRenderer(int iSortedRowNumber, int iCol) const {
0139   if (!m_collection->valueGetter().numValues()) {
0140     return nullptr;
0141   }
0142   if (iSortedRowNumber >= static_cast<int>(m_collection->size())) {
0143     m_bodyRenderer.setData("", false);
0144     return &m_bodyRenderer;
0145   }
0146   int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
0147   std::stringstream s;
0148   s.setf(std::ios_base::fixed, std::ios_base::floatfield);
0149   s.precision(m_collection->valueGetter().precision(iCol));
0150   double v = m_collection->valueGetter().valueFor(m_collection->modelData(index), iCol);
0151   s << v;
0152   m_bodyRenderer.setData(s.str(), m_collection->modelInfo(index).isSelected());
0153   return &m_bodyRenderer;
0154 }
0155 
0156 bool FWCollectionSummaryTableManager::hasRowHeaders() const { return true; }
0157 
0158 FWTableCellRendererBase* FWCollectionSummaryTableManager::rowHeader(int iSortedRowNumber) const {
0159   if (iSortedRowNumber >= static_cast<int>(m_collection->size())) {
0160     return nullptr;
0161   }
0162   int index = m_sortedToUnsortedIndicies[iSortedRowNumber];
0163   m_renderer.setData(m_collection, index);
0164   return &m_renderer;
0165 }
0166 
0167 void FWCollectionSummaryTableManager::dataChanged() {
0168   m_sortedToUnsortedIndicies.clear();
0169   m_sortedToUnsortedIndicies.reserve(m_collection->size());
0170   for (int i = 0; i < static_cast<int>(m_collection->size()); ++i) {
0171     m_sortedToUnsortedIndicies.push_back(i);
0172   }
0173   FWTableManagerBase::dataChanged();
0174 }
0175 //
0176 // static member functions
0177 //