diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index 2922c32b1..763f1f987 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -75,6 +75,13 @@ void PasteDiagramCommand::redo() { first_redo = false; + //make new uuid for every pasted conductor, because old uuid are + //the uuid of the copied conductor + const QList all_pasted_conductors = content.conductors(); + for (Conductor *c : all_pasted_conductors) { + c -> newUuid(); + } + //this is the first paste, we do some actions for the new element const QList elmts_list = content.m_elements; for (Element *e : elmts_list) diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 291608620..546f64b3e 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -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& 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())); diff --git a/sources/qetgraphicsitem/conductor.h b/sources/qetgraphicsitem/conductor.h index dc4d5586b..91ca92afb 100644 --- a/sources/qetgraphicsitem/conductor.h +++ b/sources/qetgraphicsitem/conductor.h @@ -21,6 +21,7 @@ #include "../conductorproperties.h" #include +#include class ConductorProfile; class ConductorSegmentProfile; @@ -77,6 +78,8 @@ class Conductor : public QGraphicsObject int type() const override { return Type; } Diagram *diagram() const; ConductorTextItem *textItem() const; + QUuid uuid() const {return m_uuid;} + void newUuid() {m_uuid = QUuid::createUuid();} //create new uuid for this conductor void updatePath(const QRectF & = QRectF()); //This method do nothing, it's only made to be used with Q_PROPERTY @@ -205,6 +208,7 @@ class Conductor : public QGraphicsObject Highlight must_highlight_; bool m_valid; bool m_freeze_label = false; + QUuid m_uuid; /// QPen et QBrush objects used to draw conductors static QPen conductor_pen;