DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
structure
CustomFileView.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/FileInfo.hpp
"
8
#include "
dbe/ui_constants.hpp
"
9
10
#include <QAction>
11
#include <QContextMenuEvent>
12
#include <QHBoxLayout>
13
#include <QHeaderView>
14
#include <QLabel>
15
#include <QMenu>
16
#include <QMessageBox>
17
#include <QShortcut>
19
#include "
dbe/CustomFileView.hpp
"
20
#include "
dbe/IncludeFileWidget.hpp
"
21
22
dbe::CustomFileView::CustomFileView
(QWidget* parent)
23
: QTableView(parent)
24
,
ContextMenu
(nullptr)
25
,
LaunchIncludeEditor
(nullptr)
26
,
HideReadOnlyFiles
(nullptr)
27
,
FindFile
(nullptr)
28
,
FindFileDialog
(nullptr)
29
,
LineEdit
(nullptr)
30
,
NextButton
(nullptr)
31
,
GoButton
(nullptr)
32
{
33
ConnectActions
();
34
CreateContextMenu
();
35
setSelectionBehavior(SelectionBehavior::SelectRows);
36
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::Stretch);
37
setSortingEnabled(
true
);
38
39
connect(
this
, SIGNAL(activated(QModelIndex)),
this
, SLOT(
file_info_slot
(QModelIndex)));
40
}
41
42
void
43
dbe::CustomFileView::CreateActions
()
44
{
45
LaunchIncludeEditor
=
new
QAction(tr(
"Add/Remove Files"
),
this
);
46
LaunchIncludeEditor
->setShortcutContext(Qt::WidgetShortcut);
47
connect(
LaunchIncludeEditor
, SIGNAL(triggered()),
this
, SLOT(
LaunchIncludeEditorSlot
()));
48
ContextMenu
->addAction(
LaunchIncludeEditor
);
49
50
m_file_info_action
=
new
QAction(tr(
"File &information"
));
51
connect(
m_file_info_action
, SIGNAL(triggered()),
this
, SLOT(
file_info_slot
()));
52
ContextMenu
->addAction(
m_file_info_action
);
53
54
HideReadOnlyFiles
=
new
QAction(tr(
"Hide Read Only Files"
),
this
);
55
HideReadOnlyFiles
->setShortcutContext(Qt::WidgetShortcut);
56
HideReadOnlyFiles
->setCheckable(
true
);
57
HideReadOnlyFiles
->setChecked(
false
);
58
connect(
HideReadOnlyFiles
, SIGNAL(triggered(
bool
)),
this
, SLOT(
HideReadOnlyFilesSlot
(
bool
)));
59
ContextMenu
->addAction(
HideReadOnlyFiles
);
60
61
FindFile
=
new
QAction(tr(
"Find File"
),
this
);
62
FindFile
->setShortcut(QKeySequence(tr(
"Ctrl+F"
)));
63
FindFile
->setShortcutContext(Qt::WidgetShortcut);
64
connect(
FindFile
, SIGNAL(triggered()),
this
, SLOT(
FindFileSlot
()));
65
// connect ( Shortcut, SIGNAL ( activated() ), this, SLOT ( FindFileSlot() ) );
66
ContextMenu
->addAction(
FindFile
);
67
}
68
69
void
70
dbe::CustomFileView::ConnectActions
()
71
{
72
connect(
this
, SIGNAL(clicked(QModelIndex)),
this
, SLOT(
ChangeSelection
(QModelIndex)));
73
}
74
75
void
76
dbe::CustomFileView::CreateContextMenu
()
77
{
78
if
(
ContextMenu
==
nullptr
) {
79
ContextMenu
=
new
QMenu(
this
);
80
CreateActions
();
81
}
82
}
83
84
void
85
dbe::CustomFileView::contextMenuEvent
(QContextMenuEvent* Event)
86
{
87
QModelIndex index = indexAt(Event->pos());
88
89
if
(index.isValid()) {
90
if
(model()->data(model()->index(index.row(), 2)).toString() ==
"RO"
) {
91
ContextMenu
->actions().at(0)->setVisible(
false
);
92
}
else
{
93
ContextMenu
->actions().at(0)->setVisible(
true
);
94
}
95
ContextMenu
->actions().at(1)->setVisible(
true
);
96
97
setCurrentIndex(index);
98
selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
99
}
else
{
100
ContextMenu
->actions().at(0)->setVisible(
false
);
101
ContextMenu
->actions().at(1)->setVisible(
false
);
102
}
103
ContextMenu
->exec(Event->globalPos());
104
}
105
106
void
107
dbe::CustomFileView::GoToFile
()
108
{
109
ListIndex
= 0;
110
ListOfMatch
.clear();
111
112
QString UserType =
LineEdit
->text();
113
114
if
(UserType.isEmpty()) {
115
return
;
116
}
117
118
QAbstractItemModel* Model = model();
119
120
if
(Model !=
nullptr
) {
121
QVariant StringCriterium = QVariant(UserType);
122
123
QModelIndex find_by_name = Model->index(0, 0);
124
QModelIndex find_by_path = Model->index(0, 1);
125
126
Qt::MatchFlags options = Qt::MatchContains;
127
128
if
(
CaseSensitiveCheckBox
->isChecked()) {
129
options = options | Qt::MatchCaseSensitive;
130
}
131
132
if
(
WholeWordCheckBox
->isChecked()) {
133
options = Qt::MatchExactly;
134
}
135
136
ListOfMatch
= Model->match(find_by_name, Qt::DisplayRole, StringCriterium, 1000, options);
137
138
ListOfMatch
.append(Model->match(find_by_path, Qt::DisplayRole, StringCriterium, 1000, options));
139
140
if
(
ListOfMatch
.size() > 0) {
141
ListIndex
= 0;
142
scrollTo(
ListOfMatch
.value(
ListIndex
), QAbstractItemView::EnsureVisible);
143
selectRow(
ListOfMatch
.value(
ListIndex
).row());
144
resizeColumnToContents(
ListIndex
);
145
146
GoButton
->setDisabled(
true
);
147
NextButton
->setEnabled(
true
);
148
149
disconnect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
GoToFile
()));
150
connect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
GoToNext
()));
151
ChangeSelection
(
ListOfMatch
.at(
ListIndex
));
152
}
153
}
154
}
155
156
void
157
dbe::CustomFileView::GoToNext
()
158
{
159
if
((
LineEdit
->text()).isEmpty()) {
160
ListIndex
= 0;
161
ListOfMatch
.clear();
162
return
;
163
}
164
165
if
(
ListOfMatch
.size() > 0) {
166
if
((++
ListIndex
) <
ListOfMatch
.size()) {
167
scrollTo(
ListOfMatch
.value(
ListIndex
), QAbstractItemView::EnsureVisible);
168
selectRow(
ListOfMatch
.value(
ListIndex
).row());
169
resizeColumnToContents(
ListIndex
);
170
ChangeSelection
(
ListOfMatch
.at(
ListIndex
));
171
}
else
{
172
ListIndex
= 0;
173
scrollTo(
ListOfMatch
.value(
ListIndex
), QAbstractItemView::EnsureVisible);
174
selectRow(
ListOfMatch
.value(
ListIndex
).row());
175
resizeColumnToContents(
ListIndex
);
176
ChangeSelection
(
ListOfMatch
.at(
ListIndex
));
177
}
178
}
179
}
180
181
void
182
dbe::CustomFileView::FindFileSlot
()
183
{
184
if
(
FindFileDialog
!=
nullptr
) {
185
delete
FindFileDialog
;
186
FindFileDialog
=
nullptr
;
187
}
188
189
FindFileDialog
=
new
QDialog(
this
);
190
FindFileDialog
->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
191
FindFileDialog
->setToolTip(
"Type string to edit line and press Enter."
);
192
FindFileDialog
->setWindowTitle(
"Search for a file name in the table"
);
193
194
QHBoxLayout* FileLayout =
new
QHBoxLayout();
195
QLabel* Label =
new
QLabel(QString(
"Find File:"
));
196
NextButton
=
new
QPushButton(
"Next"
);
197
GoButton
=
new
QPushButton(
"Go !"
);
198
LineEdit
=
new
QLineEdit();
199
LineEdit
->setToolTip(
"Type string and press Enter"
);
200
201
FileLayout->addWidget(Label);
202
FileLayout->addWidget(
LineEdit
);
203
FileLayout->addWidget(
GoButton
);
204
FileLayout->addWidget(
NextButton
);
205
206
QHBoxLayout* ButtonsLayout =
new
QHBoxLayout();
207
WholeWordCheckBox
=
new
QCheckBox(
"Whole String"
);
208
CaseSensitiveCheckBox
=
new
QCheckBox(
"Case Sensitive"
);
209
210
ButtonsLayout->addWidget(
WholeWordCheckBox
);
211
ButtonsLayout->addWidget(
CaseSensitiveCheckBox
);
212
213
QVBoxLayout* FindDialogLayout =
new
QVBoxLayout();
214
FindDialogLayout->addItem(FileLayout);
215
FindDialogLayout->addItem(ButtonsLayout);
216
217
FindFileDialog
->setLayout(FindDialogLayout);
218
FindFileDialog
->show();
219
// NextButton->setDisabled(true);
220
221
connect(
LineEdit
, SIGNAL(textEdited(QString)),
this
, SLOT(
EditedSearchString
(QString)));
222
connect(
WholeWordCheckBox
, SIGNAL(clicked()),
this
, SLOT(
EditedSearchString
()));
223
connect(
CaseSensitiveCheckBox
, SIGNAL(clicked()),
this
, SLOT(
EditedSearchString
()));
224
225
connect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
GoToFile
()));
226
connect(
GoButton
, SIGNAL(clicked()),
this
, SLOT(
GoToFile
()));
227
connect(
NextButton
, SIGNAL(clicked()),
this
, SLOT(
GoToNext
()));
228
}
229
230
void
231
dbe::CustomFileView::file_info_slot
()
232
{
233
file_info_slot
(currentIndex());
234
}
235
236
void
237
dbe::CustomFileView::file_info_slot
(QModelIndex index)
238
{
239
QString file = model()->data(model()->index(index.row(), 0, index.parent())).toString();
240
QString path = model()->data(model()->index(index.row(), 1, index.parent())).toString();
241
auto
full_name = path +
"/"
+ file;
242
243
FileInfo::show_file_info
(full_name);
244
}
245
246
void
247
dbe::CustomFileView::LaunchIncludeEditorSlot
()
248
{
249
QModelIndex index = currentIndex();
250
QString file = model()->data(model()->index(index.row(), 0, index.parent())).toString();
251
QString path = model()->data(model()->index(index.row(), 1, index.parent())).toString();
252
auto
full_name = path +
"/"
+ file;
253
auto
* file_widget =
new
IncludeFileWidget
(full_name);
254
255
file_widget->show();
256
}
257
258
void
259
dbe::CustomFileView::HideReadOnlyFilesSlot
(
bool
Hide)
260
{
261
for
(
int
i = 0; i < model()->rowCount(); ++i) {
262
if
(model()->data(model()->index(i, 2)).toString() ==
"RO"
) {
263
if
(Hide) {
264
hideRow(i);
265
}
else
{
266
showRow(i);
267
}
268
}
269
}
270
}
271
272
void
273
dbe::CustomFileView::EditedSearchString
(QString Text)
274
{
275
Q_UNUSED(Text)
276
277
connect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
GoToFile
()));
278
disconnect(
LineEdit
, SIGNAL(returnPressed()),
this
, SLOT(
GoToNext
()));
279
280
GoButton
->setEnabled(
true
);
281
NextButton
->setDisabled(
true
);
282
}
283
284
void
285
dbe::CustomFileView::EditedSearchString
()
286
{
287
QString Dummy(
"Dummy"
);
288
EditedSearchString
(Dummy);
289
}
290
291
void
292
dbe::CustomFileView::ChangeSelection
(QModelIndex index)
293
{
294
QString file = model()->data(model()->index(index.row(), 0, index.parent())).toString();
295
QString path = model()->data(model()->index(index.row(), 1, index.parent())).toString();
296
auto
full_name = path +
"/"
+ file;
297
emit
stateChanged
(full_name);
298
}
CustomFileView.hpp
FileInfo.hpp
IncludeFileWidget.hpp
dbe::CustomFileView::GoToFile
void GoToFile()
Definition
CustomFileView.cpp:107
dbe::CustomFileView::EditedSearchString
void EditedSearchString()
Definition
CustomFileView.cpp:285
dbe::CustomFileView::LineEdit
QLineEdit * LineEdit
Definition
CustomFileView.hpp:37
dbe::CustomFileView::CustomFileView
CustomFileView(QWidget *parent=nullptr)
Including QT Headers.
Definition
CustomFileView.cpp:22
dbe::CustomFileView::ChangeSelection
void ChangeSelection(QModelIndex Index)
Definition
CustomFileView.cpp:292
dbe::CustomFileView::CaseSensitiveCheckBox
QCheckBox * CaseSensitiveCheckBox
Definition
CustomFileView.hpp:41
dbe::CustomFileView::HideReadOnlyFiles
QAction * HideReadOnlyFiles
Definition
CustomFileView.hpp:32
dbe::CustomFileView::LaunchIncludeEditorSlot
void LaunchIncludeEditorSlot()
Definition
CustomFileView.cpp:247
dbe::CustomFileView::CreateActions
void CreateActions()
Definition
CustomFileView.cpp:43
dbe::CustomFileView::WholeWordCheckBox
QCheckBox * WholeWordCheckBox
Definition
CustomFileView.hpp:40
dbe::CustomFileView::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *Event)
Reimplemented functions.
Definition
CustomFileView.cpp:85
dbe::CustomFileView::ConnectActions
void ConnectActions()
Definition
CustomFileView.cpp:70
dbe::CustomFileView::GoToNext
void GoToNext()
Definition
CustomFileView.cpp:157
dbe::CustomFileView::ListOfMatch
QModelIndexList ListOfMatch
Definition
CustomFileView.hpp:44
dbe::CustomFileView::NextButton
QPushButton * NextButton
Definition
CustomFileView.hpp:38
dbe::CustomFileView::GoButton
QPushButton * GoButton
Definition
CustomFileView.hpp:39
dbe::CustomFileView::HideReadOnlyFilesSlot
void HideReadOnlyFilesSlot(bool Hide)
Definition
CustomFileView.cpp:259
dbe::CustomFileView::stateChanged
void stateChanged(const QString &FileName)
dbe::CustomFileView::ContextMenu
QMenu * ContextMenu
Context menu with the possible actions.
Definition
CustomFileView.hpp:30
dbe::CustomFileView::file_info_slot
void file_info_slot()
Definition
CustomFileView.cpp:231
dbe::CustomFileView::LaunchIncludeEditor
QAction * LaunchIncludeEditor
Definition
CustomFileView.hpp:31
dbe::CustomFileView::FindFileDialog
QDialog * FindFileDialog
File Dialog.
Definition
CustomFileView.hpp:36
dbe::CustomFileView::FindFile
QAction * FindFile
Definition
CustomFileView.hpp:33
dbe::CustomFileView::ListIndex
int ListIndex
Match Variables.
Definition
CustomFileView.hpp:43
dbe::CustomFileView::FindFileSlot
void FindFileSlot()
Definition
CustomFileView.cpp:182
dbe::CustomFileView::CreateContextMenu
void CreateContextMenu()
Definition
CustomFileView.cpp:76
dbe::CustomFileView::EditedSearchString
void EditedSearchString(QString Text)
Definition
CustomFileView.cpp:273
dbe::CustomFileView::m_file_info_action
QAction * m_file_info_action
Definition
CustomFileView.hpp:34
dbe::FileInfo::show_file_info
static void show_file_info(const QString &filename)
Definition
FileInfo.cpp:505
dbe::IncludeFileWidget::IncludeFileWidget
IncludeFileWidget(QString FilePath, QWidget *parent=0)
Definition
IncludeFileWidget.cpp:24
ui_constants.hpp
Generated on
for DUNE-DAQ by
1.18.0