DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::CustomTreeView Class Reference

#include <CustomTreeView.hpp>

Inheritance diagram for dbe::CustomTreeView:
[legend]
Collaboration diagram for dbe::CustomTreeView:
[legend]

Public Slots

void referencedBy (bool All)
void referencedBy (bool All, tref Object)

Signals

void OpenEditor (tref Object)

Public Member Functions

 CustomTreeView (QWidget *Parent=nullptr)
 Including QT Headers.
void contextMenuEvent (QContextMenuEvent *Event)
Public Member Functions inherited from dbe::view_common_interface
virtual ~view_common_interface ()=default
virtual void slot_delete_objects ()=0
virtual void slot_create_object ()=0
virtual void slot_edit_object ()=0
virtual void slot_copy_object ()=0

Protected Member Functions

void closeEvent (QCloseEvent *event) override

Private Slots

void slot_delete_objects ()
void slot_create_object ()
void slot_edit_object ()
void slot_copy_object ()
void referencedbyOnlycomposite ()
void referencedByAll ()

Private Member Functions

void edit_object (QModelIndex const &)
void CreateActions ()

Private Attributes

QMenu * contextMenu
QAction * editObjectAc
QAction * deleteObjectAc
QAction * createObjectAc
QAction * copyObjectAc
QAction * deleteObjectWidgetAc
QAction * hideShowAc
QAction * buildTableFromClassAc
QAction * expandAllAc
QAction * collapseAllAc
QAction * refByAc
QAction * refByAcOnlyComp

Detailed Description

Definition at line 23 of file CustomTreeView.hpp.

Constructor & Destructor Documentation

◆ CustomTreeView()

dbe::CustomTreeView::CustomTreeView ( QWidget * Parent = nullptr)
explicit

Including QT Headers.

Including DBE

Definition at line 26 of file CustomTreeView.cpp.

27 : QTreeView ( Parent ),
28 contextMenu ( nullptr )
29{
30 setDragEnabled ( true );
31 setSortingEnabled ( true );
32 setExpandsOnDoubleClick ( false );
34 setSelectionMode ( QAbstractItemView::ExtendedSelection );
35 setUniformRowHeights(true);
36}

Member Function Documentation

◆ closeEvent()

void dbe::CustomTreeView::closeEvent ( QCloseEvent * event)
overrideprotected

Definition at line 354 of file CustomTreeView.cpp.

354 {
355 // Reset the model when the widget is closed
356 // If not done, reference to removed objects may create issues
357 models::treeselection* filtermodel = dynamic_cast<models::treeselection*>(model());
358
359 setModel(nullptr);
360
361 if(filtermodel != nullptr) {
362 filtermodel->ResetQueryObjects();
363 filtermodel->deleteLater();
364 }
365
366 event->accept();
367}

◆ contextMenuEvent()

void dbe::CustomTreeView::contextMenuEvent ( QContextMenuEvent * Event)

Definition at line 40 of file CustomTreeView.cpp.

41{
42 if ( contextMenu == nullptr )
43 {
44 contextMenu = new QMenu ( this );
45 contextMenu->addAction ( editObjectAc );
46 contextMenu->addAction ( deleteObjectAc );
47 contextMenu->addAction ( createObjectAc );
48 contextMenu->addAction ( deleteObjectWidgetAc );
49 contextMenu->addAction ( copyObjectAc );
51 contextMenu->addAction ( expandAllAc );
52 contextMenu->addAction ( collapseAllAc );
53 contextMenu->addAction ( refByAc );
54 contextMenu->addAction ( refByAcOnlyComp );
55 }
56
57 model_common_interface * modelInterface =
58 dynamic_cast<model_common_interface *> ( this->model() );
59 QModelIndex index = this->currentIndex();
60
61 if ( index.isValid() )
62 {
63 if ( modelInterface )
64 {
65
66 try
67 {
68 tref obj = modelInterface->getobject ( index );
69 ( contextMenu->actions() ).at ( 0 )->setVisible ( true );
70 ( contextMenu->actions() ).at ( 1 )->setVisible ( true );
71 ( contextMenu->actions() ).at ( 2 )->setVisible ( true );
72 ( contextMenu->actions() ).at ( 3 )->setVisible ( false );
73 ( contextMenu->actions() ).at ( 4 )->setVisible ( true );
74 ( contextMenu->actions() ).at ( 5 )->setVisible ( false );
75 ( contextMenu->actions() ).at ( 6 )->setVisible ( false );
76 ( contextMenu->actions() ).at ( 7 )->setVisible ( false );
77 ( contextMenu->actions() ).at ( 8 )->setVisible ( true );
78 ( contextMenu->actions() ).at ( 9 )->setVisible ( true );
79 }
80 catch ( daq::dbe::cannot_handle_invalid_qmodelindex const & e )
81 {
82 ( contextMenu->actions() ).at ( 0 )->setVisible ( false );
83 ( contextMenu->actions() ).at ( 1 )->setVisible ( false );
84 ( contextMenu->actions() ).at ( 2 )->setVisible ( true );
85 ( contextMenu->actions() ).at ( 3 )->setVisible ( false );
86 ( contextMenu->actions() ).at ( 4 )->setVisible ( false );
87 ( contextMenu->actions() ).at ( 5 )->setVisible ( false );
88 ( contextMenu->actions() ).at ( 6 )->setVisible ( false );
89 ( contextMenu->actions() ).at ( 7 )->setVisible ( false );
90 ( contextMenu->actions() ).at ( 8 )->setVisible ( false );
91 ( contextMenu->actions() ).at ( 9 )->setVisible ( false );
92 }
93 }
94
95 contextMenu->exec ( Event->globalPos() );
96 }
97}
QAction * buildTableFromClassAc
inner::configobject::tref tref
Definition tref.hpp:35

