LCOV - code coverage report
Current view: top level - dbe/src/structure - FileModel.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 100 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 13 0

            Line data    Source code
       1              : /// Including QT Headers
       2              : #include "dbe/confaccessor.hpp"
       3              : #include "dbe/ui_constants.hpp"
       4              : #include "dbe/StyleUtility.hpp"
       5              : 
       6              : #include <QFileInfo>
       7              : #include <QDir>
       8              : /// Including DBE Headers
       9              : #include "dbe/FileModel.hpp"
      10              : #include "dbe/config_api_get.hpp"
      11              : #include "dbe/MainWindow.hpp"
      12              : 
      13            0 : dbe::FileModel::FileModel ( QObject * parent )
      14              :   : QAbstractTableModel ( parent ),
      15            0 :     Headers
      16            0 : { tr ( "Name" ), tr ( "Folder" ), tr ( "Access" ), tr ( "Status" ) }
      17              : {
      18            0 :   initpaths();
      19            0 :   initconnections();
      20            0 :   initmodel();
      21            0 : }
      22              : 
      23            0 : dbe::FileModel::FileModel ( QList<QStringList> const & FileList, QObject * parent )
      24              :   : QAbstractTableModel ( parent ),
      25            0 :     IncludedFiles ( FileList ),
      26            0 :     Headers
      27            0 : { tr ( "Name" ), tr ( "Folder" ), tr ( "Access" ), tr ( "Status" ) }
      28              : {
      29            0 :   initconnections();
      30            0 : }
      31              : 
      32            0 : dbe::FileModel::~FileModel()
      33            0 : {}
      34              : 
      35            0 : int dbe::FileModel::rowCount ( const QModelIndex & parent ) const
      36              : {
      37            0 :   if ( !parent.isValid() )
      38              :   {
      39            0 :     return IncludedFiles.size();
      40              :   }
      41              : 
      42              :   return 0;
      43              : }
      44              : 
      45            0 : int dbe::FileModel::columnCount ( const QModelIndex & parent ) const
      46              : {
      47            0 :   Q_UNUSED ( parent )
      48            0 :   return Headers.size();
      49              : }
      50              : 
      51            0 : QVariant dbe::FileModel::data ( const QModelIndex & index, int role ) const
      52              : {
      53            0 :   if ( index.isValid() )
      54              :   {
      55            0 :     if ( role == Qt::DisplayRole ) {
      56            0 :       return QVariant (
      57            0 :                IncludedFiles.at ( index.row() ).at ( index.column() ) );
      58              :     }
      59            0 :     if ( role == Qt::ForegroundRole )
      60              :     {
      61            0 :       if ( IncludedFiles.at ( index.row() ).at (
      62            0 :              static_cast<int> ( tablepositions::filepermission ) ) == "RO" ) {
      63            0 :         return QBrush (StyleUtility::FileReadOnlyForeground );
      64              :       }
      65              :     }
      66            0 :     if ( role == Qt::BackgroundRole )
      67              :     {
      68            0 :       if ( IncludedFiles.at ( index.row() ).at (
      69            0 :              static_cast<int> ( tablepositions::filepermission ) ) == "RO" ) {
      70            0 :         return QBrush (StyleUtility::FileReadOnlyBackground );
      71              :       }
      72              :     }
      73              :   }
      74              : 
      75            0 :   return QVariant();
      76              : }
      77              : 
      78            0 : QVariant dbe::FileModel::headerData ( int section, Qt::Orientation orientation,
      79              :                                       int role ) const
      80              : {
      81            0 :   if ( role == Qt::DisplayRole )
      82              :   {
      83            0 :     if ( orientation == Qt::Horizontal )
      84              :     {
      85            0 :       return Headers.at ( section );
      86              :     }
      87              : 
      88            0 :     if ( orientation == Qt::Vertical )
      89              :     {
      90            0 :       return section + 1;
      91              :     }
      92              :   }
      93              : 
      94            0 :   return QVariant();
      95              : }
      96              : 
      97            0 : Qt::ItemFlags dbe::FileModel::flags ( const QModelIndex & /*index*/ ) const
      98              : {
      99              :   // if ( IncludedFiles.at ( index.row() ).at ( static_cast<int>
     100              :   //                                            ( tablepositions::filepermission ) ) == "RW" )
     101              :   // {
     102            0 :     return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
     103              :   // }
     104              : 
     105              :   // return Qt::ItemIsSelectable;
     106              : }
     107              : 
     108            0 : void dbe::FileModel::initpaths()
     109              : {
     110            0 :   QString TDAQ_DB_REPOSITORY = getenv ( "TDAQ_DB_REPOSITORY" );
     111            0 :   if(TDAQ_DB_REPOSITORY.isEmpty() == false) {
     112            0 :       QString TDAQ_DB_USER_REPOSITORY = getenv ( "TDAQ_DB_USER_REPOSITORY" );
     113            0 :       FolderPathList = TDAQ_DB_USER_REPOSITORY.split ( ":", Qt::SkipEmptyParts );
     114              : 
     115            0 :       FolderPathList << dbe::MainWindow::findthis()->find_db_repository_dir();
     116            0 :   } else {
     117            0 :       QString DUNEDAQ_DB_PATH = getenv ( "DUNEDAQ_DB_PATH" );
     118            0 :       FolderPathList = DUNEDAQ_DB_PATH.split ( ":", Qt::SkipEmptyParts );
     119            0 :   }
     120              : 
     121            0 :   for ( QString & PathName : FolderPathList )
     122              :   {
     123            0 :     if ( !PathName.endsWith ( "/" ) )
     124              :     {
     125            0 :       PathName.append ( "/" );
     126              :     }
     127              :   }
     128            0 : }
     129              : 
     130            0 : void dbe::FileModel::initconnections()
     131              : {
     132            0 :   connect ( this, SIGNAL ( FileCacheReady ( QList<QStringList> & ) ), &confaccessor::ref(),
     133              :             SLOT ( GetFileCache ( QList<QStringList> & ) ) );
     134            0 : }
     135              : 
     136            0 : QString dbe::FileModel::GetFullFileName ( QString & FileName )
     137              : {
     138            0 :   QFileInfo FileInfo ( FileName );
     139              : 
     140            0 :   if ( FileInfo.isRelative() )
     141              :   {
     142            0 :     bool found=false;
     143            0 :     for ( const QString & Folder : FolderPathList )
     144              :     {
     145            0 :       QDir TdaqFolder ( Folder );
     146              : 
     147            0 :       if ( TdaqFolder.exists ( FileName ) )
     148              :       {
     149            0 :         FileName = TdaqFolder.path() + "/" + FileName;
     150            0 :         found=true;
     151            0 :         break;
     152              :       }
     153            0 :     }
     154            0 :     if (!found) {
     155            0 :       FileName = FileInfo.absoluteFilePath();
     156              :     }
     157              :   }
     158              : 
     159            0 :   return FileName;
     160            0 : }
     161              : 
     162            0 : QList<QStringList> dbe::FileModel::GetFilesInfo() const
     163              : {
     164            0 :   return IncludedFiles;
     165              : }
     166              : 
     167            0 : void dbe::FileModel::initmodel()
     168              : {
     169            0 :   QStringList sources = dbe::config::api::get::file::inclusions (
     170            0 :   { confaccessor::dbfullname() } );
     171              : 
     172            0 :   std::list<std::string> updated = confaccessor::uncommitted_files();
     173            0 :   for ( QString const & source : sources )
     174              :   {
     175            0 :     QFileInfo srcinfo ( source );
     176            0 :     QString fn = srcinfo.filePath();
     177            0 :     QString dn = GetFullFileName(fn).remove(QRegularExpression("/[a-zA-Z0-9_-]*.data.xml"));
     178              : 
     179            0 :     QString modified{};
     180            0 :     auto file = GetFullFileName(fn).toStdString();
     181            0 :     for (auto ufile: updated) {
     182            0 :       if (file == ufile) {
     183            0 :         modified = "Modified";
     184            0 :         break;
     185              :       }
     186            0 :     }
     187              : 
     188            0 :     IncludedFiles.append ( QStringList{ srcinfo.fileName(),
     189              :         dn,
     190            0 :         confaccessor::check_file_rw ( source ) ? "RW" : "RO",
     191            0 :         modified}
     192              :       );
     193            0 :   }
     194              : 
     195            0 :   if ( IncludedFiles.size() )
     196              :   {
     197            0 :     emit FileCacheReady ( IncludedFiles );
     198              :   }
     199            0 : }
        

Generated by: LCOV version 2.0-1