Give Conductor its own persisted uuid

Slice 1 of discussion #503 (from-to wiring list built on projectDataBase).

Conductor is the one item type on a diagram without a stable identity
of its own -- Element and Diagram both have a uuid, Conductor didn't.
This is the prerequisite the wiring-list tables need: a conductor
table keyed by uuid, the same way the existing element table is keyed
by Element::uuid().

- Conductor gets a QUuid m_uuid, generated in the constructor, with
  uuid()/newUuid() accessors mirroring Element's exact pattern.
- toXml()/fromXml() read/write a "uuid" attribute the same way
  Element already does, including the same generate-on-missing
  fallback (QUuid(e.attribute("uuid", QUuid::createUuid().toString())))
  for projects saved before this change.
- PasteDiagramCommand::redo() calls newUuid() on every pasted
  conductor (content.conductors(), all three categories), mirroring
  the existing per-element newUuid() call right above it -- otherwise
  copy-paste would duplicate a conductor's uuid.

Backward compatibility: Conductor::valideXml() doesn't require the
"uuid" attribute, so old files parse unchanged. Verified by opening a
genuinely pre-uuid project (examples/industrial.qet, 150 folios, 671
conductors, legacy integer terminal1/terminal2 references with no
uuid attribute at all) -- loads and renders correctly, gets uuids
assigned on load, and those uuids are stable across a second
load/save cycle (byte-identical uuid values). Verified paste
separately: copying a selection with conductors and pasting produces
distinct new uuids for every pasted conductor, none colliding with
the originals or each other.
This commit is contained in:
ispyisail
2026-08-02 08:12:22 +12:00
parent c1694f2b4f
commit a3511e8694
3 changed files with 19 additions and 0 deletions
+8
View File
@@ -91,6 +91,7 @@ Conductor::Conductor(Terminal *p1, Terminal* p2) :
//set Zvalue at 11 to be upper than the DiagramImageItem and element
setZValue(11);
m_previous_z_value = zValue();
m_uuid = QUuid::createUuid();
//Add this conductor to the list of conductors of each of the two terminals
bool ajout_p1 = terminal1 -> addConductor(this);
@@ -1005,6 +1006,12 @@ void Conductor::pointsToSegments(const QList<QPointF>& points_list) {
*/
bool Conductor::fromXml(QDomElement &dom_element)
{
//Older project files have no conductor uuid attribute at all --
//generate one on load, same treatment terminal uuids got when
//that field was introduced (see terminal1/terminal2 handling in
//toXml() below).
m_uuid = QUuid(dom_element.attribute("uuid", QUuid::createUuid().toString()));
setPos(dom_element.attribute("x", nullptr).toDouble(),
dom_element.attribute("y", nullptr).toDouble());
@@ -1043,6 +1050,7 @@ QDomElement Conductor::toXml(QDomDocument &dom_document,
{
QDomElement dom_element = dom_document.createElement("conductor");
dom_element.setAttribute("uuid", m_uuid.toString());
dom_element.setAttribute("x", QString::number(pos().x()));
dom_element.setAttribute("y", QString::number(pos().y()));