◆ CreateActions()

void dbe::CustomTreeView::CreateActions ( )
private

Definition at line 101 of file CustomTreeView.cpp.

102{
103
104 editObjectAc = new QAction ( tr ( "&Edit Object" ), this );
105 editObjectAc->setShortcut ( tr ( "Ctrl+E" ) );
106 editObjectAc->setShortcutContext ( Qt::WidgetShortcut );
107 connect ( editObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_edit_object() ) );
108 addAction ( editObjectAc );
109
110 deleteObjectAc = new QAction ( tr ( "&Delete Object" ), this );
111 deleteObjectAc->setShortcut ( tr ( "Ctrl+D" ) );
112 deleteObjectAc->setShortcutContext ( Qt::WidgetShortcut );
113 connect ( deleteObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_delete_objects() ) );
114 addAction ( deleteObjectAc );
115
116 createObjectAc = new QAction ( tr ( "Create &New Object" ), this );
117 createObjectAc->setShortcut ( tr ( "Ctrl+N" ) );
118 createObjectAc->setShortcutContext ( Qt::WidgetShortcut );
119 connect ( createObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_create_object() ) );
120 addAction ( createObjectAc );
121
122 copyObjectAc = new QAction ( tr ( "&Copy This Object Into A New One" ), this );
123 copyObjectAc->setShortcut ( tr ( "Ctrl+Shift+N" ) );
124 copyObjectAc->setShortcutContext ( Qt::WidgetShortcut );
125 connect ( copyObjectAc, SIGNAL ( triggered() ), this, SLOT ( slot_copy_object() ) );
126 addAction ( copyObjectAc );
127
128 deleteObjectWidgetAc = new QAction ( tr ( "Delete Object &Widget" ), this );
129 deleteObjectWidgetAc->setShortcut ( tr ( "Ctrl+W" ) );
130 deleteObjectWidgetAc->setShortcutContext ( Qt::WidgetShortcut );
131 addAction ( deleteObjectWidgetAc );
132
133 buildTableFromClassAc = new QAction ( tr ( "Build Tab&le From Class" ), this );
134 buildTableFromClassAc->setShortcut ( tr ( "Ctrl+L" ) );
135 buildTableFromClassAc->setShortcutContext ( Qt::WidgetShortcut );
136 addAction ( buildTableFromClassAc );
137
138 expandAllAc = new QAction ( tr ( "Expand &All" ), this );
139 expandAllAc->setShortcut ( tr ( "Ctrl+A" ) );
140 expandAllAc->setShortcutContext ( Qt::WidgetShortcut );
141 connect ( expandAllAc, SIGNAL ( triggered() ), this,
142 SLOT ( expandAll() ) ); // QTreeView slot
143 addAction ( expandAllAc );
144
145 collapseAllAc = new QAction ( tr ( "C&ollapse All" ), this );
146 collapseAllAc->setShortcut ( tr ( "Ctrl+Shift+C" ) );
147 collapseAllAc->setShortcutContext ( Qt::WidgetShortcut );
148 connect ( collapseAllAc, SIGNAL ( triggered() ), this,
149 SLOT ( collapseAll() ) ); // QTreeView slot
150 addAction ( collapseAllAc );
151
152 refByAc = new QAction ( tr ( "&Referenced By (All objects)" ), this );
153 refByAc->setShortcut ( tr ( "Ctrl+Y" ) );
154 refByAc->setShortcutContext ( Qt::WidgetShortcut );
155 refByAc->setToolTip ( "Find all objects which reference the selecetd object" );
156 refByAc->setStatusTip ( refByAc->toolTip() );
157 connect ( refByAc, SIGNAL ( triggered() ), this, SLOT ( referencedByAll() ) );
158 addAction ( refByAc );
159
160 refByAcOnlyComp = new QAction ( tr ( "Referenced B&y (Only Composite)" ), this );
161 refByAcOnlyComp->setShortcut ( tr ( "Ctrl+Shift+Y" ) );
162 refByAcOnlyComp->setShortcutContext ( Qt::WidgetShortcut );
163 refByAcOnlyComp->setToolTip (
164 "Find objects (ONLY Composite ones) which reference the selecetd object" );
165 refByAcOnlyComp->setStatusTip ( refByAcOnlyComp->toolTip() );
166 connect ( refByAcOnlyComp, SIGNAL ( triggered() ), this,
167 SLOT ( referencedbyOnlycomposite() ) );
168 addAction ( refByAcOnlyComp );
169}

