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