Revert pull request #48

This commit is contained in:
Laurent Trinques
2020-06-14 07:35:52 +02:00
parent c9a7c836c5
commit 22e619d6b9
13 changed files with 171 additions and 428 deletions

View File

@@ -34,8 +34,8 @@ class PropertiesInterface
virtual void toSettings (QSettings &settings, const QString = QString()) const =0;
virtual void fromSettings (const QSettings &settings, const QString = QString()) =0;
// Save/load properties to xml element
virtual QDomElement toXml (QDomDocument &xml_document) const =0;
virtual bool fromXml (const QDomElement &xml_element) =0;
virtual void toXml (QDomElement &xml_element) const =0;
virtual void fromXml (const QDomElement &xml_element) =0;
};
#endif // PROPERTIESINTERFACE_H

View File

@@ -1,86 +0,0 @@
#include "terminaldata.h"
#include <QGraphicsObject>
TerminalData::TerminalData():
PropertiesInterface()
{
init();
}
TerminalData::TerminalData(QGraphicsObject *parent):
PropertiesInterface(),
q(parent)
{
init();
}
void TerminalData::init() {
}
TerminalData::~TerminalData()
{
}
void TerminalData::setParent(QGraphicsObject* parent)
{
q = parent;
}
void TerminalData::toSettings(QSettings &settings, const QString) const
{
}
void TerminalData::fromSettings(const QSettings &settings, const QString)
{
}
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
{
QDomElement xml_element = xml_document.createElement("terminal");
// ecrit la position de la borne
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
xml_element.setAttribute("uuid", m_uuid.toString());
xml_element.setAttribute("name", m_name);
// ecrit l'orientation de la borne
xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation));
// Write name and number to XML
return(xml_element);
}
bool TerminalData::fromXml (const QDomElement &xml_element)
{
// lit la position de la borne
qreal term_x = 0.0, term_y = 0.0;
if (!QET::attributeIsAReal(xml_element, "x", &term_x))
return false;
if (!QET::attributeIsAReal(xml_element, "y", &term_y))
return false;
m_pos = QPointF(term_x, term_y);
//emit posFromXML(QPointF(term_x, term_y));
QString uuid = xml_element.attribute("uuid");
// update part and add uuid, which is used in the new version to connect terminals together
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
// to identify terminals
if (!uuid.isEmpty())
m_uuid = QUuid(uuid);
m_name = xml_element.attribute("name");
// lit l'orientation de la borne
m_orientation = Qet::orientationFromString(xml_element.attribute("orientation"));
return true;
}

View File

@@ -1,77 +0,0 @@
#ifndef TERMINALDATA_H
#define TERMINALDATA_H
#include "propertiesinterface.h"
#include "qet.h"
#include <QUuid>
#include <QPointF>
class QGraphicsObject;
/*!
* \brief The TerminalData class
* Data of the terminal. Stored in extra class so it can be used by PartTerminal and Terminal without
* defining everything again.
*/
class TerminalData : public PropertiesInterface
{
public:
TerminalData();
TerminalData(QGraphicsObject* parent);
~TerminalData();
void init();
void setParent(QGraphicsObject* parent);
// Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre
void toSettings(QSettings &settings, const QString = QString()) const override;
void fromSettings(const QSettings &settings, const QString = QString()) override;
// Save/load properties to xml element
// This method is only called from the PartTerminal and should never called from the Terminal class
QDomElement toXml(QDomDocument &xml_element) const override;
bool fromXml(const QDomElement &xml_element) override;
// must be public, because this class is a private member of PartTerminal/Terminal and they must
// access this data
public:
/*!
* \brief m_orientation
* Orientation of the terminal
*/
Qet::Orientation m_orientation;
/*!
* \brief second_point
* Position of the second point of the terminal in scene coordinates
*/
QPointF second_point;
/*!
* \brief m_uuid
* Uuid of the terminal.
*
* In elementscene.cpp an element gets a new uuid when saving the element. In the current state
* each connection is made by using the local position of the terminal and a dynamic id. In the new
* case, each terminal should have it's own uuid to identify it uniquely. When changing each time this
* uuid, the conductor after updating the part is anymore valid. So if in the loaded document a uuid exists,
* use this one and don't create a new one.
*/
QUuid m_uuid;
/*!
* \brief m_name
* Name of the element. It can be used to create wiring harness tables
*/
QString m_name;
/*!
* \brief m_pos
* Position of the terminal. The second point is calculated from this position and the orientation
* Important: this variable is only updated during read from xml and not during mouse move!
* It is used to store the initial position so that PartTerminal and Terminal have access to it.
*/
QPointF m_pos;
private:
QGraphicsObject* q{nullptr};
};
#endif // TERMINALDATA_H

View File

@@ -93,12 +93,8 @@ void XRefProperties::fromSettings(const QSettings &settings, const QString prefi
* Save to xml
* @param xml_element: QDomElement to use for saving
*/
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
QDomElement xml_element = xml_document.createElement("xref");
xml_element.setAttribute("type", m_key);
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
void XRefProperties::toXml(QDomElement &xml_element) const {
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "false");
QString display = m_display == Cross? "cross" : "contacts";
xml_element.setAttribute("displayhas", display);
QString snap = m_snap_to == Bottom? "bottom" : "label";
@@ -118,8 +114,6 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
foreach (QString key, m_prefix.keys()) {
xml_element.setAttribute(key + "prefix", m_prefix.value(key));
}
return xml_element;
}
/**
@@ -127,7 +121,7 @@ QDomElement XRefProperties::toXml(QDomDocument &xml_document) const {
* Load from xml
* @param xml_element: QDomElement to use for load
*/
bool XRefProperties::fromXml(const QDomElement &xml_element) {
void XRefProperties::fromXml(const QDomElement &xml_element) {
m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
QString display = xml_element.attribute("displayhas", "cross");
display == "cross"? m_display = Cross : m_display = Contacts;
@@ -149,7 +143,6 @@ bool XRefProperties::fromXml(const QDomElement &xml_element) {
foreach (QString key, m_prefix_keys) {
m_prefix.insert(key, xml_element.attribute(key + "prefix"));
}
return true;
}
/**

View File

@@ -42,8 +42,8 @@ class XRefProperties : public PropertiesInterface
void toSettings (QSettings &settings, const QString = QString()) const override;
void fromSettings (const QSettings &settings, const QString = QString()) override;
QDomElement toXml (QDomDocument &xml_document) const override;
bool fromXml(const QDomElement &xml_element) override;
void toXml (QDomElement &xml_element) const override;
void fromXml (const QDomElement &xml_element) override;
static QHash<QString, XRefProperties> defaultProperties();
@@ -73,8 +73,6 @@ class XRefProperties : public PropertiesInterface
void setOffset(const int offset) {m_offset = offset;}
int offset() const {return m_offset;}
void setKey(QString& key) {m_key = key;}
private:
bool m_show_power_ctc;
DisplayHas m_display;
@@ -85,7 +83,6 @@ class XRefProperties : public PropertiesInterface
QString m_master_label;
QString m_slave_label;
int m_offset;
QString m_key;
};
#endif // XREFPROPERTIES_H