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