◆ edit_object()

void dbe::CustomTreeView::edit_object ( QModelIndex const & index)
private

Definition at line 279 of file CustomTreeView.cpp.

280{
281 model_common_interface * filtermodel = dynamic_cast<model_common_interface *> ( model() );
282
283 if ( !index.isValid() )
284 {
285 return;
286 }
287
288 if ( filtermodel )
289 {
290 try
291 {
292 tref obj = filtermodel->getobject ( index );
293 bool WidgetFound = false;
294 QString ObjectEditorName = QString ( "%1@%2" ).arg ( obj.UID().c_str() ).arg (
295 obj.class_name().c_str() );
296
297 for ( QWidget * Editor : QApplication::allWidgets() )
298 {
299 ObjectEditor * Widget = dynamic_cast<ObjectEditor *> ( Editor );
300
301 if ( Widget != nullptr )
302 {
303 if ( ( Widget->objectName() ).compare ( ObjectEditorName ) == 0 )
304 {
305 Widget->raise();
306 Widget->setVisible ( true );
307 WidgetFound = true;
308 }
309 }
310 }
311
312 if ( !WidgetFound )
313 {
314 ( new ObjectEditor ( obj ) )->show();
315 }
316 }
317 catch ( daq::dbe::cannot_handle_invalid_qmodelindex const & e )
318 {
319 // nothing to do , maybe the user just clicked the wrong place
320 }
321 }
322}

◆ OpenEditor

void dbe::CustomTreeView::OpenEditor ( tref Object)
signal

◆ referencedBy [1/2]

void dbe::CustomTreeView::referencedBy ( bool All)
slot

Definition at line 370 of file CustomTreeView.cpp.

371{
372 model_common_interface * filtermodel = dynamic_cast<model_common_interface *> ( model() );
373 QModelIndex Index = currentIndex();
374
375 if ( !Index.isValid() )
376 {
377 return;
378 }
379
380 if ( filtermodel )
381 {
382
383 try
384 {
385 tref obj = filtermodel->getobject ( Index );
386 std::vector<tref> objects;
387
388 if ( not obj.is_null() )
389 {
390 objects = obj.referenced_by ( "*", All );
391 }
392
393 if ( objects.size() > 0 )
394 {
395 dbe::models::tree * Source = dynamic_cast<dbe::models::tree *> ( filtermodel
396 ->ReturnSourceModel() );
397 models::treeselection * Selection = new models::treeselection();
398 Selection->SetFilterType ( models::treeselection::ObjectFilterType );
399 Selection->SetQueryObjects ( objects );
400 Selection->setFilterRegExp ( "Dummy" );
401 Selection->setSourceModel ( Source );
402
403 CustomTreeView * tView = new CustomTreeView ( 0 );
404 tView->setModel ( Selection );
405 tView->setWindowTitle ( QString ( "Objects referencing '%1'" ).arg ( obj.UID().c_str() ) );
406 tView->setSortingEnabled ( true );
407 tView->setAlternatingRowColors ( true );
408 tView->resizeColumnToContents ( 0 );
409 tView->resizeColumnToContents ( 1 );
410 tView->setAttribute(Qt::WA_DeleteOnClose);
411
412 connect ( tView, SIGNAL ( doubleClicked ( QModelIndex ) ),
413 tView, SLOT ( slot_edit_object () ) );
414
415 tView->show();
416 }
417 else
418 {
419 if ( All )
420 {
421 WARN ( "No references of only composite objects have been found for object", " ",
422 "with UID:", obj.UID(), "of class", obj.class_name() );
423 }
424 else
425 {
426 WARN ( "No references of objects have been found for object", " ", "with UID:",
427 obj.UID(), "of class", obj.class_name() );
428 }
429 }
430 }
431 catch ( daq::dbe::cannot_handle_invalid_qmodelindex const & e )
432 {}
433 }
434}
CustomTreeView(QWidget *Parent=nullptr)
Including QT Headers.
#define WARN(...)
Definition messenger.hpp:85

