From 539de96455fabd268ce901a69b142c17b832de29 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 14 Mar 2021 11:49:01 +0100 Subject: [PATCH] Fix problem when really old elements are added to a new project. These elements do not have an uuid for each terminal. So when exporting, save an unique ID into the terminal. So the conductors know to which terminal they must be connected --- sources/diagram.cpp | 22 ++++++++++++++++++++++ sources/diagram.h | 7 +++++++ sources/qetgraphicsitem/element.cpp | 9 ++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 2ea8bf045..71f79848f 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -1864,6 +1864,28 @@ void Diagram::changeZValue(QET::DepthOption option) delete undo; } +int Diagram::uniqueTerminalID() const +{ + for (int i=1; i < 10000; i++) { + bool found = false; + for (auto element: elements()) { + for (auto terminal: element->terminals()) { + if (terminal->ID() == i) { + found = true; + break; + } + } + if (found) { + break; + } + } + + if (!found) + return i; + } + return -1; +} + /** @brief Diagram::loadElmtFolioSeq This class loads all folio sequential variables related diff --git a/sources/diagram.h b/sources/diagram.h index 5928747a5..a036f53a4 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -257,6 +257,13 @@ class Diagram : public QGraphicsScene NumerotationContext *nc); void changeZValue(QET::DepthOption option); + /*! + * \brief uniqueTerminalID + * Determines a new unique Terminal ID + * This is used only for legacy purpose + */ + int uniqueTerminalID() const; + public slots: void adjustSceneRect (); void titleChanged(const QString &); diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 0f330a778..bc5b7dda9 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -944,8 +944,15 @@ QDomElement Element::toXml( QDomElement terminal = t -> toXml(document); if (t->ID() > 0) { // for backward compatibility + // Terminal was loaded during loading an old project. So the terminal has a valid id terminal.setAttribute("id", t->ID()); // for backward compatibility - } + } else if (t->uuid().isNull()) { + // for backward compatibility + // An old element with no uuid on the terminals was added to the project. + // give it an id + t->setID(t->diagram()->uniqueTerminalID()); + terminal.setAttribute("id", t->ID()); + } xml_terminals.appendChild(terminal); } element.appendChild(xml_terminals);