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