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

This commit is contained in:
Martin Marmsoler
2021-03-14 11:49:01 +01:00
parent 2a4416469a
commit 539de96455
3 changed files with 37 additions and 1 deletions

View File

@@ -1864,6 +1864,28 @@ void Diagram::changeZValue(QET::DepthOption option)
delete undo; 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 @brief Diagram::loadElmtFolioSeq
This class loads all folio sequential variables related This class loads all folio sequential variables related

View File

@@ -257,6 +257,13 @@ class Diagram : public QGraphicsScene
NumerotationContext *nc); NumerotationContext *nc);
void changeZValue(QET::DepthOption option); 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: public slots:
void adjustSceneRect (); void adjustSceneRect ();
void titleChanged(const QString &); void titleChanged(const QString &);

View File

@@ -944,7 +944,14 @@ QDomElement Element::toXml(
QDomElement terminal = t -> toXml(document); QDomElement terminal = t -> toXml(document);
if (t->ID() > 0) { if (t->ID() > 0) {
// for backward compatibility // 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 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); xml_terminals.appendChild(terminal);
} }