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 <QContextMenuEvent>
8#include <QHBoxLayout>
9#include <QHeaderView>
10#include <QLabel>
11#include <QShortcut>
15
17 : QTableView ( parent ),
18 ContextMenu ( nullptr ),
19 LaunchIncludeEditor ( nullptr ),
20 HideReadOnlyFiles ( nullptr ),
21 FindFile ( nullptr ),
22 FindFileDialog ( nullptr ),
23 LineEdit ( nullptr ),
24 NextButton ( nullptr ),
25 GoButton ( nullptr )
26{
29 setSelectionBehavior ( SelectionBehavior::SelectRows );
30 horizontalHeader()->setSectionResizeMode ( QHeaderView::ResizeMode::Stretch );
31 setSortingEnabled ( true );
32}
33
35{
36 QShortcut * Shortcut = new QShortcut ( QKeySequence ( tr ( "Ctrl+F" ) ), this );
37
38 FindFile = new QAction ( tr ( "Find File" ), this );
39 FindFile->setShortcut ( QKeySequence ( tr ( "Ctrl+F" ) ) );
40 FindFile->setShortcutContext ( Qt::WidgetShortcut );
41 connect ( FindFile, SIGNAL ( triggered() ), this, SLOT ( FindFileSlot() ) );
42 connect ( Shortcut, SIGNAL ( activated() ), this, SLOT ( FindFileSlot() ) );
43 ContextMenu->addAction ( FindFile );
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 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
61{
62 connect ( this, SIGNAL ( clicked ( QModelIndex ) ), this,
63 SLOT ( ChangeSelection ( QModelIndex ) ) );
64}
65
67{
68 if ( ContextMenu == nullptr )
69 {
70 ContextMenu = new QMenu ( this );
71 CreateActions();
72 }
73}
74
75void dbe::CustomFileView::contextMenuEvent ( QContextMenuEvent * Event )
76{
77 QModelIndex Index = indexAt ( Event->pos() );
78
79 if ( Index.isValid() )
80 {
81 setCurrentIndex ( Index );
82 selectionModel()->setCurrentIndex ( Index, QItemSelectionModel::NoUpdate );
83 ContextMenu->exec ( Event->globalPos() );
84 }
85}
86
88{
89 ListIndex = 0;
90 ListOfMatch.clear();
91
92 QString UserType = LineEdit->text();
93
94 if ( UserType.isEmpty() )
95 {
96 return;
97 }
98
99 QAbstractItemModel * Model = model();
100
101 if ( Model != nullptr )
102 {
103 QVariant StringCriterium = QVariant ( UserType );
104
105 QModelIndex find_by_name = Model->index ( 0, 0 );
106 QModelIndex find_by_path = Model->index ( 0, 1 );
107
108 Qt::MatchFlags options = Qt::MatchContains;
109
110 if ( CaseSensitiveCheckBox->isChecked() )
111 {
112 options = options | Qt::MatchCaseSensitive;
113 }
114
115 if ( WholeWordCheckBox->isChecked() )
116 {
117 options = Qt::MatchExactly;
118 }
119
120 ListOfMatch = Model->match ( find_by_name, Qt::DisplayRole, StringCriterium, 1000,
121 options );
122
123 ListOfMatch.append (
124 Model->match ( find_by_path, Qt::DisplayRole, StringCriterium, 1000, options ) );
125
126 if ( ListOfMatch.size() > 0 )
127 {
128 ListIndex = 0;
129 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
130 selectRow ( ListOfMatch.value ( ListIndex ).row() );
131 resizeColumnToContents ( ListIndex );
132
133 GoButton->setDisabled ( true );
134 NextButton->setEnabled ( true );
135
136 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
137 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
138 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
139 }
140 }
141}
142
144{
145 if ( ( LineEdit->text() ).isEmpty() )
146 {
147 ListIndex = 0;
148 ListOfMatch.clear();
149 return;
150 }
151
152 if ( ListOfMatch.size() > 0 )
153 {
154 if ( ( ++ListIndex ) < ListOfMatch.size() )
155 {
156 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
157 selectRow ( ListOfMatch.value ( ListIndex ).row() );
158 resizeColumnToContents ( ListIndex );
159 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
160 }
161 else
162 {
163 ListIndex = 0;
164 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
165 selectRow ( ListOfMatch.value ( ListIndex ).row() );
166 resizeColumnToContents ( ListIndex );
167 ChangeSelection ( ListOfMatch.at ( ListIndex ) );
168 }
169 }
170}
171
173{
174 if ( FindFileDialog != nullptr )
175 {
176 delete FindFileDialog;
177 FindFileDialog = nullptr;
178 }
179
180 FindFileDialog = new QDialog ( this );
181 FindFileDialog->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
182 FindFileDialog->setToolTip ( "Type string to edit line and press Enter." );
183 FindFileDialog->setWindowTitle ( "Search for a file name in the table" );
184
185 QHBoxLayout * FileLayout = new QHBoxLayout();
186 QLabel * Label = new QLabel ( QString ( "Find File:" ) );
187 NextButton = new QPushButton ( "Next" );
188 GoButton = new QPushButton ( "Go !" );
189 LineEdit = new QLineEdit();
190 LineEdit->setToolTip ( "Type string and press Enter" );
191
192 FileLayout->addWidget ( Label );
193 FileLayout->addWidget ( LineEdit );
194 FileLayout->addWidget ( GoButton );
195 FileLayout->addWidget ( NextButton );
196
197 QHBoxLayout * ButtonsLayout = new QHBoxLayout();
198 WholeWordCheckBox = new QCheckBox ( "Whole String" );
199 CaseSensitiveCheckBox = new QCheckBox ( "Case Sensitive" );
200
201 ButtonsLayout->addWidget ( WholeWordCheckBox );
202 ButtonsLayout->addWidget ( CaseSensitiveCheckBox );
203
204 QVBoxLayout * FindDialogLayout = new QVBoxLayout();
205 FindDialogLayout->addItem ( FileLayout );
206 FindDialogLayout->addItem ( ButtonsLayout );
207
208 FindFileDialog->setLayout ( FindDialogLayout );
209 FindFileDialog->show();
210 //NextButton->setDisabled(true);
211
212 connect ( LineEdit, SIGNAL ( textEdited ( QString ) ), this,
213 SLOT ( EditedSearchString ( QString ) ) );
214 connect ( WholeWordCheckBox, SIGNAL ( clicked() ), this, SLOT ( EditedSearchString() ) );
215 connect ( CaseSensitiveCheckBox, SIGNAL ( clicked() ), this,
216 SLOT ( EditedSearchString() ) );
217
218 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
219 connect ( GoButton, SIGNAL ( clicked() ), this, SLOT ( GoToFile() ) );
220 connect ( NextButton, SIGNAL ( clicked() ), this, SLOT ( GoToNext() ) );
221}
222
224{
225 QModelIndex Index = currentIndex();
226 QString Data = model()->data ( model()->index ( Index.row(), 1,
227 Index.parent() ) ).toString();
228
229 IncludeFileWidget * FileWidget = new IncludeFileWidget ( Data );
230 FileWidget->show();
231}
232
234{
235 for ( int i = 0; i < model()->rowCount(); ++i )
236 {
237 if ( model()->data ( model()->index ( i, 2 ) ).toString() == "RO" )
238 {
239 if ( Hide )
240 {
241 hideRow ( i );
242 }
243 else
244 {
245 showRow ( i );
246 }
247 }
248 }
249}
250
252{
253 Q_UNUSED ( Text )
254
255 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
256 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
257
258 GoButton->setEnabled ( true );
259 NextButton->setDisabled ( true );
260}
261
263{
264 QString Dummy ( "Dummy" );
265 EditedSearchString ( Dummy );
266}
267
268void dbe::CustomFileView::ChangeSelection ( QModelIndex Index )
269{
270 QString Data = model()->data ( model()->index ( Index.row(), 1,
271 Index.parent() ) ).toString();
272 emit stateChanged ( Data );
273}
CustomFileView(QWidget *parent=nullptr)
Including QT Headers.
void ChangeSelection(QModelIndex Index)
void contextMenuEvent(QContextMenuEvent *Event)
Reimplemented functions.
void HideReadOnlyFilesSlot(bool Hide)