Give each copy of a symbol sharing a uuid its own uuid when a project opens

Older versions' copy and paste could leave two symbols with the same
uuid. Wires, links and the project database name a symbol by its uuid,
so a copy was ambiguous: #1417 worked around it for wires, but the
project database keeps one row per uuid, and a link to the uuid could
mean either copy.

When a project opens, every symbol carrying a uuid another symbol also
carries gets a uuid of its own, derived from the shared one and its
folio's uuid, so the same file gives the same result on every open. The
copy that keeps the shared uuid is the first one linked to another
symbol (its partner's link names that uuid), else the first. It is done
once the folio's wires are connected, so #1417's choice of which copy a
wire meets is kept. Folios holding such a copy are built when the
project opens, also with lazy folios.

Only files with shared uuids change, once: 3 of the 341 corpus projects.

tst_sharedsymboluuid: the lamps given one uuid now come back with three;
a linked contact and an unlinked symbol sharing its uuid keep every link
and wire, the linked one keeping the uuid. Both fail without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XCdg2Er2vYhB8Vwa5G7fSR
This commit is contained in:
ispyisail
2026-10-18 15:01:26 +13:00
parent abd1c8df2f
commit 1c0deb2bc8
4 changed files with 142 additions and 8 deletions
+17
View File
@@ -2342,6 +2342,23 @@ bool Diagram::fromXml(QDomElement &document,
<< "wire end(s) on a terminal that moved since the project was saved,"
<< "matched to it by place";
}
//A copy of a symbol sharing its uuid with another (older versions'
//copies, F100) gets its own, now that its wires are connected to
//it: wires and links then name one symbol each
//(QETProject::renewedSharedUuid(), only while the project opens)
if (consider_informations && m_project) {
const int folio_index = m_project->folioIndex(this);
QHash<QUuid, int> ordinal;
for (Element *element : std::as_const(added_elements)) {
const QUuid shared = element->uuid();
const QUuid renewed = m_project->renewedSharedUuid(folio_index, ordinal[shared]++,
shared, uuid());
if (!renewed.isNull()) {
element->setUuid(renewed);
}
}
}
if (consider_informations && !m_wires_not_reconnected.isEmpty()) {
qWarning().noquote() << "Diagram::fromXml():"
<< m_wires_not_reconnected.size()