mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 08:40:53 +01:00
Use uuid instead of an index to connect multiple elements
This commit is contained in:
committed by
Laurent Trinques
parent
bb24e121eb
commit
e6f77ec369
@@ -579,13 +579,27 @@ bool Conductor::valideXml(QDomElement &e){
|
||||
if (!e.hasAttribute("terminal2")) return(false);
|
||||
|
||||
bool conv_ok;
|
||||
// parse l'abscisse
|
||||
e.attribute("terminal1").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
// parse l'abscisse
|
||||
if (e.hasAttribute("element1")) {
|
||||
if (QUuid(e.attribute("element1")).isNull())
|
||||
return false;
|
||||
if (QUuid(e.attribute("terminal1")).isNull())
|
||||
return false;
|
||||
} else {
|
||||
e.attribute("terminal1").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
}
|
||||
|
||||
// parse l'ordonnee
|
||||
e.attribute("terminal2").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
if (e.hasAttribute("element2")) {
|
||||
if (QUuid(e.attribute("element2")).isNull())
|
||||
return false;
|
||||
if (QUuid(e.attribute("terminal2")).isNull())
|
||||
return false;
|
||||
} else {
|
||||
e.attribute("terminal2").toInt(&conv_ok);
|
||||
if (!conv_ok) return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
@@ -994,8 +1008,23 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
|
||||
|
||||
dom_element.setAttribute("x", QString::number(pos().x()));
|
||||
dom_element.setAttribute("y", QString::number(pos().y()));
|
||||
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1));
|
||||
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2));
|
||||
|
||||
// Terminal is uniquely identified by the uuid of the terminal and the element
|
||||
if (terminal1->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal1", table_adr_id.value(terminal1)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element1", terminal1->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal1", terminal1->uuid().toString());
|
||||
}
|
||||
|
||||
if (terminal2->uuid().isNull()) {
|
||||
// legacy method to identify the terminal
|
||||
dom_element.setAttribute("terminal2", table_adr_id.value(terminal2)); // for backward compability
|
||||
} else {
|
||||
dom_element.setAttribute("element2", terminal2->parentElement()->uuid().toString());
|
||||
dom_element.setAttribute("terminal2", terminal2->uuid().toString());
|
||||
}
|
||||
dom_element.setAttribute("freezeLabel", m_freeze_label? "true" : "false");
|
||||
|
||||
// on n'exporte les segments du conducteur que si ceux-ci ont
|
||||
@@ -1031,7 +1060,8 @@ QDomElement Conductor::toXml(QDomDocument &dom_document, QHash<Terminal *, int>
|
||||
|
||||
/**
|
||||
* @brief Conductor::pathFromXml
|
||||
* Generate the path from xml file
|
||||
* Generate the path (of the line) from xml file by checking the segments in the xml
|
||||
* file
|
||||
* @param e
|
||||
* @return true if generate path success else return false
|
||||
*/
|
||||
|
||||
@@ -1047,7 +1047,7 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
|
||||
foreach(Terminal *t, terminals()) {
|
||||
// alors on enregistre la borne
|
||||
QDomElement terminal = t -> toXml(document);
|
||||
terminal.setAttribute("id", id_terminal);
|
||||
terminal.setAttribute("id", id_terminal); // for backward compatibility
|
||||
table_adr_id.insert(t, id_terminal ++);
|
||||
xml_terminals.appendChild(terminal);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ const qreal Terminal::Z = 1000;
|
||||
void Terminal::init(QString number, QString name, bool hiddenName) {
|
||||
|
||||
hovered_color_ = Terminal::neutralColor;
|
||||
m_uuid = QUuid::createUuid();
|
||||
|
||||
// calcul de la position du point d'amarrage a l'element
|
||||
dock_elmt_ = d->m_pos;
|
||||
@@ -709,13 +708,12 @@ QList<Conductor *> Terminal::conductors() const {
|
||||
*/
|
||||
QDomElement Terminal::toXml(QDomDocument &doc) const {
|
||||
QDomElement qdo = doc.createElement("terminal");
|
||||
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x()));
|
||||
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));
|
||||
qdo.setAttribute("x", QString("%1").arg(dock_elmt_.x())); // for backward compatibility
|
||||
qdo.setAttribute("y", QString("%1").arg(dock_elmt_.y()));// for backward compatibility
|
||||
qdo.setAttribute("orientation", d->m_orientation);
|
||||
qdo.setAttribute("number", number_terminal_);
|
||||
qdo.setAttribute("name", name_terminal_);
|
||||
qdo.setAttribute("nameHidden", name_terminal_hidden);
|
||||
qdo.setAttribute("uuid", m_uuid.toString());
|
||||
return(qdo);
|
||||
}
|
||||
|
||||
@@ -764,9 +762,6 @@ bool Terminal::fromXml(QDomElement &terminal) {
|
||||
number_terminal_ = terminal.attribute("number");
|
||||
name_terminal_ = terminal.attribute("name");
|
||||
name_terminal_hidden = terminal.attribute("nameHidden").toInt();
|
||||
QString uuid = terminal.attribute("uuid");
|
||||
if (!uuid.isEmpty())
|
||||
m_uuid = uuid;
|
||||
|
||||
return (
|
||||
qFuzzyCompare(terminal.attribute("x").toDouble(), dock_elmt_.x()) &&
|
||||
@@ -797,6 +792,10 @@ Element *Terminal::parentElement() const {
|
||||
return(parent_element_);
|
||||
}
|
||||
|
||||
QUuid Terminal::uuid() const {
|
||||
return d->m_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Conductor::relatedPotentialTerminal
|
||||
* Return terminal at the same potential from the same
|
||||
|
||||
@@ -67,6 +67,7 @@ class Terminal : public QGraphicsObject
|
||||
int conductorsCount () const;
|
||||
Diagram *diagram () const;
|
||||
Element *parentElement () const;
|
||||
QUuid uuid () const;
|
||||
|
||||
QList<Conductor *> conductors() const;
|
||||
Qet::Orientation orientation() const;
|
||||
@@ -138,10 +139,6 @@ class Terminal : public QGraphicsObject
|
||||
/// Name of Terminal
|
||||
QString name_terminal_;
|
||||
bool name_terminal_hidden;
|
||||
|
||||
/// Unique identifier of the terminal
|
||||
/// This uuid is different to the uuid of the part terminal it represents
|
||||
QUuid m_uuid;
|
||||
|
||||
private:
|
||||
void init(QString number, QString name, bool hiddenName);
|
||||
|
||||
Reference in New Issue
Block a user