DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
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"
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>
21
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{
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
42void
44{
45 LaunchIncludeEditor = new QAction(tr("Add/Remove Files"), this);
46 LaunchIncludeEditor->setShortcutContext(Qt::WidgetShortcut);
47 connect(LaunchIncludeEditor, SIGNAL(triggered()), this, SLOT(LaunchIncludeEditorSlot()));
49
50 m_file_info_action = new QAction(tr("File &information"));
51 connect(m_file_info_action, SIGNAL(triggered()), this, SLOT(file_info_slot()));
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)));
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
69void
71{
72 connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(ChangeSelection(QModelIndex)));
73}
74
75void
77{
78 if (ContextMenu == nullptr) {
79 ContextMenu = new QMenu(this);
81 }
82}
83
84void
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
106void
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()));
152 }
153 }
154}
155
156void
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);
171 } else {
172 ListIndex = 0;
173 scrollTo(ListOfMatch.value(ListIndex), QAbstractItemView::EnsureVisible);
174 selectRow(ListOfMatch.value(ListIndex).row());
175 resizeColumnToContents(ListIndex);
177 }
178 }
179}
180
181void
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
230void
235
236void
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
246void
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
258void
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
272void
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
284void
286{
287 QString Dummy("Dummy");
288 EditedSearchString(Dummy);
289}
290
291void
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(QWidget *parent=nullptr)
Including QT Headers.
void ChangeSelection(QModelIndex Index)
QCheckBox * CaseSensitiveCheckBox
QCheckBox * WholeWordCheckBox
void contextMenuEvent(QContextMenuEvent *Event)
Reimplemented functions.
QModelIndexList ListOfMatch
QPushButton * NextButton
void HideReadOnlyFilesSlot(bool Hide)
void stateChanged(const QString &FileName)
QMenu * ContextMenu
Context menu with the possible actions.
QDialog * FindFileDialog
File Dialog.
int ListIndex
Match Variables.
void EditedSearchString(QString Text)
static void show_file_info(const QString &filename)
Definition FileInfo.cpp:505
IncludeFileWidget(QString FilePath, QWidget *parent=0)