2020-05-25 22:17:17 +02:00
|
|
|
#include "terminaldata.h"
|
|
|
|
|
|
|
|
#include <QGraphicsObject>
|
|
|
|
|
|
|
|
TerminalData::TerminalData():
|
|
|
|
PropertiesInterface()
|
|
|
|
{
|
2020-05-26 18:47:24 +02:00
|
|
|
init();
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TerminalData::TerminalData(QGraphicsObject *parent):
|
|
|
|
PropertiesInterface(),
|
|
|
|
q(parent)
|
|
|
|
{
|
2020-05-26 18:47:24 +02:00
|
|
|
init();
|
|
|
|
}
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-05-26 18:47:24 +02:00
|
|
|
void TerminalData::init() {
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TerminalData::~TerminalData()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerminalData::setParent(QGraphicsObject* parent)
|
|
|
|
{
|
|
|
|
q = parent;
|
|
|
|
}
|
|
|
|
|
2020-08-25 20:14:38 +02:00
|
|
|
void TerminalData::toSettings(QSettings& settings, const QString&) const
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-06-20 21:22:41 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(settings);
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 20:14:38 +02:00
|
|
|
void TerminalData::fromSettings(const QSettings& settings, const QString&)
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
2020-06-20 21:22:41 +02:00
|
|
|
Q_UNUSED(settings);
|
2020-05-25 22:17:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
|
|
|
{
|
2020-10-01 14:38:08 +02:00
|
|
|
QDomElement xml_element = xml_document.createElement("terminaldata");
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-08-13 23:27:11 +02:00
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "x", q->scenePos().x()));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "y", q->scenePos().y()));
|
2020-09-14 21:21:32 +02:00
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "uuid", m_uuid));
|
2020-08-13 23:27:11 +02:00
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "name", m_name));
|
|
|
|
xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation)));
|
2020-05-25 22:17:17 +02:00
|
|
|
|
|
|
|
return(xml_element);
|
|
|
|
}
|
2020-09-14 21:21:32 +02:00
|
|
|
bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True
|
2020-05-25 22:17:17 +02:00
|
|
|
{
|
|
|
|
// lit la position de la borne
|
|
|
|
qreal term_x = 0.0, term_y = 0.0;
|
2020-08-13 23:27:11 +02:00
|
|
|
|
2020-09-14 21:21:32 +02:00
|
|
|
if (propertyDouble(xml_element, "x", &term_x))
|
2020-05-25 22:17:17 +02:00
|
|
|
return false;
|
|
|
|
|
2020-09-14 21:21:32 +02:00
|
|
|
if (propertyDouble(xml_element, "y", &term_y))
|
2020-05-25 22:17:17 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
m_pos = QPointF(term_x, term_y);
|
|
|
|
|
2020-10-01 14:38:08 +02:00
|
|
|
// emit posFromXML(QPointF(term_x, term_y));
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-09-14 21:21:32 +02:00
|
|
|
QUuid uuid;
|
2020-05-25 22:17:17 +02:00
|
|
|
// update part and add uuid, which is used in the new version to connect terminals together
|
2020-05-26 18:47:24 +02:00
|
|
|
// if the attribute not exists, means, the element is created with an older version of qet. So use the legacy approach
|
|
|
|
// to identify terminals
|
2020-09-14 21:21:32 +02:00
|
|
|
if (propertyUuid(xml_element, "uuid", &uuid) == PropertyFlags::Success)
|
2020-05-25 22:17:17 +02:00
|
|
|
m_uuid = QUuid(uuid);
|
|
|
|
|
2020-09-14 21:21:32 +02:00
|
|
|
|
|
|
|
//if (propertyString(xml_element, "name", &m_name))
|
|
|
|
// return false;
|
|
|
|
propertyString(xml_element, "name", &m_name); // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
|
2020-08-13 23:27:11 +02:00
|
|
|
|
|
|
|
QString o;
|
2020-09-14 21:21:32 +02:00
|
|
|
if (propertyString(xml_element, "orientation", &o))
|
2020-08-13 23:27:11 +02:00
|
|
|
return false;
|
2020-05-25 22:17:17 +02:00
|
|
|
|
|
|
|
// lit l'orientation de la borne
|
2020-08-13 23:27:11 +02:00
|
|
|
m_orientation = orientationFromString(o);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-25 22:17:17 +02:00
|
|
|
|
2020-09-14 21:21:32 +02:00
|
|
|
bool TerminalData::valideXml(const QDomElement& xml_element) {
|
2020-08-25 20:14:38 +02:00
|
|
|
if (propertyDouble(xml_element, "x"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (propertyDouble(xml_element, "y"))
|
|
|
|
return false;
|
|
|
|
|
2020-09-14 21:21:32 +02:00
|
|
|
// legacy elements do not have an uuid
|
|
|
|
// if (propertyUuid(xml_element, "uuid"))
|
|
|
|
// return false;
|
2020-08-25 20:14:38 +02:00
|
|
|
|
2020-09-14 21:21:32 +02:00
|
|
|
//if (propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
|
|
|
|
// return false;
|
2020-08-25 20:14:38 +02:00
|
|
|
|
|
|
|
if (propertyString(xml_element, "orientation"))
|
|
|
|
return false;
|
2020-05-25 22:17:17 +02:00
|
|
|
return true;
|
|
|
|
}
|