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

            Line data    Source code
       1              : /// Including Schema Editor
       2              : #include "dbe/SchemaCustomFileModel.hpp"
       3              : #include "dbe/SchemaKernelWrapper.hpp"
       4              : #include "dbe/SchemaStyle.hpp"
       5              : /// Including C++ Headers
       6              : #include <vector>
       7              : 
       8              : #include <QBrush>
       9              : #include <QColor>
      10              : #include <QSize>
      11              : 
      12            0 : dbse::CustomFileModel::CustomFileModel(QStringList& Headers, QObject* parent)
      13              :   : QAbstractTableModel(parent)
      14            0 :   , HeaderList(Headers)
      15              : {
      16            0 :   setupModel();
      17            0 : }
      18              : 
      19            0 : dbse::CustomFileModel::~CustomFileModel() {}
      20              : 
      21              : int
      22            0 : dbse::CustomFileModel::rowCount(const QModelIndex& parent) const
      23              : {
      24            0 :   Q_UNUSED(parent);
      25            0 :   return Data.size();
      26              : }
      27              : 
      28              : int
      29            0 : dbse::CustomFileModel::columnCount(const QModelIndex& parent) const
      30              : {
      31            0 :   Q_UNUSED(parent);
      32            0 :   return HeaderList.size();
      33              : }
      34              : 
      35              : // Qt::ItemFlags dbse::CustomFileModel::flags ( const QModelIndex & index ) const
      36              : // {
      37              : //   // if ( Data.value (index.row() ).value ( 1) == "RW" ) {
      38              : //     return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
      39              : //   // }
      40              : //   // else {
      41              : //   //   return Qt::NoItemFlags;
      42              : //   // }
      43              : // }
      44              : 
      45              : QVariant
      46            0 : dbse::CustomFileModel::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::CustomFileModel::data(const QModelIndex& index, int role) const
      61              : {
      62            0 :   if (role == Qt::DisplayRole) {
      63            0 :     return Data.value(index.row()).value(index.column());
      64              :   }
      65            0 :   if (role == Qt::ForegroundRole) {
      66            0 :     if (Data.value(index.row()).value(2).contains("Active")) {
      67            0 :       return QBrush(QColor(SchemaStyle::get_color("foreground", "active_file")));
      68              :     }
      69            0 :     if (Data.value(index.row()).value(1) == "RW") {
      70            0 :       return QBrush(QColor(SchemaStyle::get_color("foreground", "default")));
      71              :     }
      72            0 :     return QBrush(SchemaStyle::get_color("foreground", "readonly"));
      73              :   }
      74            0 :   if (role == Qt::BackgroundRole) {
      75            0 :     if (Data.value(index.row()).value(2).contains("Active")) {
      76            0 :       return QBrush(QColor(SchemaStyle::get_color("background", "active_file")));
      77              :     }
      78            0 :     if (Data.value(index.row()).value(1) == "RW") {
      79            0 :       return QBrush(QColor(SchemaStyle::get_color("background", "default")));
      80              :     }
      81            0 :     return QBrush(SchemaStyle::get_color("background", "readonly"));
      82              :   }
      83            0 :   if (role == Qt::ToolTipRole) {
      84            0 :     return Data.value(index.row()).value(0);
      85              :   }
      86              : 
      87            0 :   return QVariant();
      88              : }
      89              : 
      90              : void
      91            0 : dbse::CustomFileModel::setupModel()
      92              : {
      93            0 :   std::vector<std::string> SchemaFiles;
      94            0 :   KernelWrapper::GetInstance().GetSchemaFiles(SchemaFiles);
      95            0 :   std::string ActiveSchema = KernelWrapper::GetInstance().GetActiveSchema();
      96            0 :   std::string Modified = KernelWrapper::GetInstance().ModifiedSchemaFiles();
      97            0 :   for (std::string& FileName : SchemaFiles) {
      98            0 :     QStringList Row;
      99            0 :     Row.append(QString::fromStdString(FileName));
     100              : 
     101            0 :     if (KernelWrapper::GetInstance().IsFileWritable(FileName)) {
     102            0 :       Row.append("RW");
     103              :     } else {
     104            0 :       Row.append("RO");
     105              :     }
     106              : 
     107            0 :     std::string Status = "";
     108            0 :     if (Modified.find(FileName) != std::string::npos) {
     109            0 :       Status = "Modified";
     110              :     }
     111            0 :     if (FileName == ActiveSchema) {
     112            0 :       if (!Status.empty()) {
     113            0 :         Status += "  ";
     114              :       }
     115            0 :       Status += "Active";
     116              :     }
     117              : 
     118            0 :     Row.append(QString::fromStdString(Status));
     119            0 :     Data.append(Row);
     120            0 :   }
     121            0 : }
     122              : 
     123              : QStringList
     124            0 : dbse::CustomFileModel::getRowFromIndex(QModelIndex& index)
     125              : {
     126            0 :   if (!index.isValid()) {
     127            0 :     return QStringList();
     128              :   }
     129              : 
     130            0 :   return Data.at(index.row());
     131              : }
        

Generated by: LCOV version 2.0-1