Fix a deleted symbol's joining wire getting a random uuid on every run

Deleting a symbol whose terminal held several wires joins the wires
left behind with a new one. That wire got a random uuid, so the same
deletion saved a different file every time: a diff for nothing in a
project kept in git (discussion #1512), and two copies with the same
edit could not be compared.

Its uuid now comes from its two ends (each end's symbol and terminal,
sorted), the recipe a wire saved without a uuid already gets on load
(Diagram::fromXml(), derivedItemUuid()). Undo and redo keep the same
wire, so its uuid too.

tst_joinedwireuuid deletes the coil KA1 of examples/affuteuse_250h.qet
in two runs: both saves are identical and no wire has a random uuid.
Without the fix one wire has a random uuid.

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 09:52:41 +13:00
parent 732017b015
commit f49abcc6cc
3 changed files with 132 additions and 0 deletions
@@ -259,6 +259,22 @@ void DeleteQGraphicsItemCommand::setPotentialsOfRemovedElements()
qInfo() << "m_connected_terminals" << m_connected_terminals;
Conductor *new_cond = new Conductor(new_pair.first, new_pair.second);
new_cond->setProperties(properties);
//The wire that joins the two left by the removed
//symbol gets its uuid from its two ends, as a wire
//saved without one does on load (Diagram::fromXml()):
//the same deletion then saves the same file every
//time, not a random uuid each run (F115)
if (QETProject *wire_project = new_pair.second->diagram()
? new_pair.second->diagram()->project() : nullptr) {
auto end = [](const Terminal *t) {
return t->parentElement()->uuid().toString()
+ QLatin1Char('/') + t->stableUuid().toString();
};
QStringList ends{end(new_pair.first), end(new_pair.second)};
ends.sort();
new_cond->setUuid(wire_project->derivedItemUuid(
QStringLiteral("conductor"), ends.join(QLatin1Char('\n'))));
}
new AddGraphicsObjectCommand(new_cond, new_pair.second->diagram(), QPointF(), this);
}
}