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