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