24 : QGraphicsObject ( parent ),
25 GraphicalInfo ( GraphInfo ),
28 DatabaseClassName ( GraphInfo.DatabaseClassName ),
29 DatabaseUidName ( ObjectName ),
35 setAcceptDrops (
true );
36 setFlag ( ItemIsMovable );
54 QBitmap IconMask = Icon.createHeuristicMask();
55 Icon.setMask ( IconMask );
57 IconItem =
new QGraphicsPixmapItem ( Icon );
58 TextItem =
new QGraphicsTextItem ( ObjectName );
90 const QStyleOptionGraphicsItem * option,
96 QFontMetrics Metric ( QFont (
"Helvetica", 10 ) );
97 painter->setFont ( QFont (
"Helvetica", 10 ) );
98 painter->drawPixmap ( IconItem->boundingRect(), IconItem->pixmap(),
99 IconItem->boundingRect() );
101 IconItem->boundingRect().bottomLeft() + QPointF (
102 0, Metric.boundingRect ( DatabaseUidName ).height() ),
151 if ( ! ( event->buttons() & Qt::LeftButton ) )
156 if ( ( event->pos() - StartDrag ).manhattanLength() < QApplication::startDragDistance() )
161 QDrag * drag =
new QDrag ( event->widget() );
162 QPixmap Icon = IconItem->pixmap();
164 QStringList DataList;
165 QMimeData * mimeData =
new QMimeData;
167 QDataStream DataStream ( &ItemData, QIODevice::WriteOnly );
169 DataList.append ( QString ( DatabaseUidName ) );
170 DataList.append ( QString ( DatabaseClassName ) );
171 DataStream << DataList;
172 mimeData->setData (
"application/vnd.text.list", ItemData );
174 drag->setMimeData ( mimeData );
175 drag->setPixmap ( Icon );
177 Qt::DropAction dropAction = drag->exec();
178 Q_UNUSED ( dropAction )
185 QByteArray encodedData =
event->mimeData()->data (
"application/vnd.text.list" );
186 QDataStream stream ( &encodedData, QIODevice::ReadOnly );
187 QList<QStringList> NewItems;
189 while ( !stream.atEnd() )
196 QStringList ObjectList;
198 for ( QStringList & i : NewItems )
200 ObjectList.append ( i.at ( 0 ) );
203 for (
int i = 0; i < NewItems.size(); ++i )
205 if ( NewItems.at ( 0 ).at ( 1 ) != NewItems.at ( i ).at ( 1 ) )
211 QStringList PossibleRelationships;
212 QString ClassName = NewItems.at ( 0 ).at ( 1 );
216 std::vector<dunedaq::conffwk::relationship_t> RelationshipList = ClassInfoReceiverObject
221 if ( i.p_type == ClassName.toStdString() ) PossibleRelationships.append (
222 QString::fromStdString ( i.p_name ) );
227 std::vector<std::string> RelationshipListDropped = ClassInfoDroppedObject.
p_subclasses;
229 for ( std::string & j : RelationshipListDropped )
231 if ( j == ClassName.toStdString() ) PossibleRelationships.append (
232 QString::fromStdString ( i.p_name ) );
236 QString SelectedRelationship;
238 if ( PossibleRelationships.size() == 0 )
242 else if ( PossibleRelationships.size() == 1 ) SelectedRelationship = PossibleRelationships
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 );
260 int Status = NewDialog->exec();
262 if ( Status == QDialog::Accepted )
264 SelectedRelationship = NewCombo->currentText();
281 if ( RelationshipData.
p_name == SelectedRelationship.toStdString() )
287 std::vector<std::string> RelationshipValues;
290 RelationshipValues.push_back (
291 RelationshipChildren->GetData ( 0 ).toString().toStdString() );
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() );
301 RelationshipValues );
305 QString SelectedObject;
307 if ( NewItems.size() > 1 )
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 );
323 int Status = NewDialog->exec();
325 if ( Status == QDialog::Accepted )
327 SelectedObject = NewCombo->currentText();
332 SelectedObject = NewItems.at ( 0 ).at ( 0 );
337 { SelectedObject.toStdString() } );
367 DatabaseUidName, DatabaseClassName, RelationshipData );
368 RelationshipChildNode->setParentItem (
this );
371 QPointF coord = RelationshipChildNode->mapFromParent ( boundingRect().bottomRight() );
372 RelationshipChildNode->setX ( coord.x() + dx );
373 RelationshipChildNode->setY ( coord.y() + dy );
375 for ( QGraphicsItem * GraphicItem : RelationshipChildNode->childItems() )
377 dy += GraphicItem->boundingRect().height();
390 for ( QGraphicsItem * i : this->childItems() )
395 double ThisOffsetX = 0;
396 double ThisOffsetY = 0;
397 GetOffsetX (
this, ThisOffsetX );
398 GetOffsetY (
this, ThisOffsetY );
399 QPointF ThisItemBottom = this->mapToScene ( this->boundingRect().bottomRight() );
401 if ( !this->childItems().isEmpty() )
403 ThisOffsetX -= ThisItemBottom.x();
404 ThisOffsetY -= ThisItemBottom.y();
408 QGraphicsItem * AuxiliaryItem =
this;
410 while ( AuxiliaryItem->parentItem() !=
nullptr )
412 for (
int i = AuxiliaryItem->parentItem()->childItems().indexOf ( AuxiliaryItem ) + 1;
413 i < AuxiliaryItem->parentItem()->childItems().size(); ++i )
415 QGraphicsItem * Child = AuxiliaryItem->parentItem()->childItems().at ( i );
416 Child->setY ( Child->y() + ThisOffsetY );
419 AuxiliaryItem = AuxiliaryItem->parentItem();
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() );
431 if ( !this->topLevelItem()->childItems().isEmpty() )
433 ThisTopLevelOffsetX -= ThisTopLevelItemBottom.x();
434 ThisTopLevelOffsetY -= ThisTopLevelItemBottom.y();
438 QList<QGraphicsItem *> TopLevelItems = scene()->items();
441 ( this->topLevelItem() );
442 double LineHighestOffsetY = 0;
444 for ( QGraphicsItem *
Item : TopLevelItems )
448 if (
Item->parentItem() ==
nullptr && ThisTopLevelItem->y() ==
Item->y()
449 && ThisTopLevelItem !=
Item )
453 if ( ItemObject && LineHighestOffsetY < ItemObject->GetExpandedY() ) LineHighestOffsetY =
460 for ( QGraphicsItem *
Item : TopLevelItems )
462 if ( ThisTopLevelItem !=
Item &&
Item->parentItem() ==
nullptr )
464 if ( ThisTopLevelItem->y() <
Item->y() && ThisTopLevelOffsetY > LineHighestOffsetY )
466 if ( LineHighestOffsetY == 0 )
468 Item->setY (
Item->y() + ThisOffsetY );
472 if ( ThisTopLevelOffsetY - LineHighestOffsetY < ThisTopLevelOffsetY
474 Item->y() + ThisTopLevelOffsetY - LineHighestOffsetY );
481 if ( ThisTopLevelItem->y() ==
Item->y() && ThisTopLevelItem->x() <
Item->x()
482 &&
Item->parentItem() ==
nullptr )
484 if ( ThisTopLevelOffsetX > ThisTopLevelItem->
GetExpandedX() )
488 Item->setX (
Item->x() + ThisOffsetX );
507 double ThisOffsetX = 0;
508 double ThisOffsetY = 0;
509 GetOffsetX (
this, ThisOffsetX );
510 GetOffsetY (
this, ThisOffsetY );
511 QPointF ThisItemBottom = this->mapToScene ( this->boundingRect().bottomRight() );
513 if ( !this->childItems().isEmpty() )
515 ThisOffsetX -= ThisItemBottom.x();
516 ThisOffsetY -= ThisItemBottom.y();
520 QGraphicsItem * AuxiliaryItem =
this;
522 while ( AuxiliaryItem->parentItem() !=
nullptr )
524 for (
int i = AuxiliaryItem->parentItem()->childItems().indexOf ( AuxiliaryItem ) + 1;
525 i < AuxiliaryItem->parentItem()->childItems().size(); ++i )
527 QGraphicsItem * Child = AuxiliaryItem->parentItem()->childItems().at ( i );
528 Child->setY ( Child->y() - ThisOffsetY );
531 AuxiliaryItem = AuxiliaryItem->parentItem();
538 for ( QGraphicsItem * i : this->childItems() )
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() );
550 if ( !this->topLevelItem()->childItems().isEmpty()
551 && this->topLevelItem()->childItems().at (
554 ThisTopLevelOffsetX -= ThisTopLevelItemBottom.x();
555 ThisTopLevelOffsetY -= ThisTopLevelItemBottom.y();
559 QList<QGraphicsItem *> TopLevelItems = scene()->items();
562 ( this->topLevelItem() );
563 double LineHighestOffsetY = 0;
565 for ( QGraphicsItem *
Item : TopLevelItems )
569 if (
Item->parentItem() ==
nullptr && ThisTopLevelItem->y() ==
Item->y()
570 && ThisTopLevelItem !=
Item )
574 if ( ItemObject && LineHighestOffsetY < ItemObject->GetExpandedY() ) LineHighestOffsetY =
581 for ( QGraphicsItem *
Item : TopLevelItems )
583 if ( ThisTopLevelItem !=
Item &&
Item->parentItem() ==
nullptr )
586 > LineHighestOffsetY )
588 if ( LineHighestOffsetY == 0 )
590 Item->setY (
Item->y() - ThisOffsetY );
594 if ( ThisTopLevelOffsetY >= LineHighestOffsetY && ThisTopLevelOffsetY
596 Item->y() - abs ( ThisTopLevelOffsetY - ThisTopLevelItem->
GetExpandedY() ) );
598 if ( ThisTopLevelItem->
GetExpandedY() > LineHighestOffsetY && ThisTopLevelOffsetY
599 < LineHighestOffsetY )
Item->setY (
600 Item->y() - abs ( ThisTopLevelItem->
GetExpandedY() - LineHighestOffsetY ) );
605 if ( ThisTopLevelItem->y() ==
Item->y() && ThisTopLevelItem->x() <
Item->x()
606 &&
Item->parentItem() ==
nullptr )
608 if ( ThisTopLevelOffsetX < ThisTopLevelItem->GetExpandedX() )
796 if ( ChildNode->GetData ( 0 ).toString() == QString ( RelationshipData.p_name.c_str() ) )
802 if ( ChildChildNodeObject )
807 true, ChildChildNode->GetData ( 0 ).toString(), Dummy );
808 ObjectNodeGraphical->setParentItem (
this );
810 QPointF coord = ObjectNodeGraphical->mapFromParent ( boundingRect().topRight() );
811 ObjectNodeGraphical->setX ( coord.x() + OffsetX );
812 ObjectNodeGraphical->setY ( coord.y() + OffsetY );
813 OffsetY += ObjectNodeGraphical->
boundingRect().height();