if no uuid for the terminal is available, use write the id of the terminal to the xml file, otherwise no connection can be done after saving

This commit is contained in:
Martin Marmsoler
2020-10-02 14:58:33 +02:00
parent 9684d753ec
commit c8691b243b
4 changed files with 40 additions and 4 deletions

View File

@@ -982,11 +982,29 @@ QDomElement Conductor::toXml(QDomDocument & doc) const {
dom_element.appendChild(createXmlProperty(doc, "y", pos().y())); dom_element.appendChild(createXmlProperty(doc, "y", pos().y()));
// Terminal is uniquely identified by the uuid of the terminal and the element // Terminal is uniquely identified by the uuid of the terminal and the element
dom_element.appendChild(createXmlProperty(doc, "element1", terminal1->parentElement()->uuid())); QUuid terminal = terminal1->uuid();
dom_element.appendChild(createXmlProperty(doc, "terminal1", 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));
}
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, "element2", terminal2->parentElement()->uuid()));
dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid())); dom_element.appendChild(createXmlProperty(doc, "terminal2", terminal2->uuid()));
}
dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label)); dom_element.appendChild(createXmlProperty(doc, "freezeLabel", m_freeze_label));

View File

@@ -662,6 +662,11 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
qFuzzyCompare(dockPos1.y(), dockPos2.y()) && qFuzzyCompare(dockPos1.y(), dockPos2.y()) &&
p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored p->orientation() == diagramTerminal.orientation()) { // check if the part in the collection is the same as in the diagram stored
qDebug() << "Matching Terminal found."; 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); priv_id_adr.insert(qde.attribute("id").toInt(), p);
terminal_trouvee = true; terminal_trouvee = true;
// We used to break here, because we did not expect // We used to break here, because we did not expect

View File

@@ -706,6 +706,10 @@ bool Terminal::canBeLinkedTo(Terminal *other_terminal)
return true; return true;
} }
void Terminal::setID(int id) {
m_id = id;
}
/** /**
@brief Terminal::conductors @brief Terminal::conductors
@return La liste des conducteurs lies a cette borne @return La liste des conducteurs lies a cette borne
@@ -811,6 +815,10 @@ QUuid Terminal::uuid() const {
return d->m_uuid; return d->m_uuid;
} }
int Terminal::ID() const {
return m_id;
}
QPointF Terminal::dockPos() { QPointF Terminal::dockPos() {
return dock_elmt_; return dock_elmt_;
} }

View File

@@ -77,6 +77,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
Diagram *diagram () const; Diagram *diagram () const;
Element *parentElement () const; Element *parentElement () const;
QUuid uuid () const; QUuid uuid () const;
int ID() const;
QPointF dockPos(); QPointF dockPos();
QPointF originPos(); QPointF originPos();
@@ -90,6 +91,7 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
void updateConductor(); void updateConductor();
bool isLinkedTo(Terminal *); bool isLinkedTo(Terminal *);
bool canBeLinkedTo(Terminal *); bool canBeLinkedTo(Terminal *);
void setID(int id);
// methods related to XML import/export // methods related to XML import/export
static bool valideXml(const QDomElement &); static bool valideXml(const QDomElement &);
@@ -152,6 +154,9 @@ class Terminal : public QGraphicsObject, public PropertiesInterface
QString number_terminal_; QString number_terminal_;
bool name_terminal_hidden{true}; 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: private:
void init(QString number, QString name, bool hiddenName); void init(QString number, QString name, bool hiddenName);
void init(QPointF pf, Qet::Orientation o, QString number, void init(QPointF pf, Qet::Orientation o, QString number,