From 6775930e81cce345e883c1b4796f4d3b61e21ff8 Mon Sep 17 00:00:00 2001 From: joshua Date: Tue, 7 Sep 2021 22:23:43 +0200 Subject: [PATCH] Bug fix : in some condition element are not loaded when open a project If an element are overwrite by a modified element and the terminals of the modified element are moved, the old element is not loaded because some terminal are not found. This commit remove the checking of not found terminal because it's useless now. --- sources/qetgraphicsitem/element.cpp | 58 ++++++++++++----------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 6b3b46823..a33322224 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -736,50 +736,40 @@ bool Element::fromXml( } QHash priv_id_adr; - int terminals_non_trouvees = 0; - foreach(QGraphicsItem *qgi, childItems()) { - if (Terminal *p = qgraphicsitem_cast(qgi)) { - bool terminal_trouvee = false; - foreach(QDomElement qde, liste_terminals) { - if (p -> fromXml(qde)) { - priv_id_adr.insert( - qde.attribute( - "id").toInt(), - p); - terminal_trouvee = true; - // We used to break here, because we did not expect - // several terminals to share the same position. - // Of course, it finally happened. + + for (auto *qgi : childItems()) + { + if (auto terminal_ = qgraphicsitem_cast(qgi)) + { + for(auto qde : liste_terminals) + { + if (terminal_ -> fromXml(qde)) + { + priv_id_adr.insert(qde.attribute(QStringLiteral("id")).toInt(), + terminal_); } } - if (!terminal_trouvee) ++ terminals_non_trouvees; } } - if (terminals_non_trouvees > 0) + + //Check that associated id/adress doesn't conflict with table_id_adr + for(auto found_id : priv_id_adr.keys()) { - m_state = QET::GIOK; - return(false); - } - else - { - // verifie que les associations id / adr n'entrent pas en conflit avec table_id_adr - foreach(int id_trouve, priv_id_adr.keys()) + if (table_id_adr.contains(found_id)) { - if (table_id_adr.contains(id_trouve)) - { - // cet element possede un id qui est deja reference (= conflit) - m_state = QET::GIOK; - return(false); - } - } - // copie des associations id / adr - foreach(int id_trouve, priv_id_adr.keys()) { - table_id_adr.insert(id_trouve, - priv_id_adr.value(id_trouve)); + //This element got an id who is already referenced (= conflict) + m_state = QET::GIOK; + return(false); } } + //Copie the association id/adress + for(auto found_id : priv_id_adr.keys()) { + table_id_adr.insert(found_id, + priv_id_adr.value(found_id)); + } + //load uuid of connected elements QList uuid_list = QET::findInDomElement(e, "links_uuids",