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);