DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
GraphicalClass.cpp
Go to the documentation of this file.
5#include "dbe/treenode.hpp"
6
7#include <QGraphicsSceneMouseEvent>
8#include <QPainter>
9#include <QBitmap>
10#include <QGraphicsScene>
11#include <QGraphicsObject>
12#include <QMimeData>
13#include <QComboBox>
14#include <QHBoxLayout>
15#include <QPushButton>
16#include <QMessageBox>
17#include <QApplication>
18#include <QLabel>
19#include <QDrag>
20
21//------------------------------------------------------------------------------------------
22dbe::GraphicalObject::GraphicalObject ( bool Used, QString ObjectName,
23 GraphicalClass GraphInfo, QGraphicsObject * parent )
24 : QGraphicsObject ( parent ),
25 GraphicalInfo ( GraphInfo ),
26 IconItem ( nullptr ),
27 TextItem ( nullptr ),
28 DatabaseClassName ( GraphInfo.DatabaseClassName ),
29 DatabaseUidName ( ObjectName ),
30 IsExpanded ( false ),
31 IsFetched ( false ),
32 expandedX ( 0 ),
33 expandedY ( 0 )
34{
35 setAcceptDrops ( true );
36 setFlag ( ItemIsMovable );
37
38 QPixmap Icon;
39
40 if ( Used )
41 {
42 if ( !GraphInfo.UsedPixmapFile.isEmpty() ) Icon = QPixmap (
43 ":/Images/" + GraphInfo.UsedPixmapFile );
44 else
45 {
46 Icon = QPixmap ( ":/Images/" + GraphInfo.GenericPixmapFile );
47 }
48 }
49 else
50 {
51 Icon = QPixmap ( ":/Images/" + GraphInfo.GenericPixmapFile );
52 }
53
54 QBitmap IconMask = Icon.createHeuristicMask();
55 Icon.setMask ( IconMask );
56
57 IconItem = new QGraphicsPixmapItem ( Icon );
58 TextItem = new QGraphicsTextItem ( ObjectName );
59}
60//------------------------------------------------------------------------------------------
61
62//------------------------------------------------------------------------------------------
64{
65 delete IconItem;
66 delete TextItem;
67}
68//------------------------------------------------------------------------------------------
69
70//------------------------------------------------------------------------------------------
72{
73 QRectF Boundarie;
74 Boundarie.setHeight (
75 IconItem->boundingRect().height() + TextItem->boundingRect().height() );
76
77 if ( IconItem->boundingRect().width() > TextItem->boundingRect().width() ) Boundarie
78 .setWidth ( IconItem->boundingRect().width() );
79 else
80 {
81 Boundarie.setWidth ( TextItem->boundingRect().width() );
82 }
83
84 return Boundarie;
85}
86//------------------------------------------------------------------------------------------
87
88//------------------------------------------------------------------------------------------
89void dbe::GraphicalObject::paint ( QPainter * painter,
90 const QStyleOptionGraphicsItem * option,
91 QWidget * widget )
92{
93 Q_UNUSED ( option )
94 Q_UNUSED ( widget )
95
96 QFontMetrics Metric ( QFont ( "Helvetica", 10 ) );
97 painter->setFont ( QFont ( "Helvetica", 10 ) );
98 painter->drawPixmap ( IconItem->boundingRect(), IconItem->pixmap(),
99 IconItem->boundingRect() );
100 painter->drawText (
101 IconItem->boundingRect().bottomLeft() + QPointF (
102 0, Metric.boundingRect ( DatabaseUidName ).height() ),
103 DatabaseUidName );
104}
105//------------------------------------------------------------------------------------------
106
107//------------------------------------------------------------------------------------------
108QPainterPath dbe::GraphicalObject::shape() const
109{
110 QPainterPath Path;
111 Path.addRect ( IconItem->boundingRect() );
112 return Path;
113}
114//------------------------------------------------------------------------------------------
115
116//------------------------------------------------------------------------------------------
117void dbe::GraphicalObject::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event )
118{
119 if ( !IsFetched )
120 {
121 AddGraphicChildren();
122 }
123
124 if ( !IsExpanded )
125 {
126 ShowGraphicsChildren();
127 }
128 else
129 {
130 HideGraphicsChildren();
131 }
132
133 update();
134 QGraphicsItem::mouseDoubleClickEvent ( event );
135}
136//------------------------------------------------------------------------------------------
137
138//------------------------------------------------------------------------------------------
139void dbe::GraphicalObject::mousePressEvent ( QGraphicsSceneMouseEvent * event )
140{
141 if ( event->button() == Qt::LeftButton )
142 {
143 StartDrag = event->pos();
144 }
145}
146//------------------------------------------------------------------------------------------
147
148//------------------------------------------------------------------------------------------
149void dbe::GraphicalObject::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
150{
151 if ( ! ( event->buttons() & Qt::LeftButton ) )
152 {
153 return;
154 }
155
156 if ( ( event->pos() - StartDrag ).manhattanLength() < QApplication::startDragDistance() )
157 {
158 return;
159 }
160
161 QDrag * drag = new QDrag ( event->widget() );
162 QPixmap Icon = IconItem->pixmap();
163
164 QStringList DataList;
165 QMimeData * mimeData = new QMimeData;
166 QByteArray ItemData;
167 QDataStream DataStream ( &ItemData, QIODevice::WriteOnly );
168
169 DataList.append ( QString ( DatabaseUidName ) );
170 DataList.append ( QString ( DatabaseClassName ) );
171 DataStream << DataList;
172 mimeData->setData ( "application/vnd.text.list", ItemData );
173
174 drag->setMimeData ( mimeData );
175 drag->setPixmap ( Icon );
176
177 Qt::DropAction dropAction = drag->exec();
178 Q_UNUSED ( dropAction )
179}
180//------------------------------------------------------------------------------------------
181
182//------------------------------------------------------------------------------------------
183void dbe::GraphicalObject::dropEvent ( QGraphicsSceneDragDropEvent * event )
184{
185 QByteArray encodedData = event->mimeData()->data ( "application/vnd.text.list" );
186 QDataStream stream ( &encodedData, QIODevice::ReadOnly );
187 QList<QStringList> NewItems;
188
189 while ( !stream.atEnd() )
190 {
191 QStringList Text;
192 stream >> Text;
193 NewItems << Text;
194 }
195
196 QStringList ObjectList;
197
198 for ( QStringList & i : NewItems )
199 {
200 ObjectList.append ( i.at ( 0 ) );
201 }
202
203 for ( int i = 0; i < NewItems.size(); ++i )
204 {
205 if ( NewItems.at ( 0 ).at ( 1 ) != NewItems.at ( i ).at ( 1 ) )
206 {
207 return;
208 }
209 }
210
211 QStringList PossibleRelationships;
212 QString ClassName = NewItems.at ( 0 ).at ( 1 );
213
214 dunedaq::conffwk::class_t ClassInfoReceiverObject =
215 dbe::config::api::info::onclass::definition ( DatabaseClassName.toStdString(), false );
216 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfoReceiverObject
218
219 for ( dunedaq::conffwk::relationship_t & i : RelationshipList )
220 {
221 if ( i.p_type == ClassName.toStdString() ) PossibleRelationships.append (
222 QString::fromStdString ( i.p_name ) );
223
224 dunedaq::conffwk::class_t ClassInfoDroppedObject =
226 false );
227 std::vector<std::string> RelationshipListDropped = ClassInfoDroppedObject.p_subclasses;
228
229 for ( std::string & j : RelationshipListDropped )
230 {
231 if ( j == ClassName.toStdString() ) PossibleRelationships.append (
232 QString::fromStdString ( i.p_name ) );
233 }
234 }
235
236 QString SelectedRelationship;
237
238 if ( PossibleRelationships.size() == 0 )
239 {
240 return;
241 }
242 else if ( PossibleRelationships.size() == 1 ) SelectedRelationship = PossibleRelationships
243 .at ( 0 );
244 else
245 {
246 QDialog * NewDialog = new QDialog();
247 QHBoxLayout * NewLayout = new QHBoxLayout();
248 QPushButton * OkButton = new QPushButton ( "Ok" );
249 QComboBox * NewCombo = new QComboBox();
250 QLabel * NewLabel = new QLabel ( "Choose relationship : " );
251 NewCombo->addItems ( PossibleRelationships );
252 NewLayout->addWidget ( NewLabel );
253 NewLayout->addWidget ( NewCombo );
254 NewLayout->addWidget ( OkButton );
255 NewDialog->setLayout ( NewLayout );
256 NewDialog->adjustSize();
257 connect ( OkButton, SIGNAL ( clicked() ), NewDialog, SLOT ( accept() ),
258 Qt::UniqueConnection );
259
260 int Status = NewDialog->exec();
261
262 if ( Status == QDialog::Accepted )
263 {
264 SelectedRelationship = NewCombo->currentText();
265 }
266 }
267
268 treenode * NodeObject = confaccessor::gethandler()->getnode ( DatabaseClassName,
269 DatabaseUidName );
270
271 if ( NodeObject )
272 {
273 for ( treenode * Child : NodeObject->GetChildren() )
274 {
275 if ( dynamic_cast<RelationshipNode *> ( Child ) )
276 {
277 RelationshipNode * NodeRelationship = dynamic_cast<RelationshipNode *> ( Child );
278 dunedaq::conffwk::relationship_t RelationshipData =
279 NodeRelationship->relation_t();
280
281 if ( RelationshipData.p_name == SelectedRelationship.toStdString() )
282 {
283 if ( ( RelationshipData.p_cardinality == dunedaq::conffwk::zero_or_many ) || ( RelationshipData
286 {
287 std::vector<std::string> RelationshipValues;
288
289 for ( treenode * RelationshipChildren : NodeRelationship->GetChildren() )
290 RelationshipValues.push_back (
291 RelationshipChildren->GetData ( 0 ).toString().toStdString() );
292
293 for ( QStringList & Item : NewItems )
294 if ( std::find ( RelationshipValues.begin(), RelationshipValues.end(),
295 Item.at ( 0 ).toStdString() )
296 == RelationshipValues.end() ) RelationshipValues.push_back (
297 Item.at ( 0 ).toStdString() );
298
299 tref Object = NodeObject->GetObject();
300 dbe::config::api::commands::modobj ( Object, RelationshipData,
301 RelationshipValues );
302 }
303 else
304 {
305 QString SelectedObject;
306
307 if ( NewItems.size() > 1 )
308 {
309 QDialog * NewDialog = new QDialog();
310 QHBoxLayout * NewLayout = new QHBoxLayout();
311 QPushButton * OkButton = new QPushButton ( "Ok" );
312 QComboBox * NewCombo = new QComboBox();
313 QLabel * NewLabel = new QLabel ( "Choose Object : " );
314 NewCombo->addItems ( ObjectList );
315 NewLayout->addWidget ( NewLabel );
316 NewLayout->addWidget ( NewCombo );
317 NewLayout->addWidget ( OkButton );
318 NewDialog->setLayout ( NewLayout );
319 NewDialog->adjustSize();
320 connect ( OkButton, SIGNAL ( clicked() ), NewDialog, SLOT ( accept() ),
321 Qt::UniqueConnection );
322
323 int Status = NewDialog->exec();
324
325 if ( Status == QDialog::Accepted )
326 {
327 SelectedObject = NewCombo->currentText();
328 }
329 }
330 else
331 {
332 SelectedObject = NewItems.at ( 0 ).at ( 0 );
333 }
334
335 tref Object = NodeObject->GetObject();
336 dbe::config::api::commands::modobj ( Object, RelationshipData,
337 { SelectedObject.toStdString() } );
338
339 }
340 }
341 }
342 }
343 }
344}
345//------------------------------------------------------------------------------------------
346
347//------------------------------------------------------------------------------------------
349{
350 double dx = 0;
351 double dy = 0;
352
353 treenode * NodeObject = confaccessor::gethandler()->getnode ( DatabaseClassName,
354 DatabaseUidName );
355
356 if ( NodeObject )
357 {
358 for ( treenode * ChildNode : NodeObject->GetChildren() )
359 {
360 RelationshipNode * NodeRelationship = dynamic_cast<RelationshipNode *> ( ChildNode );
361
362 if ( NodeRelationship && NodeRelationship->GetHasStructure() )
363 {
364 dunedaq::conffwk::relationship_t RelationshipData =
365 NodeRelationship->relation_t();
366 GraphicalRelationship * RelationshipChildNode = new GraphicalRelationship (
367 DatabaseUidName, DatabaseClassName, RelationshipData );
368 RelationshipChildNode->setParentItem ( this );
369 RelationshipChildNode->AddGraphicChildren();
370
371 QPointF coord = RelationshipChildNode->mapFromParent ( boundingRect().bottomRight() );
372 RelationshipChildNode->setX ( coord.x() + dx );
373 RelationshipChildNode->setY ( coord.y() + dy );
374
375 for ( QGraphicsItem * GraphicItem : RelationshipChildNode->childItems() )
376 {
377 dy += GraphicItem->boundingRect().height();
378 }
379 }
380 }
381 }
382
383 IsFetched = true;
384}
385//------------------------------------------------------------------------------------------
386
387//------------------------------------------------------------------------------------------
389{
390 for ( QGraphicsItem * i : this->childItems() )
391 {
392 i->show();
393 }
394
395 double ThisOffsetX = 0;
396 double ThisOffsetY = 0;
397 GetOffsetX ( this, ThisOffsetX );
398 GetOffsetY ( this, ThisOffsetY );
399 QPointF ThisItemBottom = this->mapToScene ( this->boundingRect().bottomRight() );
400
401 if ( !this->childItems().isEmpty() )
402 {
403 ThisOffsetX -= ThisItemBottom.x();
404 ThisOffsetY -= ThisItemBottom.y();
405 }
406
408 QGraphicsItem * AuxiliaryItem = this;
409
410 while ( AuxiliaryItem->parentItem() != nullptr )
411 {
412 for ( int i = AuxiliaryItem->parentItem()->childItems().indexOf ( AuxiliaryItem ) + 1;
413 i < AuxiliaryItem->parentItem()->childItems().size(); ++i )
414 {
415 QGraphicsItem * Child = AuxiliaryItem->parentItem()->childItems().at ( i );
416 Child->setY ( Child->y() + ThisOffsetY );
417 }
418
419 AuxiliaryItem = AuxiliaryItem->parentItem();
420 }
421
424 double ThisTopLevelOffsetX = 0;
425 double ThisTopLevelOffsetY = 0;
426 GetOffsetX ( this->topLevelItem(), ThisTopLevelOffsetX );
427 GetOffsetY ( this->topLevelItem(), ThisTopLevelOffsetY );
428 QPointF ThisTopLevelItemBottom = this->topLevelItem()->mapToScene (
429 this->topLevelItem()->boundingRect().bottomRight() );
430
431 if ( !this->topLevelItem()->childItems().isEmpty() )
432 {
433 ThisTopLevelOffsetX -= ThisTopLevelItemBottom.x();
434 ThisTopLevelOffsetY -= ThisTopLevelItemBottom.y();
435 }
436
438 QList<QGraphicsItem *> TopLevelItems = scene()->items();
440 GraphicalObject * ThisTopLevelItem = dynamic_cast<GraphicalObject *>
441 ( this->topLevelItem() );
442 double LineHighestOffsetY = 0;
443
444 for ( QGraphicsItem * Item : TopLevelItems )
445 {
448 if ( Item->parentItem() == nullptr && ThisTopLevelItem->y() == Item->y()
449 && ThisTopLevelItem != Item )
450 {
451 GraphicalObject * ItemObject = dynamic_cast<GraphicalObject *> ( Item );
452
453 if ( ItemObject && LineHighestOffsetY < ItemObject->GetExpandedY() ) LineHighestOffsetY =
454 ItemObject->GetExpandedY();
455 }
456 }
457
460 for ( QGraphicsItem * Item : TopLevelItems )
461 {
462 if ( ThisTopLevelItem != Item && Item->parentItem() == nullptr )
463 {
464 if ( ThisTopLevelItem->y() < Item->y() && ThisTopLevelOffsetY > LineHighestOffsetY )
465 {
466 if ( LineHighestOffsetY == 0 )
467 {
468 Item->setY ( Item->y() + ThisOffsetY );
469 }
470 else
471 {
472 if ( ThisTopLevelOffsetY - LineHighestOffsetY < ThisTopLevelOffsetY
473 - ThisTopLevelItem->GetExpandedY() ) Item->setY (
474 Item->y() + ThisTopLevelOffsetY - LineHighestOffsetY );
475 else Item->setY (
476 Item->y() + ThisTopLevelOffsetY - ThisTopLevelItem->GetExpandedY() );
477 }
478 }
479 }
480
481 if ( ThisTopLevelItem->y() == Item->y() && ThisTopLevelItem->x() < Item->x()
482 && Item->parentItem() == nullptr )
483 {
484 if ( ThisTopLevelOffsetX > ThisTopLevelItem->GetExpandedX() )
485 {
486 if ( ThisTopLevelItem->GetExpandedX() == 0 )
487 {
488 Item->setX ( Item->x() + ThisOffsetX );
489 }
490 else
491 {
492 Item->setX ( Item->x() + ThisTopLevelOffsetX - ThisTopLevelItem->GetExpandedX() );
493 }
494 }
495 }
496 }
497
498 ThisTopLevelItem->SetExpandedX ( ThisTopLevelOffsetX );
499 ThisTopLevelItem->SetExpandedY ( ThisTopLevelOffsetY );
500 IsExpanded = true;
501}
502//------------------------------------------------------------------------------------------
503
504//------------------------------------------------------------------------------------------
506{
507 double ThisOffsetX = 0;
508 double ThisOffsetY = 0;
509 GetOffsetX ( this, ThisOffsetX );
510 GetOffsetY ( this, ThisOffsetY );
511 QPointF ThisItemBottom = this->mapToScene ( this->boundingRect().bottomRight() );
512
513 if ( !this->childItems().isEmpty() )
514 {
515 ThisOffsetX -= ThisItemBottom.x();
516 ThisOffsetY -= ThisItemBottom.y();
517 }
518
520 QGraphicsItem * AuxiliaryItem = this;
521
522 while ( AuxiliaryItem->parentItem() != nullptr )
523 {
524 for ( int i = AuxiliaryItem->parentItem()->childItems().indexOf ( AuxiliaryItem ) + 1;
525 i < AuxiliaryItem->parentItem()->childItems().size(); ++i )
526 {
527 QGraphicsItem * Child = AuxiliaryItem->parentItem()->childItems().at ( i );
528 Child->setY ( Child->y() - ThisOffsetY );
529 }
530
531 AuxiliaryItem = AuxiliaryItem->parentItem();
532 }
533
538 for ( QGraphicsItem * i : this->childItems() )
539 {
540 i->hide();
541 }
542
543 double ThisTopLevelOffsetX = 0;
544 double ThisTopLevelOffsetY = 0;
545 GetOffsetX ( this->topLevelItem(), ThisTopLevelOffsetX );
546 GetOffsetY ( this->topLevelItem(), ThisTopLevelOffsetY );
547 QPointF ThisTopLevelItemBottom = this->topLevelItem()->mapToScene (
548 this->topLevelItem()->boundingRect().bottomRight() );
549
550 if ( !this->topLevelItem()->childItems().isEmpty()
551 && this->topLevelItem()->childItems().at (
552 0 )->isVisible() )
553 {
554 ThisTopLevelOffsetX -= ThisTopLevelItemBottom.x();
555 ThisTopLevelOffsetY -= ThisTopLevelItemBottom.y();
556 }
557
559 QList<QGraphicsItem *> TopLevelItems = scene()->items();
561 GraphicalObject * ThisTopLevelItem = dynamic_cast<GraphicalObject *>
562 ( this->topLevelItem() );
563 double LineHighestOffsetY = 0;
564
565 for ( QGraphicsItem * Item : TopLevelItems )
566 {
569 if ( Item->parentItem() == nullptr && ThisTopLevelItem->y() == Item->y()
570 && ThisTopLevelItem != Item )
571 {
572 GraphicalObject * ItemObject = dynamic_cast<GraphicalObject *> ( Item );
573
574 if ( ItemObject && LineHighestOffsetY < ItemObject->GetExpandedY() ) LineHighestOffsetY =
575 ItemObject->GetExpandedY();
576 }
577 }
578
581 for ( QGraphicsItem * Item : TopLevelItems )
582 {
583 if ( ThisTopLevelItem != Item && Item->parentItem() == nullptr )
584 {
585 if ( ThisTopLevelItem->y() < Item->y() && ThisTopLevelItem->GetExpandedY()
586 > LineHighestOffsetY )
587 {
588 if ( LineHighestOffsetY == 0 )
589 {
590 Item->setY ( Item->y() - ThisOffsetY );
591 }
592 else
593 {
594 if ( ThisTopLevelOffsetY >= LineHighestOffsetY && ThisTopLevelOffsetY
595 < ThisTopLevelItem->GetExpandedY() ) Item->setY (
596 Item->y() - abs ( ThisTopLevelOffsetY - ThisTopLevelItem->GetExpandedY() ) );
597
598 if ( ThisTopLevelItem->GetExpandedY() > LineHighestOffsetY && ThisTopLevelOffsetY
599 < LineHighestOffsetY ) Item->setY (
600 Item->y() - abs ( ThisTopLevelItem->GetExpandedY() - LineHighestOffsetY ) );
601 }
602 }
603 }
604
605 if ( ThisTopLevelItem->y() == Item->y() && ThisTopLevelItem->x() < Item->x()
606 && Item->parentItem() == nullptr )
607 {
608 if ( ThisTopLevelOffsetX < ThisTopLevelItem->GetExpandedX() )
609 {
610 Item->setX ( Item->x() - abs ( ThisTopLevelOffsetX - ThisTopLevelItem->GetExpandedX() ) );
611 }
612 }
613 }
614
615 ThisTopLevelItem->SetExpandedX ( ThisTopLevelOffsetX );
616 ThisTopLevelItem->SetExpandedY ( ThisTopLevelOffsetY );
617 IsExpanded = false;
618}
619//------------------------------------------------------------------------------------------
620
621//------------------------------------------------------------------------------------------
622void dbe::GraphicalObject::GetOffsetX ( QGraphicsItem * Item, double & Offset )
623{
624 for ( QGraphicsItem * ChildItem : Item->childItems() )
625 {
626 if ( ChildItem->isVisible() )
627 {
628 QPointF ChildItemBottom = ChildItem->mapToScene (
629 ChildItem->boundingRect().bottomRight() );
630
631 if ( Offset < ChildItemBottom.x() )
632 {
633 Offset = ChildItemBottom.x();
634 }
635 }
636
637 GetOffsetX ( ChildItem, Offset );
638 }
639}
640//------------------------------------------------------------------------------------------
641
642//------------------------------------------------------------------------------------------
643void dbe::GraphicalObject::GetOffsetY ( QGraphicsItem * Item, double & Offset )
644{
645 for ( QGraphicsItem * ChildItem : Item->childItems() )
646 {
647 if ( ChildItem->isVisible() )
648 {
649 QPointF ChildItemBottom = ChildItem->mapToScene (
650 ChildItem->boundingRect().bottomRight() );
651
652 if ( Offset < ChildItemBottom.y() )
653 {
654 Offset = ChildItemBottom.y();
655 }
656 }
657
658 GetOffsetY ( ChildItem, Offset );
659 }
660}
661//------------------------------------------------------------------------------------------
662
663//------------------------------------------------------------------------------------------
664void dbe::GraphicalObject::LocateTopMostItem ( QGraphicsItem * Auxiliary )
665{
666 while ( Auxiliary->parentItem() != nullptr )
667 {
668 Auxiliary = Auxiliary->parentItem();
669 }
670}
671//------------------------------------------------------------------------------------------
672
673//------------------------------------------------------------------------------------------
675{
676 return DatabaseClassName;
677}
678//------------------------------------------------------------------------------------------
679
680//------------------------------------------------------------------------------------------
682{
683 return DatabaseUidName;
684}
685//------------------------------------------------------------------------------------------
686
687//------------------------------------------------------------------------------------------
689{
690 return expandedX;
691}
692//------------------------------------------------------------------------------------------
693
694//------------------------------------------------------------------------------------------
696{
697 return expandedY;
698}
699//------------------------------------------------------------------------------------------
700
701//------------------------------------------------------------------------------------------
703{
704 expandedX = dx;
705}
706//------------------------------------------------------------------------------------------
707
708//------------------------------------------------------------------------------------------
710{
711 expandedY = dy;
712}
713//------------------------------------------------------------------------------------------
714
715//------------------------------------------------------------------------------------------
716dbe::GraphicalRelationship::GraphicalRelationship ( QString ObjectName, QString ClassName,
718 QGraphicsObject * parent )
719 : QGraphicsObject ( parent ),
720 DatabaseClassName ( ClassName ),
721 DatabaseUidName ( ObjectName ),
722 RelationshipData ( Data ),
723 TextItem ( nullptr )
724{
725 TextItem = new QGraphicsTextItem ( QString ( Data.p_name.c_str() ) );
726}
727//------------------------------------------------------------------------------------------
728
729//------------------------------------------------------------------------------------------
734//------------------------------------------------------------------------------------------
735
736//------------------------------------------------------------------------------------------
738{
739 return TextItem->boundingRect();
740}
741//------------------------------------------------------------------------------------------
742
743//------------------------------------------------------------------------------------------
744void dbe::GraphicalRelationship::paint ( QPainter * painter,
745 const QStyleOptionGraphicsItem * option,
746 QWidget * widget )
747{
748 painter->setFont ( QFont ( "Helvetica", 10 ) );
749 TextItem->paint ( painter, option, widget );
750}
751//------------------------------------------------------------------------------------------
752
753//------------------------------------------------------------------------------------------
755{
756 QPainterPath path;
757 path.addRect ( TextItem->boundingRect() );
758 return path;
759}
760//------------------------------------------------------------------------------------------
761
762//------------------------------------------------------------------------------------------
763void dbe::GraphicalRelationship::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * event )
764{
765 Q_UNUSED ( event )
766}
767//------------------------------------------------------------------------------------------
768
769//------------------------------------------------------------------------------------------
770void dbe::GraphicalRelationship::mousePressEvent ( QGraphicsSceneMouseEvent * event )
771{
772 Q_UNUSED ( event )
773}
774//------------------------------------------------------------------------------------------
775
776//------------------------------------------------------------------------------------------
777void dbe::GraphicalRelationship::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
778{
779 Q_UNUSED ( event )
780}
781//------------------------------------------------------------------------------------------
782
783//------------------------------------------------------------------------------------------
785{
786 double OffsetY = 0;
787 double OffsetX = 10;
788
789 treenode * NodeObject = confaccessor::gethandler()->getnode ( DatabaseClassName,
790 DatabaseUidName );
791
792 if ( NodeObject )
793 {
794 for ( treenode * ChildNode : NodeObject->GetChildren() )
795 {
796 if ( ChildNode->GetData ( 0 ).toString() == QString ( RelationshipData.p_name.c_str() ) )
797 {
798 for ( treenode * ChildChildNode : ChildNode->GetChildren() )
799 {
800 ObjectNode * ChildChildNodeObject = dynamic_cast<ObjectNode *> ( ChildChildNode );
801
802 if ( ChildChildNodeObject )
803 {
804 std::string cname = ChildChildNodeObject->GetObject().class_name();
805 GraphicalClass Dummy = confaccessor::guiconfig()->graphical ( cname );
806 GraphicalObject * ObjectNodeGraphical = new GraphicalObject (
807 true, ChildChildNode->GetData ( 0 ).toString(), Dummy );
808 ObjectNodeGraphical->setParentItem ( this );
809
810 QPointF coord = ObjectNodeGraphical->mapFromParent ( boundingRect().topRight() );
811 ObjectNodeGraphical->setX ( coord.x() + OffsetX );
812 ObjectNodeGraphical->setY ( coord.y() + OffsetY );
813 OffsetY += ObjectNodeGraphical->boundingRect().height();
814 }
815 }
816
817 break;
818 }
819 }
820 }
821}
822//------------------------------------------------------------------------------------------
QGraphicsTextItem * TextItem
void AddGraphicChildren()
Graphics.
void GetOffsetY(QGraphicsItem *Item, double &Offset)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
double GetExpandedX() const
void GetOffsetX(QGraphicsItem *Item, double &Offset)
Some Api.
QPainterPath shape() const
double GetExpandedY() const
void mousePressEvent(QGraphicsSceneMouseEvent *event)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
void dropEvent(QGraphicsSceneDragDropEvent *event)
GraphicalObject(bool Used, QString ObjectName, GraphicalClass GraphInfo, QGraphicsObject *parent=0)
QString GetDatabaseUidName() const
QRectF boundingRect() const
void LocateTopMostItem(QGraphicsItem *Auxiliary)
void SetExpandedX(double dx)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Event Handler.
QGraphicsPixmapItem * IconItem
void SetExpandedY(double dy)
QString GetDatabaseClassName() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QGraphicsTextItem * TextItem
QPainterPath shape() const
void mousePressEvent(QGraphicsSceneMouseEvent *event)
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
GraphicalRelationship(QString ObjectName, QString ClassName, dunedaq::conffwk::relationship_t &Data, QGraphicsObject *parent=0)
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Event Handler.
tref GetObject() const
Definition treenode.cpp:267
dunedaq::conffwk::relationship_t relation_t() const
Definition treenode.cpp:399
static cptr< datahandler > gethandler()
static cptr< ui::config::info > guiconfig()
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
bool GetHasStructure() const
Definition treenode.cpp:130
virtual tref GetObject() const
Definition treenode.cpp:75
QList< treenode * > GetChildren() const
Definition treenode.cpp:105
void modobj(tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T Value)
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:164
const std::vector< std::string > p_subclasses
Definition Schema.hpp:162