mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-22 08:34:12 +02:00
Merge pull request #628 from ispyisail/feature-wiring-db-tables
Add terminal and conductor tables to projectDataBase (discussion #503, slice 2)
This commit is contained in:
@@ -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,18 @@ 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(QStringLiteral("uuid")));
|
||||
if (m_uuid.isNull()) {
|
||||
//Absent, empty or malformed: mint one. A null uuid is not a usable
|
||||
//identity -- every conductor carrying one would collide with every
|
||||
//other on the conductor table's primary key.
|
||||
m_uuid = QUuid::createUuid();
|
||||
}
|
||||
|
||||
setPos(dom_element.attribute("x", nullptr).toDouble(),
|
||||
dom_element.attribute("y", nullptr).toDouble());
|
||||
|
||||
@@ -1043,6 +1056,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()));
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../conductorproperties.h"
|
||||
|
||||
#include <QGraphicsPathItem>
|
||||
#include <QUuid>
|
||||
|
||||
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;
|
||||
|
||||
@@ -820,6 +820,60 @@ QUuid Terminal::uuid() const
|
||||
return d->m_uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Terminal::stableUuid
|
||||
An identity for this terminal that exists on every element, not only on
|
||||
those saved by a uuid-aware element editor.
|
||||
|
||||
uuid() comes from the catalog .elmt definition and is empty for every
|
||||
element authored before that field existed -- which is most of the
|
||||
installed base. Anything keyed on uuid() alone therefore cannot see those
|
||||
elements at all.
|
||||
|
||||
When there is no uuid, derive one from the terminal's local position and
|
||||
orientation inside its element. That is not an arbitrary choice: it is the
|
||||
same thing the project format itself uses to match a conductor back to a
|
||||
terminal ("each connection is made by using the local position of the
|
||||
terminal and a dynamic id" -- TerminalData::m_uuid). m_pos is the position
|
||||
read from the definition and is not touched by moving the element on the
|
||||
folio, so the result is stable across loads, saves and folio moves, and it
|
||||
is unique within an element except where a definition genuinely declares
|
||||
two terminals at the same point -- three cases in the whole example corpus,
|
||||
and harmless, because two terminals sharing a position and orientation are
|
||||
indistinguishable in every observable respect: they merge to one terminal
|
||||
row and every conductor on either of them still resolves to the right
|
||||
element and name.
|
||||
|
||||
Derived values are UUID v5 in a fixed namespace, so they are reproducible
|
||||
without being written to the file, and cannot collide with the v4 uuids
|
||||
the element editor generates.
|
||||
|
||||
@return the terminal's own uuid when it has one, otherwise a derived one
|
||||
*/
|
||||
QUuid Terminal::stableUuid() const
|
||||
{
|
||||
if (!d->m_uuid.isNull()) {
|
||||
return d->m_uuid;
|
||||
}
|
||||
|
||||
//Fixed namespace for terminal identities derived from geometry.
|
||||
static const QUuid derived_ns(QStringLiteral("{6b1f6d1e-6a1a-5f7e-9a3d-9c0a5b2d7e11}"));
|
||||
|
||||
//Position and orientation only. The name is deliberately excluded: it
|
||||
//is not stable across a save cycle -- QET rewrites a terminal named
|
||||
//"_" as unnamed, which would silently change the identity of 1421 of
|
||||
//industrial.qet's 1790 terminals on the first resave. It is also not
|
||||
//needed: keying on geometry alone produces exactly the same number of
|
||||
//collisions across the example corpus, and it means renaming a
|
||||
//terminal does not change what it is.
|
||||
const QString key = QStringLiteral("%1|%2|%3")
|
||||
.arg(d->m_pos.x(), 0, 'f', 4)
|
||||
.arg(d->m_pos.y(), 0, 'f', 4)
|
||||
.arg(static_cast<int>(d->m_orientation));
|
||||
|
||||
return QUuid::createUuidV5(derived_ns, key);
|
||||
}
|
||||
|
||||
QString Terminal::name() const
|
||||
{
|
||||
if (d->m_use_master_label && parent_element_) {
|
||||
|
||||
@@ -75,6 +75,7 @@ class Terminal : public QGraphicsObject
|
||||
Diagram *diagram () const;
|
||||
Element *parentElement () const;
|
||||
QUuid uuid () const;
|
||||
QUuid stableUuid () const;
|
||||
QString name () const;
|
||||
QString baseName () const;
|
||||
TerminalData::Type terminalType() const;
|
||||
|
||||
Reference in New Issue
Block a user