DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CustomTableView.cpp
Go to the documentation of this file.
1
3
5#include <QScrollBar>
6#include <QMenu>
7#include <QLabel>
8#include <QHBoxLayout>
9#include <QContextMenuEvent>
10#include <QDialog>
11#include <QLineEdit>
12#include <QVariant>
13#include <QHeaderView>
14
17#include "dbe/ObjectEditor.hpp"
18#include "dbe/ObjectCreator.hpp"
19#include "dbe/messenger.hpp"
20
21#include "dbe/MainWindow.hpp"
22
23//-----------------------------------------------------------------------------------------------------
25 : QTableView ( parent ),
26 ContextMenu ( nullptr ),
27 FindObject ( nullptr ),
28 editObject ( nullptr ),
29 deleteObjectAc ( nullptr ),
30 refByAc ( nullptr ),
31 refByAcOnlyComp ( nullptr ),
32 copyObjectAc ( nullptr ),
33 FindFileDialog ( nullptr ),
34 LineEdit ( nullptr ),
35 NextButton ( nullptr ),
36 GoButton ( nullptr ),
37 ListIndex ( 0 )
38{
39 verticalHeader()->setVisible(true);
40 verticalHeader()->setSectionResizeMode ( QHeaderView::Interactive );
41 verticalHeader()->setMinimumSectionSize(40);
42 horizontalHeader()->setSectionResizeMode( QHeaderView::Interactive );
43 horizontalHeader()->setDefaultSectionSize(250);
44 setSortingEnabled ( true );
45 setAlternatingRowColors ( true );
46 setSelectionMode ( SelectionMode::SingleSelection );
47 setHorizontalScrollMode(ScrollMode::ScrollPerPixel);
48 setVerticalScrollMode(ScrollMode::ScrollPerPixel);
49 setWordWrap(true);
50 setTextElideMode(Qt::ElideRight);
51}
52//-----------------------------------------------------------------------------------------------------
53
54//-----------------------------------------------------------------------------------------------------
55void dbe::CustomTableView::contextMenuEvent ( QContextMenuEvent * Event )
56{
57 if ( ContextMenu == nullptr )
58 {
59 ContextMenu = new QMenu ( this );
60 CreateActions();
61 }
62
63 QModelIndex Index = indexAt ( Event->pos() );
64
65 if ( Index.isValid() )
66 {
67 ContextMenu->exec ( Event->globalPos() );
68 }
69}
70//-----------------------------------------------------------------------------------------------------
71
72//-----------------------------------------------------------------------------------------------------
74{
75 if ( FindFileDialog != nullptr )
76 {
77 delete FindFileDialog;
78 FindFileDialog = nullptr;
79 }
80
81 FindFileDialog = new QDialog ( this );
82 FindFileDialog->setSizePolicy ( QSizePolicy::Preferred, QSizePolicy::Preferred );
83 FindFileDialog->setToolTip ( "Type string to edit line and press Enter." );
84 FindFileDialog->setWindowTitle ( "Search for an object in the table" );
85
86 QHBoxLayout * Layout = new QHBoxLayout ( FindFileDialog );
87 QLabel * Label = new QLabel ( QString ( "Find Object:" ), FindFileDialog );
88
89 NextButton = new QPushButton ( "Next" );
90 GoButton = new QPushButton ( "Go !" );
91
92 LineEdit = new QLineEdit ( FindFileDialog );
93 LineEdit->setToolTip ( "Type string and press Enter" );
94
95 Layout->addWidget ( Label );
96 Layout->addWidget ( LineEdit );
97 Layout->addWidget ( GoButton );
98 Layout->addWidget ( NextButton );
99
100 FindFileDialog->setLayout ( Layout );
101 FindFileDialog->show();
102 NextButton->setDisabled ( true );
103
104 connect ( LineEdit, SIGNAL ( textEdited ( QString ) ), this,
105 SLOT ( EditedSearchString ( QString ) ) );
106 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
107 connect ( GoButton, SIGNAL ( clicked() ), this, SLOT ( GoToFile() ) );
108 connect ( NextButton, SIGNAL ( clicked() ), this, SLOT ( GoToNext() ) );
109}
110//-----------------------------------------------------------------------------------------------------
111
112//-----------------------------------------------------------------------------------------------------
114{
115 ListIndex = 0;
116 ListOfMatch.clear();
117
118 QString UserType = LineEdit->text();
119
120 if ( UserType.isEmpty() )
121 {
122 return;
123 }
124
125 QAbstractItemModel * Model = model();
126
127 if ( Model != nullptr )
128 {
129 QVariant StringCriterium = QVariant ( UserType );
130 QModelIndex WhereToStartSearch = Model->index ( 0, 0 );
131 ListOfMatch = Model->match ( WhereToStartSearch, Qt::DisplayRole, StringCriterium, 1000,
132 Qt::MatchContains | Qt::MatchWrap );
133
134 if ( ListOfMatch.size() > 0 )
135 {
136 ListIndex = 0;
137 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
138 selectRow ( ListOfMatch.value ( ListIndex ).row() );
139 resizeColumnToContents ( ListIndex );
140
141 GoButton->setDisabled ( true );
142 NextButton->setEnabled ( true );
143
144 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
145 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
146 }
147 }
148}
149//-----------------------------------------------------------------------------------------------------
150
151//-----------------------------------------------------------------------------------------------------
153{
154 if ( ( LineEdit->text() ).isEmpty() )
155 {
156 ListIndex = 0;
157 ListOfMatch.clear();
158 return;
159 }
160
161 if ( ListOfMatch.size() > 0 )
162 {
163 if ( ( ++ListIndex ) < ListOfMatch.size() )
164 {
165 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
166 selectRow ( ListOfMatch.value ( ListIndex ).row() );
167 resizeColumnToContents ( ListIndex );
168 }
169 else
170 {
171 ListIndex = 0;
172 scrollTo ( ListOfMatch.value ( ListIndex ), QAbstractItemView::EnsureVisible );
173 selectRow ( ListOfMatch.value ( ListIndex ).row() );
174 resizeColumnToContents ( ListIndex );
175 }
176 }
177}
178//-----------------------------------------------------------------------------------------------------
179
180//-----------------------------------------------------------------------------------------------------
182{
183 Q_UNUSED ( Text )
184
185 connect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToFile() ) );
186 disconnect ( LineEdit, SIGNAL ( returnPressed() ), this, SLOT ( GoToNext() ) );
187
188 GoButton->setEnabled ( true );
189 NextButton->setDisabled ( true );
190}
191//-----------------------------------------------------------------------------------------------------
192
193//-----------------------------------------------------------------------------------------------------
195{
196 QModelIndex const & index = this->currentIndex();
197
198 if ( index.isValid() )
199 {
200 if ( models::tableselection const * selectionmodel =
201 dynamic_cast<models::tableselection const *> ( index.model() ) )
202 {
203 if ( models::table const * srcmodel =
204 dynamic_cast<const dbe::models::table *> ( selectionmodel->sourceModel() ) )
205 {
206 tref obj = srcmodel->GetTableObject ( selectionmodel->mapToSource ( index ).row() );
207
208 if ( not obj.is_null() )
209 {
210 emit OpenEditor ( obj );
211 }
212 }
213 }
214 }
215}
216//-----------------------------------------------------------------------------------------------------
217
218//-----------------------------------------------------------------------------------------------------
220{
221 QModelIndex const & Index = this->currentIndex();
222
223 const dbe::models::tableselection * Model =
224 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
225
226 const dbe::models::table * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
227 ->sourceModel() );
228
229 if ( !Index.isValid() || !Model )
230 {
231 return;
232 }
233
234 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
235 referencedBy ( obj, true );
236}
237//-----------------------------------------------------------------------------------------------------
238
239//-----------------------------------------------------------------------------------------------------
241{
242 QModelIndex const & Index = this->currentIndex();
243 const dbe::models::tableselection * Model =
244 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
245
246 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
247 ->sourceModel() );
248
249 if ( !Index.isValid() || !Model )
250 {
251 return;
252 }
253
254 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
255 referencedBy ( obj, false );
256}
257//-----------------------------------------------------------------------------------------------------
258
259//-----------------------------------------------------------------------------------------------------
261{
262 QModelIndex const & Index = this->currentIndex();
263
264 dbe::models::tableselection const * Model =
265 dynamic_cast<const dbe::models::tableselection *> ( Index.model() );
266
267 dbe::models::table const * SourceModel = dynamic_cast<const dbe::models::table *> ( Model
268 ->sourceModel() );
269
270 if ( Index.isValid() and Model )
271 {
272 tref obj = SourceModel->GetTableObject ( Model->mapToSource ( Index ).row() );
273
274 if ( not obj.is_null() )
275 {
276 ( new ObjectCreator ( obj ) )->show();
277 }
278 }
279}
280//-----------------------------------------------------------------------------------------------------
281
282//-----------------------------------------------------------------------------------------------------
284{
285 // TODO implement dbe::CustomTableView::slot_create_object
286 throw std::string ( " dbe::CustomTableView::slot_create_object is not yet implemented " );
287}
288//-----------------------------------------------------------------------------------------------------
289
290//-----------------------------------------------------------------------------------------------------
292{
293 if ( this->model() != nullptr )
294 {
295 QModelIndexList qindices = this->selectedIndexes();
296 std::vector<QModelIndex> indices;
297
298 for ( QModelIndex q : qindices )
299 {
300 if ( q.isValid() )
301 {
302 indices.push_back ( q );
303 }
304 }
305
306 if ( dbe::models::tableselection * casted =
307 dynamic_cast<dbe::models::tableselection *> ( this->model() ) )
308 {
309 casted->delete_objects ( indices.begin(), indices.end() );
310 }
311 else if ( dbe::models::table * casted = dynamic_cast<dbe::models::table *>
312 ( this->model() ) )
313 {
314 casted->delete_objects ( indices.begin(), indices.end() );
315 }
316 else
317 {
318 WARN ( "Object Deleting",
319 "Object deletion failed due to the internal model being in invalid state",
320 "You are advised to restart the application before proceeding any further" );
321 }
322 }
323
324}
325//-----------------------------------------------------------------------------------------------------
326
327//-----------------------------------------------------------------------------------------------------
329{
330 FindObject = new QAction ( tr ( "Find Object" ), this );
331 FindObject->setShortcutContext ( Qt::WidgetShortcut );
332 connect ( FindObject, SIGNAL ( triggered() ), this, SLOT ( FindObjectSlot() ) );
333 ContextMenu->addAction ( FindObject );
334
335 editObject = new QAction ( tr ( "&Edit Object" ), this );
336 editObject->setShortcut ( tr ( "Ctrl+E" ) );
337 editObject->setShortcutContext ( Qt::WidgetShortcut );
338 connect ( editObject, SIGNAL ( triggered() ), this, SLOT ( slot_edit_object() ) );
339 ContextMenu->addAction ( editObject );
340
341 deleteObjectAc = new QAction ( tr ( "&Delete Object" ), this );
342 deleteObjectAc->setShortcut ( tr ( "Ctrl+D" ) );
343 deleteObjectAc->setShortcutContext ( Qt::WidgetShortcut );
344 connect ( deleteObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_delete_objects() ) );
345 ContextMenu->addAction ( deleteObjectAc );
346
347 refByAc = new QAction ( tr ( "Referenced B&y (All objects)" ), this );
348 refByAc->setShortcut ( tr ( "Ctrl+Y" ) );
349 refByAc->setShortcutContext ( Qt::WidgetShortcut );
350 refByAc->setToolTip ( "Find all objects which reference the selected object" );
351 refByAc->setStatusTip ( refByAc->toolTip() );
352 connect ( refByAc, SIGNAL ( triggered() ), this, SLOT ( referencedBy_All() ) );
353 ContextMenu->addAction ( refByAc );
354
355 refByAcOnlyComp = new QAction ( tr ( "Referenced B&y (Only Composite)" ), this );
356 refByAcOnlyComp->setShortcut ( tr ( "Ctrl+Shift+Y" ) );
357 refByAcOnlyComp->setShortcutContext ( Qt::WidgetShortcut );
358 refByAcOnlyComp->setToolTip (
359 "Find objects (ONLY Composite ones) which reference the selected object" );
360 refByAcOnlyComp->setStatusTip ( refByAcOnlyComp->toolTip() );
361 connect ( refByAcOnlyComp, SIGNAL ( triggered() ), this,
362 SLOT ( referencedBy_OnlyComposite() ) );
363 ContextMenu->addAction ( refByAcOnlyComp );
364
365 copyObjectAc = new QAction ( tr ( "Copy This Object Into A &New One" ), this );
366 copyObjectAc->setShortcut ( tr ( "Ctrl+Shift+N" ) );
367 copyObjectAc->setShortcutContext ( Qt::WidgetShortcut );
368 connect ( copyObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_copy_object() ) );
369 ContextMenu->addAction ( copyObjectAc );
370}
371//-----------------------------------------------------------------------------------------------------
372
373//-----------------------------------------------------------------------------------------------------
374void dbe::CustomTableView::referencedBy ( tref obj, bool onlyComposite )
375{
376 if ( not obj.is_null() )
377 {
378 MainWindow::findthis()->get_view()->referencedBy ( onlyComposite, obj );
379 }
380}
381//-----------------------------------------------------------------------------------------------------
382
CustomTableView(QWidget *parent=0)
Including QT#include <QHeaderView>
void referencedBy(tref obj, bool onlyComposite)
void EditedSearchString(QString Text)
void contextMenuEvent(QContextMenuEvent *Event)
cptr< dbe::CustomTreeView > get_view() const
static MainWindow * findthis()
tref GetTableObject(int ObjectIndex) const
Definition table.cpp:430
#define WARN(...)
Definition messenger.hpp:80