LCOV - code coverage report
Current view: top level - dbe/apps/SchemaEditor - SchemaCustomTableModel.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 73 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 11 0

            Line data    Source code
       1              : #include "dbe/SchemaCustomTableModel.hpp"
       2              : #include "dbe/SchemaKernelWrapper.hpp"
       3              : #include "dbe/SchemaStyle.hpp"
       4              : #include <QIODevice>
       5              : #include <QDataStream>
       6              : 
       7              : using namespace dunedaq::oks;
       8              : 
       9            0 : dbse::CustomTableModel::CustomTableModel ( QStringList Headers, QObject * parent )
      10              :   : QAbstractTableModel ( parent ),
      11            0 :     HeaderList ( Headers )
      12              : {
      13            0 :   setupModel();
      14            0 : }
      15              : 
      16            0 : dbse::CustomTableModel::~CustomTableModel()
      17              : {
      18            0 : }
      19              : 
      20            0 : int dbse::CustomTableModel::rowCount ( const QModelIndex & parent ) const
      21              : {
      22            0 :   Q_UNUSED ( parent );
      23            0 :   return m_data.size();
      24              : }
      25              : 
      26            0 : int dbse::CustomTableModel::columnCount ( const QModelIndex & parent ) const
      27              : {
      28            0 :   Q_UNUSED ( parent );
      29            0 :   return HeaderList.size();
      30              : }
      31              : 
      32            0 : Qt::ItemFlags dbse::CustomTableModel::flags ( const QModelIndex & index ) const
      33              : {
      34            0 :   Q_UNUSED ( index );
      35            0 :   return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
      36              : }
      37              : 
      38            0 : QVariant dbse::CustomTableModel::headerData ( int section, Qt::Orientation orientation,
      39              :                                               int role ) const
      40              : {
      41            0 :   if ( role != Qt::DisplayRole )
      42              :   {
      43            0 :     return QVariant();
      44              :   }
      45              : 
      46            0 :   if ( orientation == Qt::Horizontal )
      47              :   {
      48            0 :     return HeaderList.at ( section );
      49              :   }
      50              : 
      51            0 :   return QVariant();
      52              : }
      53              : 
      54            0 : QVariant dbse::CustomTableModel::data ( const QModelIndex & index, int role ) const
      55              : {
      56            0 :   if ( role == Qt::DisplayRole )
      57              :   {
      58            0 :     return m_data.value ( index.row() ).value ( index.column() );
      59              :   }
      60            0 :   if ( role == Qt::ToolTipRole )
      61              :   {
      62            0 :     return m_tooltips.value ( index.row() ).value ( index.column() );
      63              :   }
      64            0 :   if (role == Qt::ForegroundRole) {
      65            0 :     return m_brushes.at(index.row());
      66              :   }
      67            0 :   if (role == Qt::BackgroundRole) {
      68            0 :     return m_backgrounds.at(index.row());
      69              :   }
      70              : 
      71            0 :   return QVariant();
      72              : }
      73              : 
      74            0 : QStringList dbse::CustomTableModel::getRowFromIndex ( QModelIndex & index )
      75              : {
      76            0 :   if ( !index.isValid() )
      77              :   {
      78            0 :     return QStringList();
      79              :   }
      80              : 
      81            0 :   return m_data.at ( index.row() );
      82              : }
      83              : 
      84            0 : void dbse::CustomTableModel::setupModel()
      85              : {
      86            0 :   std::vector<OksClass *> ClassList;
      87            0 :   KernelWrapper::GetInstance().GetClassList ( ClassList );
      88              : 
      89            0 :   for ( unsigned int i = 0; i < ClassList.size(); ++i )
      90              :   {
      91            0 :     QList<QString> Row;
      92            0 :     OksClass * Class = ClassList.at ( i );
      93            0 :     Row.append ( QString ( Class->get_name().c_str() ) );
      94            0 :     m_data.append ( Row );
      95            0 :     m_tooltips.append (QStringList {QString ( Class->get_description().c_str() )});
      96              : 
      97            0 :     auto fn = Class->get_file()->get_full_file_name();
      98            0 :     if (!KernelWrapper::GetInstance().IsFileWritable (fn)) {
      99            0 :       m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "readonly")));
     100            0 :       m_backgrounds.emplace_back(SchemaStyle::get_color("background", "readonly"));
     101              :     }
     102            0 :     else if (fn == KernelWrapper::GetInstance().GetActiveSchema()) {
     103            0 :       m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "active_file")));
     104            0 :       m_backgrounds.emplace_back(SchemaStyle::get_color("background", "active_file"));
     105              :     }
     106              :     else {
     107            0 :       m_brushes.emplace_back(QBrush(SchemaStyle::get_color("foreground", "default")));
     108            0 :       m_backgrounds.emplace_back(SchemaStyle::get_color("background", "default"));
     109              :     }
     110            0 :   }
     111            0 : }
     112              : 
     113            0 : QStringList dbse::CustomTableModel::mimeTypes() const
     114              : {
     115            0 :   QStringList types;
     116            0 :   types << "application/vnd.text.list";
     117            0 :   return types;
     118            0 : }
     119              : 
     120            0 : QMimeData * dbse::CustomTableModel::mimeData ( const QModelIndexList & indexes ) const
     121              : {
     122            0 :   QMimeData * mimeData = new QMimeData();
     123            0 :   QByteArray encodedData;
     124              : 
     125            0 :   QDataStream stream ( &encodedData, QIODevice::WriteOnly );
     126              : 
     127            0 :   foreach ( QModelIndex index, indexes )
     128              :   {
     129            0 :     if ( index.isValid() && index.column() == 0 )
     130              :     {
     131            0 :       QString ClassName = data ( index, Qt::DisplayRole ).toString();
     132            0 :       stream << ClassName;
     133            0 :     }
     134            0 :   }
     135              : 
     136            0 :   mimeData->setData ( "application/vnd.text.list", encodedData );
     137            0 :   return mimeData;
     138            0 : }
        

Generated by: LCOV version 2.0-1