DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
GraphView.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
6#include "dbe/GraphView.hpp"
7#include "dbe/MainWindow.hpp"
12#include "dbe/treenode.hpp"
13
14#include <QComboBox>
15#include <QContextMenuEvent>
16#include <QDialog>
17#include <QLabel>
18#include <QMenu>
19
20//------------------------------------------------------------------------------------------
22
24 : QWidget(parent)
25 , ContextMenu(nullptr)
26 , ClickedItem(nullptr)
27 , uuid(QUuid::createUuid())
28{
29 setupUi(this);
33 setWindowTitle("Graphical View");
35 QGraphicsScene* scene = new QGraphicsScene(this);
36 scene->setItemIndexMethod(QGraphicsScene::NoIndex);
37 scene->setSceneRect(0, 0, 10000, 10000);
38 GraphicalView->setScene(scene);
39 GraphicalView->setCacheMode(QGraphicsView::CacheBackground);
40 GraphicalView->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
41 GraphicalView->setRenderHint(QPainter::Antialiasing);
42 GraphicalView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
43 GraphicalView->setMinimumSize(400, 400);
44 GraphicalView->centerOn(scene->sceneRect().topLeft());
45 GraphicalView->setAcceptDrops(true);
46}
47//------------------------------------------------------------------------------------------
48
49//------------------------------------------------------------------------------------------
50void
52{
53 connect(LoadButton, SIGNAL(clicked()), this, SLOT(GetWindowConfiguration()), Qt::UniqueConnection);
54}
55//------------------------------------------------------------------------------------------
56
57//------------------------------------------------------------------------------------------
58void
60{
62 GraphicalView->scene()->clear();
63
65 double dy = 0;
66 setWindowTitle(WindowConfiguration.Title + " View");
67
69 for (QString& ClassName : WindowConfiguration.GraphicalClassesList) {
70 GraphicalClass GraphicalClassInfo = confaccessor::guiconfig()->graphical(ClassName.toStdString());
72 // QStringList ClassesToInitialize = GraphicalClassInfo.DerivedClasses;
73 // ClassesToInitialize.append(GraphicalClassInfo.DatabaseClassName);
74
75 // for(QString& InitializeClass : ClassesToInitialize)
76 // {
77 double dx = 0;
78 double ChildNodeHeight = 0;
79
80 // Node* ClassNode = ConfigWrapper::GetInstance().GetDataHandler()->GetClassNode(InitializeClass);
81 treenode* ClassNode = confaccessor::gethandler()->getnode(GraphicalClassInfo.DatabaseClassName);
82
83 if (ClassNode) {
86
87 for (treenode* Object : ClassNode->GetChildren()) {
88 bool Used = true;
89 GraphicalObject* ObjectNodeGraphical =
90 new GraphicalObject(Used, Object->GetData(0).toString(), GraphicalClassInfo);
91 GraphicalView->scene()->addItem(ObjectNodeGraphical);
92 ObjectNodeGraphical->setPos(GraphicalView->scene()->sceneRect().topLeft() + QPointF(dx, dy));
93 dx += ObjectNodeGraphical->boundingRect().width() + 30;
94
95 if ((dx + ObjectNodeGraphical->boundingRect().width()) > GraphicalView->scene()->sceneRect().width()) {
96 dx = 0;
97 dy += ChildNodeHeight + 30;
98 }
99
100 ChildNodeHeight = ObjectNodeGraphical->boundingRect().height();
101 }
102
103 dy += ChildNodeHeight + 30;
104 }
105
106 // }
107 }
108}
109//------------------------------------------------------------------------------------------
110
111//------------------------------------------------------------------------------------------
112void
113dbe::GraphView::contextMenuEvent(QContextMenuEvent* Event)
114{
115 if (ContextMenu == nullptr) {
116 ContextMenu = new QMenu(GraphicalView);
119 }
120
121 QGraphicsItem* Index = GraphicalView->itemAt(Event->pos());
122
123 if (Index) {
124 ClickedItem = dynamic_cast<GraphicalObject*>(Index);
125
126 if (ClickedItem) {
127 ContextMenu->exec(Event->globalPos());
128 }
129 }
130}
131//------------------------------------------------------------------------------------------
132
133//------------------------------------------------------------------------------------------
134void
136{
137 editObject = new QAction(tr("&Edit Object"), this);
138 editObject->setShortcut(tr("Ctrl+E"));
139 editObject->setShortcutContext(Qt::WidgetShortcut);
140 connect(editObject, SIGNAL(triggered()), this, SLOT(editThisObject()), Qt::UniqueConnection);
141 ContextMenu->addAction(editObject);
142
143 deleteObjectAc = new QAction(tr("&Delete Object"), this);
144 deleteObjectAc->setShortcut(tr("Ctrl+D"));
145 deleteObjectAc->setShortcutContext(Qt::WidgetShortcut);
146 connect(deleteObjectAc, SIGNAL(triggered()), this, SLOT(deleteThisObject()), Qt::UniqueConnection);
147 ContextMenu->addAction(deleteObjectAc);
148
149 refByAc = new QAction(tr("Referenced B&y (All objects)"), this);
150 refByAc->setShortcut(tr("Ctrl+Y"));
151 refByAc->setShortcutContext(Qt::WidgetShortcut);
152 refByAc->setToolTip("Find all objects which reference the selecetd object");
153 refByAc->setStatusTip(refByAc->toolTip());
154 connect(refByAc, SIGNAL(triggered()), this, SLOT(referencedBy_All()), Qt::UniqueConnection);
155 ContextMenu->addAction(refByAc);
156
157 refByAcOnlyComp = new QAction(tr("Referenced B&y (Only Composite)"), this);
158 refByAcOnlyComp->setShortcut(tr("Ctrl+Shift+Y"));
159 refByAcOnlyComp->setShortcutContext(Qt::WidgetShortcut);
160 refByAcOnlyComp->setToolTip("Find objects (ONLY Composite ones) which reference the selecetd object");
161 refByAcOnlyComp->setStatusTip(refByAcOnlyComp->toolTip());
162 connect(refByAcOnlyComp, SIGNAL(triggered()), this, SLOT(referencedBy_OnlyComposite()), Qt::UniqueConnection);
163 ContextMenu->addAction(refByAcOnlyComp);
164
165 copyObjectAc = new QAction(tr("Copy This Object Into A &New One"), this);
166 copyObjectAc->setShortcut(tr("Ctrl+Shift+N"));
167 copyObjectAc->setShortcutContext(Qt::WidgetShortcut);
168 connect(copyObjectAc, SIGNAL(triggered()), this, SLOT(copyObject()), Qt::UniqueConnection);
169 ContextMenu->addAction(copyObjectAc);
170}
171//------------------------------------------------------------------------------------------
172
173//------------------------------------------------------------------------------------------
174void
176{
178 { ClickedItem->GetDatabaseUidName().toStdString(), ClickedItem->GetDatabaseClassName().toStdString() });
179
180 bool WidgetFound = false;
181 QString ObjectEditorName = QString("%1@%2").arg(Object.UID().c_str()).arg(Object.class_name().c_str());
182
183 for (QWidget* Editor : QApplication::allWidgets()) {
184 ObjectEditor* Widget = dynamic_cast<ObjectEditor*>(Editor);
185
186 if (Widget != nullptr) {
187 if ((Widget->objectName()).compare(ObjectEditorName) == 0) {
188 Widget->raise();
189 Widget->setVisible(true);
190 WidgetFound = true;
191 }
192 }
193 }
194
195 if (!WidgetFound) {
196 (new ObjectEditor(Object))->show();
197 }
198}
199
200void
202{
203
204 try {
206 { ClickedItem->GetDatabaseUidName().toStdString(), ClickedItem->GetDatabaseClassName().toStdString() });
207
209 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
210 // Nothing needed to do here , if the lookup failed that is ok
211 }
212}
213//------------------------------------------------------------------------------------------
214
215//------------------------------------------------------------------------------------------
216void
218{
219
220 try {
222 { ClickedItem->GetDatabaseUidName().toStdString(), ClickedItem->GetDatabaseClassName().toStdString() });
223
224 (new ObjectCreator(obj))->show();
225 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
226 }
227}
228//------------------------------------------------------------------------------------------
229
230//------------------------------------------------------------------------------------------
231void
233{
234
235 try {
237 { ClickedItem->GetDatabaseUidName().toStdString(), ClickedItem->GetDatabaseClassName().toStdString() });
238
239 MainWindow::findthis()->get_view()->referencedBy(false, obj);
240 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
241 // Nothing needed to do here , it seems that the object has not been found ,
242 }
243}
244//------------------------------------------------------------------------------------------
245
246//------------------------------------------------------------------------------------------
247void
249{
250 try {
252 { ClickedItem->GetDatabaseUidName().toStdString(), ClickedItem->GetDatabaseClassName().toStdString() });
253
254 MainWindow::findthis()->get_view()->referencedBy(true, obj);
255 } catch (daq::dbe::config_object_retrieval_result_is_null const& ex) {
256 // Nothing needed to do here , it seems that the object has not been found ,
257 // which is weird in this case
258 }
259}
260//------------------------------------------------------------------------------------------
261
262//------------------------------------------------------------------------------------------
263void
265{
266 QString ChoosenWindow;
267
268 QDialog* ChooseDialog = new QDialog(this);
269 QComboBox* Combo = new QComboBox(ChooseDialog);
270 QPushButton* GoButton = new QPushButton("Choose");
271 QHBoxLayout* Layout = new QHBoxLayout(ChooseDialog);
272 QLabel* Label = new QLabel("Window Configuration : ", ChooseDialog);
273
274 connect(GoButton, SIGNAL(clicked()), ChooseDialog, SLOT(accept()), Qt::UniqueConnection);
275
276 std::vector<Window> Configurations = confaccessor::guiconfig()->windows();
277
278 for (Window const& WindowConfig : Configurations) {
279 Combo->addItem(WindowConfig.Title);
280 }
281
282 Layout->addWidget(Label);
283 Layout->addWidget(Combo);
284 Layout->addWidget(GoButton);
285
286 ChooseDialog->setLayout(Layout);
287 ChooseDialog->setWindowTitle("Choose window configuration");
288
289 if (ChooseDialog->exec()) {
290 ChoosenWindow = Combo->currentText();
291 }
292
293 for (Window& Setting : Configurations) {
294 if (ChoosenWindow == Setting.Title) {
295 WindowConfiguration = Setting;
296 SetupView();
297 break;
298 }
299 }
300}
301//------------------------------------------------------------------------------------------
302
303//------------------------------------------------------------------------------------------
304void
306{
307 Q_UNUSED(Object)
308 SetupView();
309}
310//------------------------------------------------------------------------------------------
311
312//------------------------------------------------------------------------------------------
313void
318//------------------------------------------------------------------------------------------
QAction * refByAc
Definition GraphView.hpp:55
void ConnectActions()
Definition GraphView.cpp:51
GraphView(QWidget *parent=nullptr)
Definition GraphView.cpp:23
void editThisObject()
void contextMenuEvent(QContextMenuEvent *Event)
void referencedBy_OnlyComposite()
QAction * refByAcOnlyComp
Definition GraphView.hpp:56
QUuid const uuid
Definition GraphView.hpp:59
void GetWindowConfiguration()
QMenu * ContextMenu
Definition GraphView.hpp:52
void deleteThisObject()
QAction * editObject
Definition GraphView.hpp:53
QAction * deleteObjectAc
Definition GraphView.hpp:54
Window WindowConfiguration
Definition GraphView.hpp:50
void referencedBy_All()
void CreateActions()
void RedrawObject()
GraphicalObject * ClickedItem
Definition GraphView.hpp:58
QAction * copyObjectAc
Definition GraphView.hpp:57
GraphicalObject(bool Used, QString ObjectName, GraphicalClass GraphInfo, QGraphicsObject *parent=0)
QRectF boundingRect() const
cptr< dbe::CustomTreeView > get_view() const
static MainWindow * findthis()
ObjectCreator(dunedaq::conffwk::class_t const &classinfo, QWidget *parent=0)
ObjectEditor(QWidget *parent=nullptr)
static cptr< datahandler > gethandler()
static cptr< ui::config::info > guiconfig()
static configobject::tref get(dbe::cokey const &desc)
QList< treenode * > GetChildren() const
Definition treenode.cpp:110
bool delobj(inner::configobject::tref obj, QUuid const &src)
inner::configobject::tref tref
Definition tref.hpp:36