mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-30 23:04:13 +02:00
Give wires saved without a uuid a lasting one, from what they connect
A wire saved without a uuid got a random one on every load, never saved (#754): it had no identity from one session to the next, so a script could only name it as "the wire on terminal N of symbol X", and a comparison of two versions could not tell a moved wire from a new one. When a folio is loaded, such a wire now gets a UUID v5 derived from its two ends -- the symbol and terminal at each, sorted so the direction it was drawn in does not matter -- and it is written on save. Never its place in the file or its folio's index: inserting or moving a folio, or saving the wires in another order, does not change it. Once saved the uuid no longer depends on the ends, so re-connecting the wire keeps it; QETProject::derivedItemUuid() never hands out a uuid the file already carries, so a wire later drawn on the ends it left gets another one. Wires that have a uuid keep it; a paste still renews them. The 24 example projects: 3,189 wires, none with a uuid before, all 3,189 after one save, none lost, no uuid used twice in any project; two saves of the same file are identical, and a second save keeps every wire's uuid. Discussion #1103 has the measurements behind the recipe. tst_derivedwireuuid runs --resave on a fixture naming ends by uuid and on examples/tremie_vibrante.qet (ends by terminal number): every wire gets a distinct uuid, the same on every load, read back after a save, kept per wire when a folio is inserted, the wires are reordered or a wire is drawn the other way, and a newcomer on a re-connected wire's old ends gets another uuid. Without this change 14 of the 18 fail; with the uuid taken from folio index and file order instead, the folio-insert and reorder tests fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1825,6 +1825,28 @@ bool Diagram::fromXml(QDomElement &document,
|
||||
{
|
||||
addItem(c);
|
||||
c -> fromXml(f);
|
||||
//A wire saved without a uuid got a random one that was
|
||||
//never saved (#754), so it had no identity from one
|
||||
//session to the next. Derive it from what it connects:
|
||||
//the symbol and terminal at each end, sorted so the
|
||||
//direction it was drawn in does not matter. Never its
|
||||
//place in the file or its folio's index, so inserting or
|
||||
//moving a folio, or saving the wires in another order,
|
||||
//does not change it. It is saved from now on, so
|
||||
//re-connecting the wire later keeps it; derivedItemUuid()
|
||||
//never hands out a uuid the file already carries, so a
|
||||
//wire later drawn on the ends it left gets another one.
|
||||
if (consider_informations && m_project
|
||||
&& QUuid(f.attribute(QStringLiteral("uuid"))).isNull()) {
|
||||
auto end = [](const Terminal *t) {
|
||||
return t->parentElement()->uuid().toString()
|
||||
+ QLatin1Char('/') + t->stableUuid().toString();
|
||||
};
|
||||
QStringList ends{end(p1), end(p2)};
|
||||
ends.sort();
|
||||
c->setUuid(m_project->derivedItemUuid(QStringLiteral("conductor"),
|
||||
ends.join(QLatin1Char('\n'))));
|
||||
}
|
||||
added_conductors << c;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user