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 21 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 313 of file CustomTreeView.cpp.

314{
315 // Reset the model when the widget is closed
316 // If not done, reference to removed objects may create issues
317 models::treeselection* filtermodel = dynamic_cast<models::treeselection*>(model());
318
319 setModel(nullptr);
320
321 if (filtermodel != nullptr) {
322 filtermodel->ResetQueryObjects();
323 filtermodel->deleteLater();
324 }
325
326 event->accept();
327}

◆ contextMenuEvent()

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

Definition at line 41 of file CustomTreeView.cpp.

42{
43 if (contextMenu == nullptr) {
44 contextMenu = new QMenu(this);
45 contextMenu->addAction(editObjectAc);
46 contextMenu->addAction(deleteObjectAc);
47 contextMenu->addAction(createObjectAc);
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 = dynamic_cast<model_common_interface*>(this->model());
58 QModelIndex index = this->currentIndex();
59
60 if (index.isValid()) {
61 if (modelInterface) {
62
63 try {
64 tref obj = modelInterface->getobject(index);
65 (contextMenu->actions()).at(0)->setVisible(true);
66 (contextMenu->actions()).at(1)->setVisible(true);
67 (contextMenu->actions()).at(2)->setVisible(true);
68 (contextMenu->actions()).at(3)->setVisible(false);
69 (contextMenu->actions()).at(4)->setVisible(true);
70 (contextMenu->actions()).at(5)->setVisible(false);
71 (contextMenu->actions()).at(6)->setVisible(false);
72 (contextMenu->actions()).at(7)->setVisible(false);
73 (contextMenu->actions()).at(8)->setVisible(true);
74 (contextMenu->actions()).at(9)->setVisible(true);
75 } catch (daq::dbe::cannot_handle_invalid_qmodelindex const& e) {
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:36

◆ CreateActions()

void dbe::CustomTreeView::CreateActions ( )
private

Definition at line 96 of file CustomTreeView.cpp.

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

◆ edit_object()

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

Definition at line 248 of file CustomTreeView.cpp.

249{
250 model_common_interface* filtermodel = dynamic_cast<model_common_interface*>(model());
251
252 if (!index.isValid()) {
253 return;
254 }
255
256 if (filtermodel) {
257 try {
258 tref obj = filtermodel->getobject(index);
259 bool WidgetFound = false;
260 QString ObjectEditorName = QString("%1@%2").arg(obj.UID().c_str()).arg(obj.class_name().c_str());
261
262 for (QWidget* Editor : QApplication::allWidgets()) {
263 ObjectEditor* Widget = dynamic_cast<ObjectEditor*>(Editor);
264
265 if (Widget != nullptr) {
266 if ((Widget->objectName()).compare(ObjectEditorName) == 0) {
267 Widget->raise();
268 Widget->setVisible(true);
269 WidgetFound = true;
270 }
271 }
272 }
273
274 if (!WidgetFound) {
275 (new ObjectEditor(obj))->show();
276 }
277 } catch (daq::dbe::cannot_handle_invalid_qmodelindex const& e) {
278 // nothing to do , maybe the user just clicked the wrong place
279 }
280 }
281}
ObjectEditor(QWidget *parent=nullptr)

◆ OpenEditor

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

◆ referencedBy [1/2]

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

Definition at line 331 of file CustomTreeView.cpp.

332{
333 model_common_interface* filtermodel = dynamic_cast<model_common_interface*>(model());
334 QModelIndex Index = currentIndex();
335
336 if (!Index.isValid()) {
337 return;
338 }
339
340 if (filtermodel) {
341
342 try {
343 tref obj = filtermodel->getobject(Index);
344 std::vector<tref> objects;
345
346 if (not obj.is_null()) {
347 objects = obj.referenced_by("*", All);
348 }
349
350 if (objects.size() > 0) {
351 dbe::models::tree* Source = dynamic_cast<dbe::models::tree*>(filtermodel->ReturnSourceModel());
352 models::treeselection* Selection = new models::treeselection();
353 Selection->SetFilterType(models::treeselection::ObjectFilterType);
354 Selection->SetQueryObjects(objects);
355 Selection->setFilterRegExp("Dummy");
356 Selection->setSourceModel(Source);
357
358 CustomTreeView* tView = new CustomTreeView(0);
359 tView->setModel(Selection);
360 tView->setWindowTitle(QString("Objects referencing '%1'").arg(obj.UID().c_str()));
361 tView->setSortingEnabled(true);
362 tView->setAlternatingRowColors(true);
363 tView->resizeColumnToContents(0);
364 tView->resizeColumnToContents(1);
365 tView->setAttribute(Qt::WA_DeleteOnClose);
366
367 connect(tView, SIGNAL(doubleClicked(QModelIndex)), tView, SLOT(slot_edit_object()));
368
369 tView->show();
370 } else {
371 if (All) {
372 WARN("No references of only composite objects have been found for object",
373 " ",
374 "with UID:",
375 obj.UID(),
376 "of class",
377 obj.class_name());
378 } else {
379 WARN("No references of objects have been found for object",
380 " ",
381 "with UID:",
382 obj.UID(),
383 "of class",
384 obj.class_name());
385 }
386 }
387 } catch (daq::dbe::cannot_handle_invalid_qmodelindex const& e) {
388 }
389 }
390}
CustomTreeView(QWidget *Parent=nullptr)
Including QT Headers.
#define WARN(...)
Definition messenger.hpp:82

◆ referencedBy [2/2]

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

Definition at line 395 of file CustomTreeView.cpp.

396{
397 model_common_interface* filtermodel = dynamic_cast<model_common_interface*>(model());
398
399 if (filtermodel) {
400 std::vector<tref> objects;
401
402 if (!obj.is_null()) {
403 objects = obj.referenced_by("*", All);
404 }
405
406 if (objects.size() > 0) {
407 dbe::models::tree* Source = dynamic_cast<dbe::models::tree*>(filtermodel->ReturnSourceModel());
408 models::treeselection* Selection = new models::treeselection();
409 Selection->SetFilterType(models::treeselection::ObjectFilterType);
410 Selection->SetQueryObjects(objects);
411 Selection->setFilterRegExp("Dummy");
412 Selection->setSourceModel(Source);
413
414 CustomTreeView* tView = new CustomTreeView(0);
415 tView->setModel(Selection);
416 tView->setSortingEnabled(true);
417 tView->setAlternatingRowColors(true);
418 tView->resizeColumnToContents(0);
419 tView->hideColumn(1);
420 // tView->resizeColumnToContents(1);
421 tView->setWindowTitle(QString("Objects referencing '%1'").arg(obj.UID().c_str()));
422 tView->setAttribute(Qt::WA_DeleteOnClose);
423
424 connect(tView, SIGNAL(doubleClicked(QModelIndex)), tView, SLOT(slot_edit_object()));
425
426 tView->show();
427 } else {
428 if (All) {
429 WARN("No references for object", "Only Composite Objects - Not found", "with UID:", obj.UID());
430 } else {
431 WARN("No references for object", "All Objects - Not found", "with UID:", obj.UID());
432 }
433 }
434 }
435}

◆ referencedByAll

void dbe::CustomTreeView::referencedByAll ( )
privateslot

Definition at line 307 of file CustomTreeView.cpp.

308{
309 referencedBy(false);
310}
void referencedBy(bool All)

◆ referencedbyOnlycomposite

void dbe::CustomTreeView::referencedbyOnlycomposite ( )
privateslot

Definition at line 301 of file CustomTreeView.cpp.

302{
303 referencedBy(true);
304}

◆ slot_copy_object

void dbe::CustomTreeView::slot_copy_object ( )
privateslot

Definition at line 286 of file CustomTreeView.cpp.

287{
288 model_common_interface* filtermodel = dynamic_cast<model_common_interface*>(model());
289 QModelIndex i = currentIndex();
290
291 if (i.isValid() and filtermodel) {
292 try {
293 (new ObjectCreator(filtermodel->getobject(i)))->show();
294 } catch (daq::dbe::cannot_handle_invalid_qmodelindex const& e) {
295 // TODO the index can be invalid in this case
296 }
297 }
298}
ObjectCreator(dunedaq::conffwk::class_t const &classinfo, QWidget *parent=0)

◆ 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 dunedaq::conffwk::class_t classinfo = common_model->getclass(treeindex);
177
178 if (dynamic_cast<models::treeselection*>(model())) {
179 models::treeselection* selectionmodel = dynamic_cast<models::treeselection*>(model());
180
181 if (selectionmodel) {
182 QModelIndex const& srcindex = selectionmodel->mapToSource(treeindex);
183
184 if (dbe::models::tree* tree_model = dynamic_cast<dbe::models::tree*>(selectionmodel->sourceModel())) {
185 cnode = tree_model->getnode(srcindex);
186 }
187 }
188 } else if (dbe::models::subtree_proxy* subtree_model = dynamic_cast<dbe::models::subtree_proxy*>(model())) {
189 cnode = subtree_model->getnode(treeindex);
190 }
191
192 if (dynamic_cast<RelationshipNode*>(cnode)) {
193 treenode* parent = cnode->GetParent();
194 ObjectNode* NodeObject = dynamic_cast<ObjectNode*>(parent);
195 RelationshipNode* RelationshipTreeNode = dynamic_cast<RelationshipNode*>(cnode);
196
197 (new ObjectCreator(NodeObject->GetObject(), RelationshipTreeNode->relation_t()))->show();
198 } else {
199 (new ObjectCreator(classinfo))->show();
200 }
201 }
202}

◆ slot_delete_objects

void dbe::CustomTreeView::slot_delete_objects ( )
privateslot

Definition at line 207 of file CustomTreeView.cpp.

208{
209 if (this->model() != nullptr) {
210 QModelIndexList qindices = this->selectedIndexes();
211 std::vector<QModelIndex> indices;
212
213 for (QModelIndex const& q : qindices) {
214 if (q.isValid() and q.column() == 0) {
215 indices.push_back(q);
216 }
217 }
218
219 if (models::treeselection* casted_model = dynamic_cast<models::treeselection*>(this->model())) {
220 casted_model->delete_objects(indices.begin(), indices.end());
221 } else if (dbe::models::subtree_proxy* casted_model = dynamic_cast<dbe::models::subtree_proxy*>(this->model())) {
222 casted_model->delete_objects(indices.begin(), indices.end());
223 } else {
224 WARN("Object Deleting",
225 "Object deletion failed due to the internal model being in invalid state",
226 "You are advised to restart the application before proceeding any further");
227 }
228 }
229}

◆ slot_edit_object

void dbe::CustomTreeView::slot_edit_object ( )
privateslot

Definition at line 234 of file CustomTreeView.cpp.

235{
236 if (this->model() != nullptr) {
237 QModelIndexList indices = this->selectedIndexes();
238
239 for (QModelIndex const& q : indices) {
240 edit_object(q);
241 }
242 }
243}
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: