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