◆ referencedBy [2/2]

void dbe::CustomTreeView::referencedBy ( bool All,
tref Object )
slot

Definition at line 438 of file CustomTreeView.cpp.

439{
440 model_common_interface * filtermodel = dynamic_cast<model_common_interface *> ( model() );
441
442 if ( filtermodel )
443 {
444 std::vector<tref> objects;
445
446 if ( !obj.is_null() )
447 {
448 objects = obj.referenced_by ( "*", All );
449 }
450
451 if ( objects.size() > 0 )
452 {
453 dbe::models::tree * Source = dynamic_cast<dbe::models::tree *> ( filtermodel
454 ->ReturnSourceModel() );
455 models::treeselection * Selection = new models::treeselection();
456 Selection->SetFilterType ( models::treeselection::ObjectFilterType );
457 Selection->SetQueryObjects ( objects );
458 Selection->setFilterRegExp ( "Dummy" );
459 Selection->setSourceModel ( Source );
460
461 CustomTreeView * tView = new CustomTreeView ( 0 );
462 tView->setModel ( Selection );
463 tView->setSortingEnabled ( true );
464 tView->setAlternatingRowColors ( true );
465 tView->resizeColumnToContents ( 0 );
466 tView->hideColumn ( 1 );
467 //tView->resizeColumnToContents(1);
468 tView->setWindowTitle ( QString ( "Objects referencing '%1'" ).arg ( obj.UID().c_str() ) );
469 tView->setAttribute(Qt::WA_DeleteOnClose);
470
471 connect ( tView, SIGNAL ( doubleClicked ( QModelIndex ) ), tView,
472 SLOT ( slot_edit_object () ) );
473
474 tView->show();
475 }
476 else
477 {
478 if ( All )
479 {
480 WARN ( "No references for object", "Only Composite Objects - Not found", "with UID:",
481 obj.UID() );
482 }
483 else
484 {
485 WARN ( "No references for object", "All Objects - Not found", "with UID:", obj.UID() );
486 }
487 }
488 }
489}

◆ referencedByAll

void dbe::CustomTreeView::referencedByAll ( )
privateslot

Definition at line 349 of file CustomTreeView.cpp.

350{
351 referencedBy ( false );
352}
void referencedBy(bool All)

◆ referencedbyOnlycomposite

void dbe::CustomTreeView::referencedbyOnlycomposite ( )
privateslot

Definition at line 344 of file CustomTreeView.cpp.

345{
346 referencedBy ( true );
347}

◆ slot_copy_object

void dbe::CustomTreeView::slot_copy_object ( )
privateslot

Definition at line 326 of file CustomTreeView.cpp.

327{
328 model_common_interface * filtermodel = dynamic_cast<model_common_interface *> ( model() );
329 QModelIndex i = currentIndex();
330
331 if ( i.isValid() and filtermodel )
332 {
333 try
334 {
335 ( new ObjectCreator ( filtermodel->getobject ( i ) ) )->show();
336 }
337 catch ( daq::dbe::cannot_handle_invalid_qmodelindex const & e )
338 {
339 //TODO the index can be invalid in this case
340 }
341 }
342}

◆ slot_create_object

void dbe::CustomTreeView::slot_create_object ( )
privateslot

Definition at line 173 of file CustomTreeView.cpp.

