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 * colapseAllAc
 
QAction * refByAc
 
QAction * refByAcOnlyComp
 

Detailed Description

Definition at line 18 of file CustomTreeView.hpp.

Constructor & Destructor Documentation

◆ CustomTreeView()

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

Including QT Headers.

Including DBE

Definition at line 20 of file CustomTreeView.cpp.

21 : QTreeView ( Parent ),
22 contextMenu ( nullptr )
23{
24 setDragEnabled ( true );
25 setSortingEnabled ( true );
26 setExpandsOnDoubleClick ( false );
28 setSelectionMode ( QAbstractItemView::ExtendedSelection );
29 setUniformRowHeights(true);
30}

Member Function Documentation

◆ closeEvent()

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

Definition at line 348 of file CustomTreeView.cpp.

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

◆ contextMenuEvent()

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

Definition at line 34 of file CustomTreeView.cpp.

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

◆ CreateActions()

void dbe::CustomTreeView::CreateActions ( )
private

Definition at line 95 of file CustomTreeView.cpp.

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

◆ edit_object()

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

Definition at line 273 of file CustomTreeView.cpp.

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

◆ OpenEditor

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

◆ referencedBy [1/2]

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

Definition at line 364 of file CustomTreeView.cpp.

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

◆ referencedBy [2/2]

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

Definition at line 434 of file CustomTreeView.cpp.

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

◆ referencedByAll

void dbe::CustomTreeView::referencedByAll ( )
privateslot

Definition at line 343 of file CustomTreeView.cpp.

344{
345 referencedBy ( false );
346}
void referencedBy(bool All)

◆ referencedbyOnlycomposite

void dbe::CustomTreeView::referencedbyOnlycomposite ( )
privateslot

Definition at line 338 of file CustomTreeView.cpp.

339{
340 referencedBy ( true );
341}

◆ slot_copy_object

void dbe::CustomTreeView::slot_copy_object ( )
privateslot

Definition at line 320 of file CustomTreeView.cpp.

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

◆ slot_create_object

void dbe::CustomTreeView::slot_create_object ( )
privateslot

Definition at line 167 of file CustomTreeView.cpp.

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

◆ slot_delete_objects

void dbe::CustomTreeView::slot_delete_objects ( )
privateslot

Definition at line 219 of file CustomTreeView.cpp.

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

◆ slot_edit_object

void dbe::CustomTreeView::slot_edit_object ( )
privateslot

Definition at line 258 of file CustomTreeView.cpp.

259{
260 if ( this->model() != nullptr )
261 {
262 QModelIndexList indices = this->selectedIndexes();
263
264 for ( QModelIndex const & q : indices )
265 {
266 edit_object ( q );
267 }
268 }
269}
void edit_object(QModelIndex const &)

Member Data Documentation

◆ buildTableFromClassAc

QAction* dbe::CustomTreeView::buildTableFromClassAc
private

Definition at line 54 of file CustomTreeView.hpp.

◆ colapseAllAc

QAction* dbe::CustomTreeView::colapseAllAc
private

Definition at line 56 of file CustomTreeView.hpp.

◆ contextMenu

QMenu* dbe::CustomTreeView::contextMenu
private

Definition at line 47 of file CustomTreeView.hpp.

◆ copyObjectAc

QAction* dbe::CustomTreeView::copyObjectAc
private

Definition at line 51 of file CustomTreeView.hpp.

◆ createObjectAc

QAction* dbe::CustomTreeView::createObjectAc
private

Definition at line 50 of file CustomTreeView.hpp.

◆ deleteObjectAc

QAction* dbe::CustomTreeView::deleteObjectAc
private

Definition at line 49 of file CustomTreeView.hpp.

◆ deleteObjectWidgetAc

QAction* dbe::CustomTreeView::deleteObjectWidgetAc
private

Definition at line 52 of file CustomTreeView.hpp.

◆ editObjectAc

QAction* dbe::CustomTreeView::editObjectAc
private

Definition at line 48 of file CustomTreeView.hpp.

◆ expandAllAc

QAction* dbe::CustomTreeView::expandAllAc
private

Definition at line 55 of file CustomTreeView.hpp.

◆ hideShowAc

QAction* dbe::CustomTreeView::hideShowAc
private

Definition at line 53 of file CustomTreeView.hpp.

◆ refByAc

QAction* dbe::CustomTreeView::refByAc
private

Definition at line 57 of file CustomTreeView.hpp.

◆ refByAcOnlyComp

QAction* dbe::CustomTreeView::refByAcOnlyComp
private

Definition at line 58 of file CustomTreeView.hpp.


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