From 91a56799a7332a8a7414bd33350d875826626759 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 1 Oct 2020 16:31:15 +0200 Subject: [PATCH] Solves problem that terminals are not placed at the correct place --- sources/qetgraphicsitem/element.cpp | 10 ++++++++-- sources/qetgraphicsitem/terminal.cpp | 8 ++++++++ sources/qetgraphicsitem/terminal.h | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 2df97d364..fbb04347d 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -650,8 +650,14 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool for(QGraphicsItem *qgi: childItems()) { // TODO: Where the Terminals are added as childs? if (Terminal *p = qgraphicsitem_cast(qgi)) { bool terminal_trouvee = false; - foreach(QDomElement qde, liste_terminals) { - if (p -> fromXml(qde)) { // TODO: is there validXML enough? Because the Terminal was already read in the ElementCreation function + for(QDomElement qde: liste_terminals) { + Terminal diagramTerminal(0,0, Qet::Orientation::East); + diagramTerminal.fromXml(qde); + QPointF dockPos1 = diagramTerminal.originPos(); // position here is directly the dock_elmt_ position (stored in the diagram) + QPointF dockPos2 = p->dockPos(); + if (qFuzzyCompare(dockPos1.x(), dockPos2.x()) && + qFuzzyCompare(dockPos1.y(), dockPos2.y()) && + p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored qDebug() << "Matching Terminal found."; priv_id_adr.insert(qde.attribute("id").toInt(), p); terminal_trouvee = true; diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 51923ed0e..8b44f5440 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -811,6 +811,14 @@ QUuid Terminal::uuid() const { return d->m_uuid; } +QPointF Terminal::dockPos() { + return dock_elmt_; +} + +QPointF Terminal::originPos() { + return d->m_pos; +} + /** @brief Conductor::relatedPotentialTerminal Return terminal at the same potential from the same diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 8a06733f9..6b153e0c7 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -77,6 +77,8 @@ class Terminal : public QGraphicsObject, public PropertiesInterface Diagram *diagram () const; Element *parentElement () const; QUuid uuid () const; + QPointF dockPos(); + QPointF originPos(); QList conductors() const; Qet::Orientation orientation() const;