DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
src
graphical
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
"
8
#include "
dbe/ObjectCreator.hpp
"
9
#include "
dbe/config_api_commands.hpp
"
10
#include "
dbe/config_api_info.hpp
"
11
#include "
dbe/config_ui_info.hpp
"
12
#include "
dbe/treenode.hpp
"
13
14
#include <QComboBox>
15
#include <QContextMenuEvent>
16
#include <QDialog>
17
#include <QLabel>
18
#include <QMenu>
19
20
//------------------------------------------------------------------------------------------
21
dbe::GraphView::~GraphView
() =
default
;
22
23
dbe::GraphView::GraphView
(QWidget* parent)
24
: QWidget(parent)
25
,
ContextMenu
(nullptr)
26
,
ClickedItem
(nullptr)
27
,
uuid
(QUuid::createUuid())
28
{
29
setupUi(
this
);
31
ConnectActions
();
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
//------------------------------------------------------------------------------------------
50
void
51
dbe::GraphView::ConnectActions
()
52
{
53
connect(LoadButton, SIGNAL(clicked()),
this
, SLOT(
GetWindowConfiguration
()), Qt::UniqueConnection);
54
}
55
//------------------------------------------------------------------------------------------
56
57
//------------------------------------------------------------------------------------------
58
void
59
dbe::GraphView::SetupView
()
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
) {
85
confaccessor::gethandler
()->FetchMore(
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
//------------------------------------------------------------------------------------------
112
void
113
dbe::GraphView::contextMenuEvent
(QContextMenuEvent* Event)
114
{
115
if
(
ContextMenu
==
nullptr
) {
116
ContextMenu
=
new
QMenu(GraphicalView);
118
CreateActions
();
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
//------------------------------------------------------------------------------------------
134
void
135
dbe::GraphView::CreateActions
()
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
//------------------------------------------------------------------------------------------
174
void
175
dbe::GraphView::editThisObject
()
176
{
177
tref
Object =
inner::dbcontroller::get
(
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
200
void
201
dbe::GraphView::deleteThisObject
()
202
{
203
204
try
{
205
tref
obj =
inner::dbcontroller::get
(
206
{
ClickedItem
->GetDatabaseUidName().toStdString(),
ClickedItem
->GetDatabaseClassName().toStdString() });
207
208
dbe::config::api::commands::delobj
(obj,
uuid
);
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
//------------------------------------------------------------------------------------------
216
void
217
dbe::GraphView::copyObject
()
218
{
219
220
try
{
221
tref
obj =
inner::dbcontroller::get
(
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
//------------------------------------------------------------------------------------------
231
void
232
dbe::GraphView::referencedBy_All
()
233
{
234
235
try
{
236
tref
obj =
inner::dbcontroller::get
(
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
//------------------------------------------------------------------------------------------
247
void
248
dbe::GraphView::referencedBy_OnlyComposite
()
249
{
250
try
{
251
tref
obj =
inner::dbcontroller::get
(
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
//------------------------------------------------------------------------------------------
263
void
264
dbe::GraphView::GetWindowConfiguration
()
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
//------------------------------------------------------------------------------------------
304
void
305
dbe::GraphView::RedrawObject
(
tref
Object)
306
{
307
Q_UNUSED(Object)
308
SetupView
();
309
}
310
//------------------------------------------------------------------------------------------
311
312
//------------------------------------------------------------------------------------------
313
void
314
dbe::GraphView::RedrawObject
()
315
{
316
SetupView
();
317
}
318
//------------------------------------------------------------------------------------------
GraphView.hpp
MainWindow.hpp
ObjectCreator.hpp
dbe::ClassNode
Definition
treenode.hpp:62
dbe::GraphView::refByAc
QAction * refByAc
Definition
GraphView.hpp:55
dbe::GraphView::ConnectActions
void ConnectActions()
Definition
GraphView.cpp:51
dbe::GraphView::copyObject
void copyObject()
Definition
GraphView.cpp:217
dbe::GraphView::~GraphView
~GraphView()
dbe::GraphView::GraphView
GraphView(QWidget *parent=nullptr)
Definition
GraphView.cpp:23
dbe::GraphView::editThisObject
void editThisObject()
Definition
GraphView.cpp:175
dbe::GraphView::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *Event)
Definition
GraphView.cpp:113
dbe::GraphView::referencedBy_OnlyComposite
void referencedBy_OnlyComposite()
Definition
GraphView.cpp:248
dbe::GraphView::refByAcOnlyComp
QAction * refByAcOnlyComp
Definition
GraphView.hpp:56
dbe::GraphView::uuid
QUuid const uuid
Definition
GraphView.hpp:59
dbe::GraphView::GetWindowConfiguration
void GetWindowConfiguration()
Definition
GraphView.cpp:264
dbe::GraphView::ContextMenu
QMenu * ContextMenu
Definition
GraphView.hpp:52
dbe::GraphView::deleteThisObject
void deleteThisObject()
Definition
GraphView.cpp:201
dbe::GraphView::editObject
QAction * editObject
Definition
GraphView.hpp:53
dbe::GraphView::deleteObjectAc
QAction * deleteObjectAc
Definition
GraphView.hpp:54
dbe::GraphView::SetupView
void SetupView()
Definition
GraphView.cpp:59
dbe::GraphView::WindowConfiguration
Window WindowConfiguration
Definition
GraphView.hpp:50
dbe::GraphView::referencedBy_All
void referencedBy_All()
Definition
GraphView.cpp:232
dbe::GraphView::CreateActions
void CreateActions()
Definition
GraphView.cpp:135
dbe::GraphView::RedrawObject
void RedrawObject()
Definition
GraphView.cpp:314
dbe::GraphView::ClickedItem
GraphicalObject * ClickedItem
Definition
GraphView.hpp:58
dbe::GraphView::copyObjectAc
QAction * copyObjectAc
Definition
GraphView.hpp:57
dbe::GraphicalObject
Definition
GraphicalClass.hpp:55
dbe::GraphicalObject::GraphicalObject
GraphicalObject(bool Used, QString ObjectName, GraphicalClass GraphInfo, QGraphicsObject *parent=0)
Definition
GraphicalClass.cpp:27
dbe::GraphicalObject::boundingRect
QRectF boundingRect() const
Definition
GraphicalClass.cpp:72
dbe::MainWindow::get_view
cptr< dbe::CustomTreeView > get_view() const
Definition
MainWindow.cpp:1653
dbe::MainWindow::findthis
static MainWindow * findthis()
Definition
MainWindow.cpp:1562
dbe::ObjectCreator::ObjectCreator
ObjectCreator(dunedaq::conffwk::class_t const &classinfo, QWidget *parent=0)
Definition
ObjectCreator.cpp:45
dbe::ObjectEditor
Definition
ObjectEditor.hpp:31
dbe::ObjectEditor::ObjectEditor
ObjectEditor(QWidget *parent=nullptr)
Definition
ObjectEditor.cpp:44
dbe::confaccessor::gethandler
static cptr< datahandler > gethandler()
Definition
confaccessor.cpp:150
dbe::confaccessor::guiconfig
static cptr< ui::config::info > guiconfig()
Definition
confaccessor.cpp:157
dbe::inner::configobject::ref_interface::class_name
std::string class_name() const
Definition
config_reference.hpp:180
dbe::inner::configobject::ref_interface::UID
std::string UID() const
Definition
config_reference.hpp:178
dbe::inner::dbcontroller::get
static configobject::tref get(dbe::cokey const &desc)
Definition
dbcontroller.cpp:357
dbe::treenode
Definition
treenode.hpp:19
dbe::treenode::GetChildren
QList< treenode * > GetChildren() const
Definition
treenode.cpp:110
config_api_commands.hpp
config_api_info.hpp
config_ui_info.hpp
dbe::config::api::commands::delobj
bool delobj(inner::configobject::tref obj, QUuid const &src)
Definition
config_api_commands.cpp:75
dbe::tref
inner::configobject::tref tref
Definition
tref.hpp:36
dbe::GraphicalClass
Definition
GraphicalClass.hpp:29
dbe::GraphicalClass::DatabaseClassName
QString DatabaseClassName
Definition
GraphicalClass.hpp:31
dbe::Window
Definition
GraphicalClass.hpp:48
treenode.hpp
Generated on
for DUNE-DAQ by
1.18.0