File indexing completed on 2024-04-06 12:11:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <sstream>
0015 #include <functional>
0016 #include "TClass.h"
0017
0018
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
0026
0027
0028
0029
0030
0031
0032
0033
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
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
0054
0055
0056
0057
0058 FWCollectionSummaryTableManager::~FWCollectionSummaryTableManager() {}
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
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 }
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
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
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
0177