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
8#include "dbe/GraphView.hpp"
9#include "dbe/MainWindow.hpp"
12#include "dbe/treenode.hpp"
13
14#include <QLabel>
15#include <QDialog>
16#include <QComboBox>
17#include <QMenu>
18#include <QContextMenuEvent>
19
20
21//------------------------------------------------------------------------------------------
23
24dbe::GraphView::GraphView ( QWidget * parent )
25 : QWidget ( parent ),
26 ContextMenu ( nullptr ),
27 ClickedItem ( nullptr ),
28 uuid ( QUuid::createUuid() )
29{
30 setupUi ( this );
34 setWindowTitle ( "Graphical View" );
36 QGraphicsScene * scene = new QGraphicsScene ( this );
37 scene->setItemIndexMethod ( QGraphicsScene::NoIndex );
38 scene->setSceneRect ( 0, 0, 10000, 10000 );
39 GraphicalView->setScene ( scene );
40 GraphicalView->setCacheMode ( QGraphicsView::CacheBackground );
41 GraphicalView->setViewportUpdateMode ( QGraphicsView::BoundingRectViewportUpdate );
42 GraphicalView->setRenderHint ( QPainter::Antialiasing );
43 GraphicalView->setTransformationAnchor ( QGraphicsView::AnchorUnderMouse );
44 GraphicalView->setMinimumSize ( 400, 400 );
45 GraphicalView->centerOn ( scene->sceneRect().topLeft() );
46 GraphicalView->setAcceptDrops ( true );
47}
48//------------------------------------------------------------------------------------------
49
50//------------------------------------------------------------------------------------------
52{
53 connect ( LoadButton, SIGNAL ( clicked() ), this, SLOT ( GetWindowConfiguration() ),
54 Qt::UniqueConnection );
55}
56//------------------------------------------------------------------------------------------
57
58//------------------------------------------------------------------------------------------
60{
62 GraphicalView->scene()->clear();
63
65 double dy = 0;
66 setWindowTitle ( WindowConfiguration.Title + " View" );
67
69 for ( QString & ClassName : WindowConfiguration.GraphicalClassesList )
70 {
71 GraphicalClass GraphicalClassInfo = confaccessor::guiconfig()->graphical (
72 ClassName.toStdString() );
74 // QStringList ClassesToInitialize = GraphicalClassInfo.DerivedClasses;
75 // ClassesToInitialize.append(GraphicalClassInfo.DatabaseClassName);
76
77 // for(QString& InitializeClass : ClassesToInitialize)
78 // {
79 double dx = 0;
80 double ChildNodeHeight = 0;
81
82 // Node* ClassNode = ConfigWrapper::GetInstance().GetDataHandler()->GetClassNode(InitializeClass);
84 GraphicalClassInfo.DatabaseClassName );
85
86 if ( ClassNode )
87 {
89 confaccessor::gethandler()->FetchMore ( ClassNode );
90
91 for ( treenode * Object : ClassNode->GetChildren() )
92 {
93 bool Used = true;
94 GraphicalObject * ObjectNodeGraphical = new GraphicalObject (
95 Used, Object->GetData ( 0 ).toString(), GraphicalClassInfo );
96 GraphicalView->scene()->addItem ( ObjectNodeGraphical );
97 ObjectNodeGraphical->setPos (
98 GraphicalView->scene()->sceneRect().topLeft() + QPointF ( dx, dy ) );
99 dx += ObjectNodeGraphical->boundingRect().width() + 30;
100
101 if ( ( dx + ObjectNodeGraphical->boundingRect().width() ) > GraphicalView->scene()
102 ->sceneRect().width() )
103 {
104 dx = 0;
105 dy += ChildNodeHeight + 30;
106 }
107
108 ChildNodeHeight = ObjectNodeGraphical->boundingRect().height();
109 }
110
111 dy += ChildNodeHeight + 30;
112 }
113
114 // }
115 }
116}
117//------------------------------------------------------------------------------------------
118
119//------------------------------------------------------------------------------------------
120void dbe::GraphView::contextMenuEvent ( QContextMenuEvent * Event )
121{
122 if ( ContextMenu == nullptr )
123 {
124 ContextMenu = new QMenu ( GraphicalView );
127 }
128
129 QGraphicsItem * Index = GraphicalView->itemAt ( Event->pos() );
130
131 if ( Index )
132 {
133 ClickedItem = dynamic_cast<GraphicalObject *> ( Index );
134
135 if ( ClickedItem )
136 {
137 ContextMenu->exec ( Event->globalPos() );
138 }
139 }
140}
141//------------------------------------------------------------------------------------------
142
143//------------------------------------------------------------------------------------------
145{
146 editObject = new QAction ( tr ( "&Edit Object" ), this );
147 editObject->setShortcut ( tr ( "Ctrl+E" ) );
148 editObject->setShortcutContext ( Qt::WidgetShortcut );
149 connect ( editObject, SIGNAL ( triggered() ), this, SLOT ( editThisObject() ),
150 Qt::UniqueConnection );
151 ContextMenu->addAction ( editObject );
152
153 deleteObjectAc = new QAction ( tr ( "&Delete Object" ), this );
154 deleteObjectAc->setShortcut ( tr ( "Ctrl+D" ) );
155 deleteObjectAc->setShortcutContext ( Qt::WidgetShortcut );
156 connect ( deleteObjectAc, SIGNAL ( triggered() ), this, SLOT ( deleteThisObject() ),
157 Qt::UniqueConnection );
158 ContextMenu->addAction ( deleteObjectAc );
159
160 refByAc = new QAction ( tr ( "Referenced B&y (All objects)" ), this );
161 refByAc->setShortcut ( tr ( "Ctrl+Y" ) );
162 refByAc->setShortcutContext ( Qt::WidgetShortcut );
163 refByAc->setToolTip ( "Find all objects which reference the selecetd object" );
164 refByAc->setStatusTip ( refByAc->toolTip() );
165 connect ( refByAc, SIGNAL ( triggered() ), this, SLOT ( referencedBy_All() ),
166 Qt::UniqueConnection );
167 ContextMenu->addAction ( refByAc );
168
169 refByAcOnlyComp = new QAction ( tr ( "Referenced B&y (Only Composite)" ), this );
170 refByAcOnlyComp->setShortcut ( tr ( "Ctrl+Shift+Y" ) );
171 refByAcOnlyComp->setShortcutContext ( Qt::WidgetShortcut );
172 refByAcOnlyComp->setToolTip (
173 "Find objects (ONLY Composite ones) which reference the selecetd object" );
174 refByAcOnlyComp->setStatusTip ( refByAcOnlyComp->toolTip() );
175 connect ( refByAcOnlyComp, SIGNAL ( triggered() ), this,
177 Qt::UniqueConnection );
178 ContextMenu->addAction ( refByAcOnlyComp );
179
180 copyObjectAc = new QAction ( tr ( "Copy This Object Into A &New One" ), this );
181 copyObjectAc->setShortcut ( tr ( "Ctrl+Shift+N" ) );
182 copyObjectAc->setShortcutContext ( Qt::WidgetShortcut );
183 connect ( copyObjectAc, SIGNAL ( triggered() ), this, SLOT ( copyObject() ),
184 Qt::UniqueConnection );
185 ContextMenu->addAction ( copyObjectAc );
186}
187//------------------------------------------------------------------------------------------
188
189//------------------------------------------------------------------------------------------
191{
193 {
194 ClickedItem->GetDatabaseUidName().toStdString(), ClickedItem->GetDatabaseClassName()
195 .toStdString()
196 } );
197
198 bool WidgetFound = false;
199 QString ObjectEditorName = QString ( "%1@%2" ).arg ( Object.UID().c_str() ).arg (
200 Object.class_name().c_str() );
201
202 for ( QWidget * Editor : QApplication::allWidgets() )
203 {
204 ObjectEditor * Widget = dynamic_cast<ObjectEditor *> ( Editor );
205
206 if ( Widget != nullptr )
207 {
208 if ( ( Widget->objectName() ).compare ( ObjectEditorName ) == 0 )
209 {
210 Widget->raise();
211 Widget->setVisible ( true );
212 WidgetFound = true;
213 }
214 }
215 }
216
217 if ( !WidgetFound )
218 {
219 ( new ObjectEditor ( Object ) )->show();
220 }
221}
222
224{
225
226 try
227 {
229 {
230 ClickedItem->GetDatabaseUidName().toStdString(),
231 ClickedItem->GetDatabaseClassName().toStdString()
232 } );
233
235 }
236 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
237 {
238 // Nothing needed to do here , if the lookup failed that is ok
239 }
240
241}
242//------------------------------------------------------------------------------------------
243
244//------------------------------------------------------------------------------------------
246{
247
248 try
249 {
251 {
252 ClickedItem->GetDatabaseUidName().toStdString(),
253 ClickedItem->GetDatabaseClassName().toStdString()
254 } );
255
256 ( new ObjectCreator ( obj ) )->show();
257 }
258 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
259 {
260
261 }
262
263}
264//------------------------------------------------------------------------------------------
265
266//------------------------------------------------------------------------------------------
268{
269
270 try
271 {
273 {
274 ClickedItem->GetDatabaseUidName().toStdString(),
275 ClickedItem->GetDatabaseClassName().toStdString()
276 } );
277
278 MainWindow::findthis()->get_view()->referencedBy ( false, obj );
279 }
280 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
281 {
282 // Nothing needed to do here , it seems that the object has not been found ,
283 }
284
285}
286//------------------------------------------------------------------------------------------
287
288//------------------------------------------------------------------------------------------
290{
291 try
292 {
294 {
295 ClickedItem->GetDatabaseUidName().toStdString(),
296 ClickedItem->GetDatabaseClassName().toStdString()
297 } );
298
299 MainWindow::findthis()->get_view()->referencedBy ( true, obj );
300 }
301 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
302 {
303 // Nothing needed to do here , it seems that the object has not been found ,
304 // which is weird in this case
305 }
306}
307//------------------------------------------------------------------------------------------
308
309//------------------------------------------------------------------------------------------
311{
312 QString ChoosenWindow;
313
314 QDialog * ChooseDialog = new QDialog ( this );
315 QComboBox * Combo = new QComboBox ( ChooseDialog );
316 QPushButton * GoButton = new QPushButton ( "Choose" );
317 QHBoxLayout * Layout = new QHBoxLayout ( ChooseDialog );
318 QLabel * Label = new QLabel ( "Window Configuration : ", ChooseDialog );
319
320 connect ( GoButton, SIGNAL ( clicked() ), ChooseDialog, SLOT ( accept() ),
321 Qt::UniqueConnection );
322
323 std::vector<Window> Configurations = confaccessor::guiconfig()->windows();
324
325 for ( Window const & WindowConfig : Configurations )
326 {
327 Combo->addItem ( WindowConfig.Title );
328 }
329
330 Layout->addWidget ( Label );
331 Layout->addWidget ( Combo );
332 Layout->addWidget ( GoButton );
333
334 ChooseDialog->setLayout ( Layout );
335 ChooseDialog->setWindowTitle ( "Choose window configuration" );
336
337 if ( ChooseDialog->exec() )
338 {
339 ChoosenWindow = Combo->currentText();
340 }
341
342 for ( Window & Setting : Configurations )
343 {
344 if ( ChoosenWindow == Setting.Title )
345 {
346 WindowConfiguration = Setting;
347 SetupView();
348 break;
349 }
350 }
351}
352//------------------------------------------------------------------------------------------
353
354//------------------------------------------------------------------------------------------
356{
357 Q_UNUSED ( Object )
358 SetupView();
359}
360//------------------------------------------------------------------------------------------
361
362//------------------------------------------------------------------------------------------
367//------------------------------------------------------------------------------------------
QAction * refByAc
Definition GraphView.hpp:55
void ConnectActions()
Definition GraphView.cpp:51
GraphView(QWidget *parent=nullptr)
Definition GraphView.cpp:24
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
QRectF boundingRect() const
cptr< dbe::CustomTreeView > get_view() const
static MainWindow * findthis()
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:111
bool delobj(inner::configobject::tref obj, QUuid const &src)
inner::configobject::tref tref
Definition tref.hpp:35