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 <QMenu>
12#include <QMessageBox>
13#include <QContextMenuEvent>
14#include <QHBoxLayout>
15#include <QHeaderView>
16#include <QLabel>
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)),
40 this, SLOT(file_info_slot(QModelIndex)) );
41}
42
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
74{
75 connect ( this, SIGNAL ( clicked ( QModelIndex ) ), this,
76 SLOT ( ChangeSelection ( QModelIndex ) ) );
77}
78
80{
81 if ( ContextMenu == nullptr )
82 {
83 ContextMenu = new QMenu ( this );
85 }
86}
87
88void 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
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() ) );
164 }
165 }
166}
167
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 );
185 }
186 else
187 {
188 ListIndex = 0;
189 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
190 selectRow ( ListOfMatch.value ( ListIndex ).row() );
191 resizeColumnToContents ( ListIndex );
193 }
194 }
195}
196
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
249 file_info_slot(currentIndex());
250}
251
252void 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
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
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
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
305{
306 QString Dummy ( "Dummy" );
307 EditedSearchString ( Dummy );
308}
309
310void 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(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:454