CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Fireworks/Core/src/FWTriggerTableViewTableManager.cc

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