174{
175 // To create an object we only need to extract the information of the class that the
176 // user had clicked onto.
177 model_common_interface * common_model = dynamic_cast<model_common_interface *> ( model() );
178 QModelIndex const & treeindex = currentIndex();
179 treenode * cnode = nullptr;
180
181 if ( common_model && treeindex.isValid() )
182 {
183 dunedaq::conffwk::class_t classinfo = common_model->getclass ( treeindex );
184
185 if ( dynamic_cast<models::treeselection *> ( model() ) )
186 {
187 models::treeselection * selectionmodel = dynamic_cast<models::treeselection *> ( model() );
188
189 if ( selectionmodel )
190 {
191 QModelIndex const & srcindex = selectionmodel->mapToSource ( treeindex );
192
193 if ( dbe::models::tree * tree_model = dynamic_cast<dbe::models::tree *>
194 ( selectionmodel->sourceModel() )
195 )
196 {
197 cnode = tree_model->getnode ( srcindex );
198 }
199 }
200 }
201 else if ( dbe::models::subtree_proxy * subtree_model =
202 dynamic_cast<dbe::models::subtree_proxy *> ( model() ) )
203 {
204 cnode = subtree_model->getnode ( treeindex );
205 }
206
207 if ( dynamic_cast<RelationshipNode *> ( cnode ) )
208 {
209 treenode * parent = cnode->GetParent();
210 ObjectNode * NodeObject = dynamic_cast<ObjectNode *> ( parent );
211 RelationshipNode * RelationshipTreeNode = dynamic_cast<RelationshipNode *> ( cnode );
212
213 ( new ObjectCreator ( NodeObject->GetObject(),
214 RelationshipTreeNode->relation_t() ) )->show();
215 }
216 else
217 {
218 ( new ObjectCreator ( classinfo ) )->show();
219 }
220 }
221}

◆ slot_delete_objects

void dbe::CustomTreeView::slot_delete_objects ( )
privateslot

Definition at line 225 of file CustomTreeView.cpp.

226{
227 if ( this->model() != nullptr )
228 {
229 QModelIndexList qindices = this->selectedIndexes();
230 std::vector<QModelIndex> indices;
231
232 for ( QModelIndex const & q : qindices )
233 {
234 if ( q.isValid() and q.column() == 0 )
235 {
236 indices.push_back ( q );
237 }
238 }
239
240 if ( models::treeselection * casted_model = dynamic_cast<models::treeselection *> ( this
241 ->model() )
242 )
243 {
244 casted_model->delete_objects ( indices.begin(), indices.end() );
245 }
246 else if ( dbe::models::subtree_proxy * casted_model =
247 dynamic_cast<dbe::models::subtree_proxy *>
248 ( this->model() ) )
249 {
250 casted_model->delete_objects ( indices.begin(), indices.end() );
251 }
252 else
253 {
254 WARN ( "Object Deleting",
255 "Object deletion failed due to the internal model being in invalid state",
256 "You are advised to restart the application before proceeding any further" );
257 }
258
259 }
260}

◆ slot_edit_object

void dbe::CustomTreeView::slot_edit_object ( )
privateslot

Definition at line 264 of file CustomTreeView.cpp.

265{
266 if ( this->model() != nullptr )
267 {
268 QModelIndexList indices = this->selectedIndexes();
269
270 for ( QModelIndex const & q : indices )
271 {
272 edit_object ( q );
273 }
274 }
275}
void edit_object(QModelIndex const &)

Member Data Documentation

◆ buildTableFromClassAc

QAction* dbe::CustomTreeView::buildTableFromClassAc
private

Definition at line 59 of file CustomTreeView.hpp.

◆ collapseAllAc

QAction* dbe::CustomTreeView::collapseAllAc
private

Definition at line 61 of file CustomTreeView.hpp.

◆ contextMenu

QMenu* dbe::CustomTreeView::contextMenu
private

Definition at line 52 of file CustomTreeView.hpp.

◆ copyObjectAc

QAction* dbe::CustomTreeView::copyObjectAc
private

Definition at line 56 of file CustomTreeView.hpp.

◆ createObjectAc

QAction* dbe::CustomTreeView::createObjectAc
private

Definition at line 55 of file CustomTreeView.hpp.

◆ deleteObjectAc

QAction* dbe::CustomTreeView::deleteObjectAc
private

Definition at line 54 of file CustomTreeView.hpp.

◆ deleteObjectWidgetAc

QAction* dbe::CustomTreeView::deleteObjectWidgetAc
private

Definition at line 57 of file CustomTreeView.hpp.

◆ editObjectAc

QAction* dbe::CustomTreeView::editObjectAc
private

Definition at line 53 of file CustomTreeView.hpp.

◆ expandAllAc

QAction* dbe::CustomTreeView::expandAllAc
private

Definition at line 60 of file CustomTreeView.hpp.

◆ hideShowAc

QAction* dbe::CustomTreeView::hideShowAc
private

Definition at line 58 of file CustomTreeView.hpp.

◆ refByAc

QAction* dbe::CustomTreeView::refByAc
private

Definition at line 62 of file CustomTreeView.hpp.

◆ refByAcOnlyComp

QAction* dbe::CustomTreeView::refByAcOnlyComp
private

Definition at line 63 of file CustomTreeView.hpp.


The documentation for this class was generated from the following files: