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