From 96d84bf85293bec5c170fae1b720fab3927a3e22 Mon Sep 17 00:00:00 2001 From: achim Date: Sun, 3 Aug 2025 00:21:20 +0200 Subject: [PATCH] Better handling of conductors when creating from XML The position of a conductor is determined by the two terminals the conductor connects. Therefore, it makes no sense to set the position with 'setPos()'. It is better to first load all elements (but not the conductors), position them if necessary, and only then load the conductors and assign them to the elements (terminals). --- sources/diagram.cpp | 55 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 6ee509aa5..41996cf06 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -1438,33 +1438,6 @@ bool Diagram::fromXml(QDomElement &document, added_shapes << dii; } - // Load conductor - QList added_conductors; - for (auto f : QET::findInDomElement(root, - QStringLiteral("conductors"), - QStringLiteral("conductor"))) - { - if (!Conductor::valideXml(f)) continue; - - //Check if terminal that conductor must be linked is know - - Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements); - Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements); - - if (p1 && p2 && p1 != p2) - { - Conductor *c = new Conductor(p1, p2); - if (c->isValid()) - { - addItem(c); - c -> fromXml(f); - added_conductors << c; - } - else - delete c; - } - } - //Load tables QVector added_tables; for (const auto &dom_table : QETXML::subChild(root, @@ -1485,7 +1458,6 @@ bool Diagram::fromXml(QDomElement &document, { QVector added_items; for (auto element : qAsConst(added_elements )) added_items << element; - for (auto cond : qAsConst(added_conductors )) added_items << cond; for (auto shape : qAsConst(added_shapes )) added_items << shape; for (auto text : qAsConst(added_texts )) added_items << text; for (auto image : qAsConst(added_images )) added_items << image; @@ -1510,6 +1482,33 @@ bool Diagram::fromXml(QDomElement &document, qgi->setPos(qgi->pos() += pos_); } + // Load conductor + QList added_conductors; + for (auto f : QET::findInDomElement(root, + QStringLiteral("conductors"), + QStringLiteral("conductor"))) + { + if (!Conductor::valideXml(f)) continue; + + //Check if terminal that conductor must be linked is know + + Terminal* p1 = findTerminal(1, f, table_adr_id, added_elements); + Terminal* p2 = findTerminal(2, f, table_adr_id, added_elements); + + if (p1 && p2 && p1 != p2) + { + Conductor *c = new Conductor(p1, p2); + if (c->isValid()) + { + addItem(c); + c -> fromXml(f); + added_conductors << c; + } + else + delete c; + } + } + //Filling of falculatory lists if (content_ptr) { content_ptr -> m_elements = added_elements;