DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
widgets
IncludeFileWidget.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
6
#include "
dbe/IncludeFileWidget.hpp
"
7
#include "
dbe/confaccessor.hpp
"
8
#include "
dbe/StyleUtility.hpp
"
9
#include "
dbe/Exceptions.hpp
"
10
#include "
dbe/config_api_get.hpp
"
11
#include "
dbe/config_api_commands.hpp
"
12
#include "ui_IncludeFileWidget.h"
13
#include "
dbe/messenger.hpp
"
14
#include "
dbe/MainWindow.hpp
"
15
16
#include <QUrl>
17
#include <QApplication>
18
19
#include <boost/scope_exit.hpp>
20
#include <cstdlib>
21
22
dbe::IncludeFileWidget::~IncludeFileWidget
() =
default
;
23
24
dbe::IncludeFileWidget::IncludeFileWidget
( QString FilePath, QWidget * parent )
25
: QWidget ( parent ),
26
ui
( new
Ui
::
IncludeFileWidget
),
27
CreateWidget
( nullptr ),
28
DatabasePath
( FilePath ),
29
Removed
( false ),
30
StatusBar
( nullptr ),
31
SelectFile
( nullptr )
32
{
33
ui
->setupUi (
this
);
34
36
ui
->AddLabel->setStyleSheet (
37
"QLabel{background-color:#8DAA2E; color:#facd64; font:bold14px; border-style:outset; border-width:2px; border-radius:10px;"
38
"border-color:beige; font:bold14px; min-width:10em; padding: 6px;}"
);
39
ui
->RemoveLabel->setStyleSheet (
40
"QLabel{background-color:#b5351b; color:#facd64; font:bold14px; border-style:outset;"
41
"border-width:2px; border-radius:10px; border-color:beige; font:bold14px; min-width:10em; padding:6px;}"
);
42
setWindowTitle (
43
QString (
"Edit Included Files for Database : %1"
).arg ( QFileInfo (
44
FilePath ).fileName() ) );
45
46
StatusBar
=
new
QStatusBar (
ui
->StatusFrame );
47
StatusBar
->setSizeGripEnabled (
false
);
48
ui
->StatusFrame->setFrameStyle ( QFrame::NoFrame );
49
ui
->StatusLayout->addWidget (
StatusBar
);
50
51
StatusBar
->setAutoFillBackground (
true
);
52
StatusBar
->showMessage (
"Select files to include or to remove from include!"
);
53
54
SetRemoveComboBox
();
55
56
SelectFile
=
new
QFileDialog (
this
, tr (
"Open File"
),
"."
, tr (
"XML files (*.xml)"
) );
57
SelectFile
->setFileMode ( QFileDialog::ExistingFiles );
58
SelectFile
->setViewMode ( QFileDialog::Detail );
59
SelectFile
->setAcceptMode ( QFileDialog::AcceptOpen );
60
61
QString TDAQ_DB_REPOSITORY = getenv (
"TDAQ_DB_REPOSITORY"
);
62
if
(TDAQ_DB_REPOSITORY.isEmpty() ==
false
) {
63
QString TDAQ_DB_USER_REPOSITORY = getenv (
"TDAQ_DB_USER_REPOSITORY"
);
64
FolderPathList
= TDAQ_DB_USER_REPOSITORY.split (
":"
, Qt::SkipEmptyParts );
65
66
FolderPathList
.append(
dbe::MainWindow::findthis
()->find_db_repository_dir());
67
}
else
{
68
QString DUNEDAQ_DB_PATH = getenv (
"DUNEDAQ_DB_PATH"
);
69
FolderPathList
= DUNEDAQ_DB_PATH.split (
":"
, Qt::SkipEmptyParts );
70
}
71
72
for
( QString & PathName :
FolderPathList
)
73
{
74
if
( !PathName.endsWith (
"/"
) )
75
{
76
PathName.append (
"/"
);
77
}
78
}
79
80
QList<QUrl> List =
SelectFile
->sidebarUrls();
81
82
if
( !
FolderPathList
.isEmpty() )
83
{
84
dbPath
=
FolderPathList
;
85
86
for
(
const
QString & Dir :
dbPath
)
87
{
88
ui
->DirectoryCombo->addItem ( Dir );
89
QString TDAqDir = QString (
"file://"
).append ( Dir );
90
QUrl URL = QUrl ( TDAqDir );
91
List << URL;
92
}
93
}
94
95
SelectFile
->setSidebarUrls ( List );
96
SelectFile
->setOption (QFileDialog::DontResolveSymlinks,
true
);
97
ui
->AddToIncludeButton->setDisabled (
true
);
98
ui
->RemoveButton->setDisabled (
true
);
99
100
ui
->AddFileLine->setSelectionMode(QAbstractItemView::NoSelection);
101
102
SetController
();
103
}
104
105
106
void
dbe::IncludeFileWidget::keyPressEvent
(QKeyEvent* event) {
107
if
(event->key() == Qt::Key_Escape) {
108
close();
109
}
110
QWidget::keyPressEvent(event);
111
}
112
113
114
void
dbe::IncludeFileWidget::SetRemoveComboBox
()
115
{
116
QStringList IncludeList (
dbe::config::api::get::file::inclusions_singlefile
(
117
DatabasePath
) );
118
119
if
( !IncludeList.isEmpty() )
120
{
121
if
( IncludeList.contains (
DatabasePath
) )
122
{
123
IncludeList.removeOne (
DatabasePath
);
124
}
125
126
ui
->RemoveCombo->clear();
127
ui
->RemoveCombo->addItems ( IncludeList );
128
}
129
}
130
131
void
dbe::IncludeFileWidget::SetController
()
132
{
133
connect (
ui
->SelectFileButton, SIGNAL ( clicked() ),
this
, SLOT (
SelectFileToInclude
() ),
134
Qt::UniqueConnection );
135
connect (
ui
->CreateFileButton, SIGNAL ( clicked() ),
this
, SLOT (
CreateFileToInclude
() ),
136
Qt::UniqueConnection );
137
connect (
ui
->AddToIncludeButton, SIGNAL ( clicked() ),
this
, SLOT (
AddFileToInclude
() ),
138
Qt::UniqueConnection );
139
connect (
ui
->RemoveButton, SIGNAL ( clicked() ),
this
, SLOT (
RemoveFileFromInclude
() ),
140
Qt::UniqueConnection );
141
connect (
ui
->RemoveCombo, SIGNAL ( activated (
int
) ),
this
,
142
SLOT (
RemoveFileFromInclude
(
int
) ),
143
Qt::UniqueConnection );
144
connect (
ui
->DirectoryCombo, SIGNAL ( activated (
const
QString & ) ),
this
,
145
SLOT (
SetDirectory
(
const
QString & ) ), Qt::UniqueConnection );
146
connect (
ui
->ExitButton, SIGNAL ( clicked() ),
this
, SLOT ( close() ) );
147
}
148
149
void
dbe::IncludeFileWidget::SelectFileToInclude
()
150
{
151
ui
->AddFileLine->clear();
152
QStringList Files;
153
154
if
( !
Directory
.isEmpty() )
155
{
156
SelectFile
->setDirectory (
Directory
);
157
}
158
159
if
(
SelectFile
->exec() )
160
{
161
Files =
SelectFile
->selectedFiles();
162
}
163
164
if
(Files.isEmpty()) {
165
return
;
166
}
167
168
for
(
const
QString& FileToInclude : Files) {
169
QFileInfo f(FileToInclude);
170
171
if
(
Directory
.isEmpty() )
172
{
173
ui
->AddFileLine->addItem(f.absoluteFilePath());
174
}
175
else
176
{
177
ui
->AddFileLine->addItem(f.absoluteFilePath().remove (
Directory
+ QString (
'/'
), Qt::CaseSensitive ));
178
}
179
}
180
181
CheckInclude
();
182
}
183
184
void
dbe::IncludeFileWidget::AddFileToInclude
()
185
{
186
BOOST_SCOPE_EXIT(
void
)
187
{
188
QApplication::restoreOverrideCursor();
189
}
190
BOOST_SCOPE_EXIT_END
191
192
QApplication::setOverrideCursor(Qt::WaitCursor);
193
194
for
(
int
i = 0; i <
ui
->AddFileLine->count(); ++i) {
195
QString File =
ui
->AddFileLine->item(i)->text();
196
197
if
( !File.isEmpty() )
198
{
200
for
( QString & PathFile :
FolderPathList
)
201
{
202
if
( File.startsWith ( PathFile ) )
203
{
204
File = File.replace ( 0, PathFile.size(),
""
);
205
break
;
206
}
207
}
208
209
config::api::commands::file::add
(
DatabasePath
, File );
210
211
StatusBar
->setPalette ( QApplication::palette (
this
) );
212
StatusBar
->showMessage (
213
QString (
"The file %1 was added to the included files"
).arg ( File ) );
214
}
215
}
216
217
SetRemoveComboBox
();
218
219
ui
->AddFileLine->clear();
220
ui
->AddToIncludeButton->setDisabled (
true
);
221
}
222
223
void
dbe::IncludeFileWidget::AddNewFileToInclude
(
const
QString & File )
224
{
225
ui
->AddFileLine->clear();
226
227
QString includeFilePath;
228
includeFilePath = File;
229
230
if
( includeFilePath.isEmpty() )
231
{
232
return
;
233
}
234
235
QFileInfo includeFile = QFileInfo ( includeFilePath );
236
237
if
( !includeFile.isFile() )
238
{
239
StatusBar
->setPalette (
StyleUtility::AlertStatusBarPallete
);
240
StatusBar
->showMessage ( QString (
"The file is NOT accessible. Check before usage"
) );
241
}
242
else
243
{
244
QString fileToInclude;
245
246
if
(
Directory
.isEmpty() )
247
{
248
fileToInclude = includeFile.absoluteFilePath();
249
}
250
else
if
( ( includeFile.absoluteDir().canonicalPath() ).compare (
251
Directory
) == 0 ) fileToInclude =
252
includeFile.absoluteFilePath().remove (
Directory
+ QString (
'/'
), Qt::CaseSensitive );
253
else
254
{
255
fileToInclude = includeFile.absoluteFilePath();
256
}
257
258
ui
->AddFileLine->addItem( fileToInclude );
259
ui
->AddToIncludeButton->setDisabled(
false
);
260
}
261
}
262
263
void
dbe::IncludeFileWidget::RemoveFileFromInclude
()
264
{
265
if
(
ui
->RemoveCombo->currentIndex() != -1 )
266
{
267
BOOST_SCOPE_EXIT(
void
)
268
{
269
QApplication::restoreOverrideCursor();
270
}
271
BOOST_SCOPE_EXIT_END
272
273
QApplication::setOverrideCursor(Qt::WaitCursor);
274
275
QString File =
ui
->RemoveCombo->currentText();
276
277
config::api::commands::file::remove
(
DatabasePath
, File );
278
Removed
=
true
;
279
StatusBar
->setPalette ( QApplication::palette (
this
) );
280
StatusBar
->showMessage (
281
QString (
"The file %1 was removed from the included files"
).arg ( File ) );
282
SetRemoveComboBox
();
283
}
284
else
285
{
286
StatusBar
->setPalette (
StyleUtility::AlertStatusBarPallete
);
287
StatusBar
->showMessage (
288
QString (
"The file is NOT selected. Use combo box to select one."
) );
289
}
290
}
291
292
void
dbe::IncludeFileWidget::RemoveFileFromInclude
(
int
)
293
{
294
if
(
ui
->RemoveCombo->currentIndex() != -1 )
295
{
296
ui
->RemoveButton->setEnabled (
true
);
297
StatusBar
->setPalette ( QApplication::palette (
this
) );
298
StatusBar
->showMessage (
299
QString (
"The file %1 will be removed from the included files of %2"
).arg (
300
QFileInfo (
ui
->RemoveCombo->currentText() ).fileName() ).arg (
301
QFileInfo (
DatabasePath
).fileName() ) );
302
}
303
}
304
305
void
dbe::IncludeFileWidget::SetDirectory
(
const
QString & Dir )
306
{
307
if
(
dbPath
.contains(Dir, Qt::CaseSensitivity::CaseSensitive) && QDir(Dir).exists()) {
308
Directory
= Dir;
309
SelectFile
->setDirectory (
Directory
);
310
}
else
{
311
Directory
.clear();
312
SelectFile
->setDirectory(QDir(
"."
));
313
}
314
}
315
316
void
dbe::IncludeFileWidget::CheckInclude
()
317
{
318
SetRemoveComboBox
();
319
320
if
(
ui
->AddFileLine->count() == 0 )
321
{
322
StatusBar
->setPalette (
StyleUtility::AlertStatusBarPallete
);
323
StatusBar
->showMessage ( QString (
"Select existing file!"
) );
324
ui
->AddToIncludeButton->setDisabled (
true
);
325
326
return
;
327
}
328
329
std::vector<int> removedItems;
330
for
(
int
i = 0; i <
ui
->AddFileLine->count(); ++i) {
331
const
QString inc =
ui
->AddFileLine->item(i)->text();
332
333
if
(inc ==
DatabasePath
) {
334
removedItems.push_back(i);
335
}
else
{
336
for
(
int
j = 0; j <
ui
->RemoveCombo->count(); ++j) {
337
if
(
ui
->RemoveCombo->itemText(j).compare(inc) == 0) {
338
removedItems.push_back(i);
339
}
340
}
341
}
342
}
343
344
if
(removedItems.empty() ==
false
) {
345
QString message =
"The following files will not be included because already included:"
;
346
347
for
(
int
i : removedItems) {
348
QListWidgetItem* item =
ui
->AddFileLine->takeItem(i);
349
message +=
"\n- "
+ item->text();
350
delete
item;
351
}
352
353
WARN
(
"File inclusion issue"
, message.toStdString());
354
}
355
356
ui
->AddToIncludeButton->setDisabled((
ui
->AddFileLine->count() == 0) ?
true
:
false
);
357
}
358
359
void
dbe::IncludeFileWidget::CreateFileToInclude
()
360
{
361
CreateWidget
=
new
CreateDatabaseWidget
(
nullptr
,
true
,
Directory
);
362
connect (
CreateWidget
, SIGNAL ( CanIncludeDatabase (
const
QString & ) ),
this
,
363
SLOT (
AddNewFileToInclude
(
const
QString & ) ), Qt::UniqueConnection );
364
CreateWidget
->show();
365
}
Exceptions.hpp
IncludeFileWidget.hpp
MainWindow.hpp
StyleUtility.hpp
dbe::CreateDatabaseWidget
Definition
CreateDatabaseWidget.hpp:25
dbe::IncludeFileWidget::SetDirectory
void SetDirectory(const QString &Dir)
Definition
IncludeFileWidget.cpp:305
dbe::IncludeFileWidget::AddNewFileToInclude
void AddNewFileToInclude(const QString &File)
Definition
IncludeFileWidget.cpp:223
dbe::IncludeFileWidget::~IncludeFileWidget
~IncludeFileWidget()
dbe::IncludeFileWidget::CreateWidget
CreateDatabaseWidget * CreateWidget
Definition
IncludeFileWidget.hpp:37
dbe::IncludeFileWidget::SelectFileToInclude
void SelectFileToInclude()
Definition
IncludeFileWidget.cpp:149
dbe::IncludeFileWidget::SetController
void SetController()
Definition
IncludeFileWidget.cpp:131
dbe::IncludeFileWidget::AddFileToInclude
void AddFileToInclude()
Definition
IncludeFileWidget.cpp:184
dbe::IncludeFileWidget::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Definition
IncludeFileWidget.cpp:106
dbe::IncludeFileWidget::IncludeFileWidget
IncludeFileWidget(QString FilePath, QWidget *parent=0)
Definition
IncludeFileWidget.cpp:24
dbe::IncludeFileWidget::ui
std::unique_ptr< dbe::Ui::IncludeFileWidget > ui
Definition
IncludeFileWidget.hpp:35
dbe::IncludeFileWidget::Directory
QString Directory
Definition
IncludeFileWidget.hpp:39
dbe::IncludeFileWidget::SetRemoveComboBox
void SetRemoveComboBox()
Definition
IncludeFileWidget.cpp:114
dbe::IncludeFileWidget::SelectFile
QFileDialog * SelectFile
Definition
IncludeFileWidget.hpp:42
dbe::IncludeFileWidget::dbPath
QStringList dbPath
Definition
IncludeFileWidget.hpp:44
dbe::IncludeFileWidget::Removed
bool Removed
Definition
IncludeFileWidget.hpp:40
dbe::IncludeFileWidget::DatabasePath
QString DatabasePath
Definition
IncludeFileWidget.hpp:38
dbe::IncludeFileWidget::FolderPathList
QStringList FolderPathList
Definition
IncludeFileWidget.hpp:43
dbe::IncludeFileWidget::CreateFileToInclude
void CreateFileToInclude()
Definition
IncludeFileWidget.cpp:359
dbe::IncludeFileWidget::RemoveFileFromInclude
void RemoveFileFromInclude()
Definition
IncludeFileWidget.cpp:263
dbe::IncludeFileWidget::CheckInclude
void CheckInclude()
Definition
IncludeFileWidget.cpp:316
dbe::IncludeFileWidget::StatusBar
QStatusBar * StatusBar
Definition
IncludeFileWidget.hpp:41
dbe::MainWindow::findthis
static MainWindow * findthis()
Definition
MainWindow.cpp:1667
dbe::StyleUtility::AlertStatusBarPallete
static QPalette AlertStatusBarPallete
Definition
StyleUtility.hpp:29
dbe::config::api::get::file::inclusions_singlefile
static QStringList inclusions_singlefile(QString const &)
Definition
config_api_get.cpp:315
confaccessor.hpp
config_api_commands.hpp
config_api_get.hpp
messenger.hpp
WARN
#define WARN(...)
Definition
messenger.hpp:85
Ui
Definition
SchemaSettings.hpp:10
dbe::config::api::commands::file::remove
void remove(QString const &db, QString const &fn)
Definition
config_api_commands.cpp:301
dbe::config::api::commands::file::add
void add(QString const &db, QString const &fn)
Definition
config_api_commands.cpp:323
Generated on
for DUNE-DAQ by
1.17.0