mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
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:
parent
2a4416469a
commit
539de96455
@ -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
|
||||
|
@ -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 &);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user