LCOV - code coverage report
Current view: top level - dbe/apps/SchemaEditor - SchemaCustomTableModel.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 72 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 11 0

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

Generated by: LCOV version 2.0-1