diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index b87138a5a..e4567b0ec 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -982,11 +982,29 @@ QDomElement Conductor::toXml(QDomDocument & doc) const { dom_element.appendChild(createXmlProperty(doc, "y", pos().y())); // Terminal is uniquely identified by the uuid of the terminal and the element - dom_element.appendChild(createXmlProperty(doc, "element1", terminal1->parentElement()->uuid())); - dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->uuid())); + QUuid terminal = terminal1->uuid(); + QUuid terminalParent = terminal1->parentElement()->uuid(); + if (terminalParent.isNull() || terminal.isNull()) { + // legacy when the terminal does not have a valid uuid + // do not store element1 information, because this is used to determine in the fromXml + // process that legacy file format + dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal1->ID())); + } else { + dom_element.appendChild(createXmlProperty(doc, "element1", terminalParent)); + dom_element.appendChild(createXmlProperty(doc, "terminal1", terminal)); + } - dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid())); - dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid())); + terminal = terminal2->uuid(); + terminalParent = terminal2->parentElement()->uuid(); + if (terminalParent.isNull() || terminal.isNull()) { + // legacy when the terminal does not have a valid uuid + // do not store element1 information, because this is used to determine in the fromXml + // process that legacy file format + dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->ID())); + } else { + dom_element.appendChild(createXmlProperty(doc, "element2", terminal2->parentElement()->uuid())); + dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid())); + } dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label)); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 7982e454f..e2d8169f1 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -662,6 +662,11 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool 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."; + // store id for legacy purpose, because when opening a old project in the collection the terminal does not have an uuid. Therefore the id must be used + if (p->uuid().isNull()) { + p->setID(qde.attribute("id").toInt()); + } + priv_id_adr.insert(qde.attribute("id").toInt(), p); terminal_trouvee = true; // We used to break here, because we did not expect diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 8b44f5440..c16e3eee7 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -706,6 +706,10 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal) return true; } +void Terminal::setID(int id) { + m_id = id; +} + /** @brief Terminal::conductors @return La liste des conducteurs lies a cette borne @@ -811,6 +815,10 @@ QUuid Terminal::uuid() const { return d->m_uuid; } +int Terminal::ID() const { + return m_id; +} + QPointF Terminal::dockPos() { return dock_elmt_; } diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 6b153e0c7..daf7ac935 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -77,6 +77,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface Diagram *diagram () const; Element *parentElement () const; QUuid uuid () const; + int ID() const; QPointF dockPos(); QPointF originPos(); @@ -90,6 +91,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface void updateConductor(); bool isLinkedTo(Terminal *); bool canBeLinkedTo(Terminal *); + void setID(int id); // methods related to XML import/export static bool valideXml(const QDomElement &); @@ -151,6 +153,9 @@ class Terminal : public QGraphicsObject, public PropertiesInterface /// Number of Terminal QString number_terminal_; bool name_terminal_hidden{true}; + + /// legacy id used by the conductor to find the terminal. From 0.8x on the uuid is used instead. + int m_id{-1}; private: void init(QString number, QString name, bool hiddenName);