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