mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-30 15:50:52 +01:00
TEST a Merge branch 'XMLProperties'
it gets built let's test it for bugs Conflicts: sources/ElementsCollection/fileelementcollectionitem.cpp sources/QetGraphicsItemModeler/qetgraphicshandleritem.h sources/borderproperties.cpp sources/conductorproperties.cpp sources/conductorproperties.h sources/diagram.cpp sources/diagram.h sources/diagramprintdialog.cpp sources/diagramprintdialog.h sources/editor/graphicspart/customelementgraphicpart.cpp sources/editor/graphicspart/partarc.cpp sources/editor/graphicspart/partdynamictextfield.cpp sources/editor/graphicspart/partdynamictextfield.h sources/editor/graphicspart/partellipse.cpp sources/editor/graphicspart/partline.cpp sources/editor/graphicspart/partpolygon.cpp sources/editor/graphicspart/partrectangle.cpp sources/editor/graphicspart/partterminal.cpp sources/editor/graphicspart/partterminal.h sources/editor/graphicspart/parttext.cpp sources/properties/propertiesinterface.cpp sources/properties/propertiesinterface.h sources/properties/terminaldata.cpp sources/properties/terminaldata.h sources/properties/xrefproperties.cpp sources/properties/xrefproperties.h sources/qetgraphicsitem/conductor.cpp sources/qetgraphicsitem/conductor.h sources/qetgraphicsitem/conductortextitem.h sources/qetgraphicsitem/dynamicelementtextitem.h sources/qetgraphicsitem/element.cpp sources/qetgraphicsitem/element.h sources/qetgraphicsitem/elementtextitemgroup.h sources/qetgraphicsitem/slaveelement.cpp sources/qetgraphicsitem/slaveelement.h sources/qetgraphicsitem/terminal.cpp sources/qetgraphicsitem/terminal.h sources/qetproject.cpp sources/titleblockproperties.cpp
This commit is contained in:
@@ -17,16 +17,313 @@
|
||||
*/
|
||||
#include "propertiesinterface.h"
|
||||
|
||||
/**
|
||||
@brief PropertiesInterface::PropertiesInterface
|
||||
*/
|
||||
#include <QDebug>
|
||||
|
||||
/*!
|
||||
* Available property types
|
||||
*/
|
||||
namespace {
|
||||
const QString integerS = "int";
|
||||
const QString doubleS = "double";
|
||||
const QString boolS = "bool";
|
||||
const QString stringS = "string";
|
||||
const QString uuidS = "uuid";
|
||||
const QString colorS = "color";
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertiesInterface()
|
||||
{
|
||||
}
|
||||
/**
|
||||
@brief PropertiesInterface::~PropertiesInterface
|
||||
*/
|
||||
PropertiesInterface::~PropertiesInterface()
|
||||
{
|
||||
|
||||
bool PropertiesInterface::valideXml(QDomElement& element) {
|
||||
qDebug(QString("ValideXml() is not implemented. File: %1, Line: %2").arg(__FILE__).arg(__LINE__).toStdString().data());
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const QString value) {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", stringS);
|
||||
p.setAttribute("value", value);
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument &doc, const QString& name, const char* value) {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", stringS);
|
||||
p.setAttribute("value", value);
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const int value) {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", integerS);
|
||||
p.setAttribute("value", QString::number(value));
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const double value) {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", doubleS);
|
||||
p.setAttribute("value", QString::number(value));
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const bool value) {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", boolS);
|
||||
p.setAttribute("value", QString::number(value));
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", uuidS);
|
||||
p.setAttribute("value", value.toString());
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", colorS);
|
||||
p.setAttribute("value", value.name());
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::property(const QDomElement& e, const QString& name) {
|
||||
for (int i=0; i < e.childNodes().count(); i++) {
|
||||
QDomElement child = e.childNodes().at(i).toElement();
|
||||
if (!validXmlProperty(child))
|
||||
continue; // there might also non property childs
|
||||
|
||||
if (child.attribute("name") == name)
|
||||
return child;
|
||||
}
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PropertiesInterface::attribute
|
||||
* Returns the property with the name \p attribute_name and type \p type
|
||||
* \param e Xml element which contains the property
|
||||
* \param attribute_name
|
||||
* \param type Type of the property
|
||||
* \param attr
|
||||
* \return
|
||||
*/
|
||||
bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr) {
|
||||
QDomElement p = property(e, attribute_name);
|
||||
if (p.isNull()) {
|
||||
// check if legacy property is available,
|
||||
// where the property is inside the element as attribute
|
||||
if (!e.hasAttribute(attribute_name)) {
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "Property " << attribute_name << "is not available";
|
||||
return false;
|
||||
}
|
||||
|
||||
*attr = e.attribute(attribute_name);
|
||||
|
||||
} else {
|
||||
if (p.attribute("type") != type) {
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ", Property: " << attribute_name << "(" << p.attribute("type") << ") has not type: " << type;
|
||||
return false;
|
||||
}
|
||||
|
||||
*attr = p.attribute("value");
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PropertiesInterface::propertyInteger
|
||||
* Reads an interger from the XML element.
|
||||
* \param e DomElement which contains the property attribute
|
||||
* \param attribute_name Name of the attribute
|
||||
* \param entier Return value if success
|
||||
* \return True if reading an integer was successful, else False. If the attribute was not found,
|
||||
* \p entier is not valid and the return value is False
|
||||
*/
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QDomElement &e, const QString& attribute_name, int* entier) {
|
||||
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, integerS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
// verifie la validite de l'attribut
|
||||
bool ok;
|
||||
int tmp = attr.toInt(&ok);
|
||||
if (!ok) {
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
if (entier != nullptr)
|
||||
*entier = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) {
|
||||
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, doubleS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
// verifie la validite de l'attribut
|
||||
bool ok;
|
||||
double tmp = attr.toDouble(&ok);
|
||||
if (!ok) {
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << doubleS << ". value: " << attr;
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
if (reel != nullptr)
|
||||
*reel = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) {
|
||||
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, boolS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
// verifie la validite de l'attribut
|
||||
bool ok;
|
||||
bool tmp = attr.toInt(&ok);
|
||||
if (!ok) {
|
||||
if (attr == "true" || attr == "1")
|
||||
tmp = true;
|
||||
else if (attr == "false" || attr == "0")
|
||||
tmp = false;
|
||||
else {
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << integerS << ". value: " << attr;
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
}
|
||||
|
||||
if (boolean != nullptr)
|
||||
*boolean = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) {
|
||||
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, colorS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
// verifie la validite de l'attribut
|
||||
QColor tmp = QColor(attr);
|
||||
if (!tmp.isValid()) {
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << colorS << ". value: " << attr;
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
if (color != nullptr)
|
||||
*color = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) {
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, uuidS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
if (QUuid(attr).isNull()){
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << uuidS << ". value: " << attr;
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
|
||||
if (uuid != nullptr)
|
||||
*uuid = QUuid(attr);
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string) {
|
||||
|
||||
QString attr;
|
||||
if (!attribute(e, attribute_name, stringS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
// verifie la validite de l'attribut
|
||||
if (string != nullptr)
|
||||
*string = attr;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PropertiesInterface::validXmlProperty
|
||||
* Check if the Xml element contains the needed fields
|
||||
* \param e Xml Property
|
||||
* \return True if name, type, value attribute are available, else false
|
||||
*/
|
||||
bool PropertiesInterface::validXmlProperty(const QDomElement& e) {
|
||||
if (!e.hasAttribute("name"))
|
||||
return false;
|
||||
|
||||
if (!e.hasAttribute("type"))
|
||||
return false;
|
||||
|
||||
if (!e.hasAttribute("value"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w")
|
||||
en orientation. Si la chaine fait plusieurs caracteres, seul le
|
||||
premier est pris en compte. En cas d'incoherence, Qet::North est
|
||||
retourne.
|
||||
@param s Chaine de caractere cense representer une orientation
|
||||
@return l'orientation designee par la chaine de caractere
|
||||
*/
|
||||
Qet::Orientation PropertiesInterface::orientationFromString(const QString &s) {
|
||||
QChar c = s[0];
|
||||
// in some cases/ old projects? (affuteuse_250h.qet) numbers instead of characters are
|
||||
// used for the orientation
|
||||
if (c == 'e' || c == '1') return(Qet::East);
|
||||
else if (c == 's' || c == '2') return(Qet::South);
|
||||
else if (c == 'w' || c == '3') return (Qet::West);
|
||||
else return(Qet::North); // c == '0'
|
||||
}
|
||||
|
||||
/**
|
||||
@param o une orientation
|
||||
@return une chaine de caractere representant l'orientation
|
||||
*/
|
||||
QString PropertiesInterface::orientationToString(Qet::Orientation o) {
|
||||
QString ret;
|
||||
switch(o) {
|
||||
case Qet::North: ret = "n"; break;
|
||||
case Qet::East : ret = "e"; break;
|
||||
case Qet::South: ret = "s"; break;
|
||||
case Qet::West : ret = "w"; break;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
#include <QColor>
|
||||
#include <QDomElement>
|
||||
#include <limits>
|
||||
#include "qet.h"
|
||||
#include <QUuid>
|
||||
|
||||
/**
|
||||
@brief The PropertiesInterface class
|
||||
@@ -30,40 +34,66 @@
|
||||
class PropertiesInterface
|
||||
{
|
||||
public:
|
||||
PropertiesInterface();
|
||||
virtual ~PropertiesInterface();
|
||||
/**
|
||||
@brief toSettings
|
||||
Save properties to setting file.
|
||||
@param settings : is use for prefix a word
|
||||
befor the name of each paramètre
|
||||
@param QString
|
||||
*/
|
||||
virtual void toSettings (QSettings &settings,
|
||||
const QString = QString()) const =0;
|
||||
/**
|
||||
@brief fromSettings
|
||||
load properties to setting file.
|
||||
@param settings : is use for prefix a word
|
||||
befor the name of each paramètre
|
||||
@param QString
|
||||
*/
|
||||
virtual void fromSettings (const QSettings &settings,
|
||||
const QString = QString()) =0;
|
||||
/**
|
||||
@brief toXml
|
||||
Save properties to xml element
|
||||
@param xml_document
|
||||
@return QDomElement
|
||||
*/
|
||||
virtual QDomElement toXml (QDomDocument &xml_document) const =0;
|
||||
/**
|
||||
@brief fromXml
|
||||
load properties to xml element
|
||||
@param xml_element
|
||||
@return true / false
|
||||
*/
|
||||
virtual bool fromXml (const QDomElement &xml_element) =0;
|
||||
PropertiesInterface();
|
||||
// Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre
|
||||
virtual void toSettings (QSettings &settings, const QString& = QString()) const {Q_UNUSED(settings)};
|
||||
virtual void fromSettings (const QSettings &settings, const QString& = QString()) {Q_UNUSED(settings)};
|
||||
// Save/load properties to xml element
|
||||
virtual QDomElement toXml (QDomDocument &xml_document) const =0;
|
||||
virtual bool fromXml (const QDomElement &xml_element) =0;
|
||||
static bool valideXml(QDomElement& element);
|
||||
|
||||
/*!
|
||||
* Use this functions to add properties to the xml document
|
||||
*/
|
||||
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QString value);
|
||||
static QDomElement createXmlProperty(QDomDocument &doc, const QString& name, const char* value);
|
||||
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value);
|
||||
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value);
|
||||
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value);
|
||||
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value);
|
||||
static QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QColor value);
|
||||
|
||||
static QDomElement property(const QDomElement& e, const QString& name);
|
||||
static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr);
|
||||
|
||||
enum PropertyFlags {
|
||||
Success = 0,
|
||||
NotFound = 1,
|
||||
NoValidConversion = 2,
|
||||
// = 4
|
||||
};
|
||||
|
||||
/*!
|
||||
* Try not using the default Value feature. It is better to initialize the class members in the class definition!
|
||||
*/
|
||||
static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr);
|
||||
static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr);
|
||||
static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr);
|
||||
static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr);
|
||||
static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr);
|
||||
static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr);
|
||||
|
||||
|
||||
static bool validXmlProperty(const QDomElement& e);
|
||||
|
||||
QVariant XmlProperty(const QDomElement& element);
|
||||
|
||||
/**
|
||||
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w")
|
||||
en orientation. Si la chaine fait plusieurs caracteres, seul le
|
||||
premier est pris en compte. En cas d'incoherence, Qet::North est
|
||||
retourne.
|
||||
@param s Chaine de caractere cense representer une orientation
|
||||
@return l'orientation designee par la chaine de caractere
|
||||
*/
|
||||
static Qet::Orientation orientationFromString(const QString &s);
|
||||
|
||||
/**
|
||||
@param o une orientation
|
||||
@return une chaine de caractere representant l'orientation
|
||||
*/
|
||||
static QString orientationToString(Qet::Orientation o);
|
||||
};
|
||||
|
||||
#endif // PROPERTIESINTERFACE_H
|
||||
|
||||
@@ -33,33 +33,15 @@ void TerminalData::setParent(QGraphicsObject* parent)
|
||||
q = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::toSettings
|
||||
Save properties to setting file.
|
||||
|
||||
QString is use for prefix a word befor the name of each paramètre
|
||||
@param settings UNUSED
|
||||
@param prefix UNUSED
|
||||
*/
|
||||
void TerminalData::toSettings(QSettings &settings, const QString prefix) const
|
||||
void TerminalData::toSettings(QSettings& settings, const QString&) const
|
||||
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
Q_UNUSED(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::fromSettings
|
||||
load properties to setting file.
|
||||
|
||||
QString is use for prefix a word befor the name of each paramètre
|
||||
@param settings UNUSED
|
||||
@param prefix UNUSED
|
||||
*/
|
||||
void TerminalData::fromSettings(const QSettings &settings, const QString prefix)
|
||||
void TerminalData::fromSettings(const QSettings& settings, const QString&)
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
Q_UNUSED(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,66 +58,68 @@ void TerminalData::fromSettings(const QSettings &settings, const QString prefix)
|
||||
*/
|
||||
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("terminal");
|
||||
QDomElement xml_element = xml_document.createElement("terminaldata");
|
||||
|
||||
// write the position of the 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()));
|
||||
|
||||
// Write name and number to XML
|
||||
xml_element.setAttribute("uuid", m_uuid.toString());
|
||||
xml_element.setAttribute("name", m_name);
|
||||
|
||||
// write the orientation of the terminal
|
||||
// ecrit l'orientation de la borne
|
||||
xml_element.setAttribute("orientation",
|
||||
Qet::orientationToString(m_orientation));
|
||||
// m_pos cannot be stored, because in the partterminal it will not be updated.
|
||||
// In PartTerminal m_pos is the position of the dock, in Terminal m_pos is the second side of the terminal
|
||||
// This is hold for legacy compability reason
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "x", m_pos.x()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "y", m_pos.y()));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "name", m_name));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "orientation", orientationToString(m_orientation)));
|
||||
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::fromXml
|
||||
load properties to xml element
|
||||
|
||||
@note This method is only called from the PartTerminal
|
||||
and should never called from the Terminal class
|
||||
@param xml_element
|
||||
@return true if succeeded / false if the attribute is not real
|
||||
*/
|
||||
bool TerminalData::fromXml (const QDomElement &xml_element)
|
||||
bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True
|
||||
{
|
||||
qreal term_x = 0.0;
|
||||
qreal term_y = 0.0;
|
||||
|
||||
// reads the position of the terminal
|
||||
// lit la position de la borne
|
||||
if (!QET::attributeIsAReal(xml_element, "x", &term_x))
|
||||
qreal term_x = 0.0, term_y = 0.0;
|
||||
|
||||
if (propertyDouble(xml_element, "x", &term_x))
|
||||
return false;
|
||||
|
||||
if (!QET::attributeIsAReal(xml_element, "y", &term_y))
|
||||
if (propertyDouble(xml_element, "y", &term_y))
|
||||
return false;
|
||||
|
||||
m_pos = QPointF(term_x, term_y);
|
||||
|
||||
//emit posFromXML(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);
|
||||
// do not write uuid from this class, because only PartTerminal::fromXml need
|
||||
// to write it to xml file. Terminal::fromXml does not need.
|
||||
|
||||
m_name = xml_element.attribute("name");
|
||||
|
||||
// read the orientation of the terminal
|
||||
//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"
|
||||
|
||||
QString o;
|
||||
if (propertyString(xml_element, "orientation", &o))
|
||||
return false;
|
||||
|
||||
// lit l'orientation de la borne
|
||||
m_orientation = Qet::orientationFromString(
|
||||
xml_element.attribute("orientation"));
|
||||
m_orientation = orientationFromString(o);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TerminalData::valideXml(const QDomElement& xml_element) {
|
||||
if (propertyDouble(xml_element, "x"))
|
||||
return false;
|
||||
|
||||
if (propertyDouble(xml_element, "y"))
|
||||
return false;
|
||||
|
||||
// legacy elements do not have an uuid
|
||||
// if (propertyUuid(xml_element, "uuid"))
|
||||
// return false;
|
||||
|
||||
//if (propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
|
||||
// return false;
|
||||
|
||||
if (propertyString(xml_element, "orientation"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,62 +26,58 @@ class TerminalData : public PropertiesInterface
|
||||
void init();
|
||||
|
||||
void setParent(QGraphicsObject* parent);
|
||||
void toSettings(QSettings &settings,
|
||||
const QString prefix = QString()) const override;
|
||||
void fromSettings(const QSettings &settings,
|
||||
const QString prefix = QString()) override;
|
||||
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.
|
||||
// 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;
|
||||
|
||||
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;
|
||||
static bool valideXml(const QDomElement &xml_element);
|
||||
|
||||
/**
|
||||
@brief m_pos
|
||||
Position of the terminal. The second point is calculated
|
||||
from this position and the orientation
|
||||
@note
|
||||
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};
|
||||
// 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{Qet::Orientation::North};
|
||||
/*!
|
||||
* \brief second_point
|
||||
* Position of the second point of the terminal in scene coordinates
|
||||
*/
|
||||
QPointF second_point{0,0};
|
||||
/*!
|
||||
* \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; // default is an invalid 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{0,0};
|
||||
private:
|
||||
QGraphicsObject* q{nullptr};
|
||||
};
|
||||
|
||||
#endif // TERMINALDATA_H
|
||||
|
||||
@@ -27,14 +27,6 @@
|
||||
*/
|
||||
XRefProperties::XRefProperties()
|
||||
{
|
||||
m_show_power_ctc = true;
|
||||
m_display = Cross;
|
||||
m_snap_to = Bottom;
|
||||
m_prefix_keys << "power" << "delay" << "switch";
|
||||
m_master_label = "%f-%l%c";
|
||||
m_slave_label = "(%f-%l%c)";
|
||||
m_offset = 0;
|
||||
m_xref_pos = Qt::AlignBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,8 +35,9 @@ XRefProperties::XRefProperties()
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
*/
|
||||
void XRefProperties::toSettings(QSettings &settings,
|
||||
const QString prefix) const
|
||||
void XRefProperties::toSettings(
|
||||
QSettings &settings,
|
||||
const QString &prefix) const
|
||||
{
|
||||
settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
|
||||
QString display = m_display == Cross? "cross" : "contacts";
|
||||
@@ -73,8 +66,7 @@ void XRefProperties::toSettings(QSettings &settings,
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
*/
|
||||
void XRefProperties::fromSettings(const QSettings &settings,
|
||||
const QString prefix)
|
||||
void XRefProperties::fromSettings(const QSettings &settings, const QString &prefix)
|
||||
{
|
||||
m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool();
|
||||
QString display = settings.value(prefix + "displayhas", "cross").toString();
|
||||
@@ -103,58 +95,59 @@ 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");
|
||||
QString display = m_display == Cross? "cross" : "contacts";
|
||||
xml_element.setAttribute("displayhas", display);
|
||||
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
||||
xml_element.setAttribute("snapto", snap);
|
||||
|
||||
QString xrefpos;
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "type", m_key));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "showpowerctc", m_show_power_ctc));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "displayhas", m_display == Cross? "cross" : "contacts"));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "snapto", m_snap_to == Bottom? "bottom" : "label"));
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
xml_element.setAttribute("xrefpos", var.valueToKey(m_xref_pos));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "xrefpos", var.valueToKey(m_xref_pos)));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "offset", m_offset));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "master_label", m_master_label));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "slave_label", m_slave_label));
|
||||
|
||||
int offset = m_offset;
|
||||
xml_element.setAttribute("offset", QString::number(offset));
|
||||
QString master_label = m_master_label;
|
||||
xml_element.setAttribute("master_label", master_label);
|
||||
QString slave_label = m_slave_label;
|
||||
xml_element.setAttribute("slave_label", slave_label);
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
xml_element.setAttribute(key + "prefix", m_prefix.value(key));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key)));
|
||||
}
|
||||
|
||||
return xml_element;
|
||||
}
|
||||
|
||||
/**
|
||||
/** RETURNS True
|
||||
@brief XRefProperties::fromXml
|
||||
Load from xml
|
||||
@param xml_element: QDomElement to use for load
|
||||
*/
|
||||
bool 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;
|
||||
QString snap = xml_element.attribute("snapto", "label");
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
|
||||
QString xrefpos = xml_element.attribute("xrefpos","Left");
|
||||
if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
|
||||
return false;
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
QString display;
|
||||
if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) {
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
}
|
||||
|
||||
if(xml_element.hasAttribute("xrefpos"))
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xml_element.attribute("xrefpos").toStdString().data()));
|
||||
else
|
||||
m_xref_pos = Qt::AlignBottom;
|
||||
|
||||
m_offset = xml_element.attribute("offset", "0").toInt();
|
||||
m_master_label = xml_element.attribute("master_label", "%f-%l%c");
|
||||
m_slave_label = xml_element.attribute("slave_label","(%f-%l%c)");
|
||||
QString snap;
|
||||
if (propertyString(xml_element, "snapto", &snap) != PropertyFlags::NotFound) {
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
}
|
||||
|
||||
QString xrefpos;
|
||||
if (propertyString(xml_element, "xrefpos", &xrefpos) != PropertyFlags::NotFound) {
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xrefpos.toStdString().data()));
|
||||
}
|
||||
// TODO: why it compiles without this true??
|
||||
propertyInteger(xml_element, "offset", &m_offset);
|
||||
propertyString(xml_element, "master_label", &m_master_label);
|
||||
propertyString(xml_element, "slave_label", &m_slave_label);
|
||||
QString value;
|
||||
foreach (QString key, m_prefix_keys) {
|
||||
m_prefix.insert(key, xml_element.attribute(key + "prefix"));
|
||||
if (!propertyString(xml_element, key + "prefix", &value));
|
||||
m_prefix.insert(key, value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,11 +42,9 @@ class XRefProperties : public PropertiesInterface
|
||||
Label
|
||||
};
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
static QHash<QString, XRefProperties> defaultProperties();
|
||||
@@ -80,15 +78,15 @@ class XRefProperties : public PropertiesInterface
|
||||
void setKey(QString& key) {m_key = key;}
|
||||
|
||||
private:
|
||||
bool m_show_power_ctc;
|
||||
DisplayHas m_display;
|
||||
SnapTo m_snap_to;
|
||||
Qt::AlignmentFlag m_xref_pos;
|
||||
bool m_show_power_ctc{true};
|
||||
DisplayHas m_display{Cross};
|
||||
SnapTo m_snap_to{Bottom};
|
||||
Qt::AlignmentFlag m_xref_pos{Qt::AlignBottom};
|
||||
QHash <QString, QString> m_prefix;
|
||||
QStringList m_prefix_keys;
|
||||
QString m_master_label;
|
||||
QString m_slave_label;
|
||||
int m_offset;
|
||||
QStringList m_prefix_keys{"power","delay","switch"};
|
||||
QString m_master_label{"%f-%l%c"};
|
||||
QString m_slave_label{"(%f-%l%c)"};
|
||||
int m_offset{0};
|
||||
QString m_key;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user