mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-08 07:59:58 +01:00
Revert "Merge branch 'XMLPropertiesNew'"
**Break a lot of thing.** This reverts commit1db1800572, reversing changes made to4c563821e8.
This commit is contained in:
@@ -19,18 +19,19 @@
|
||||
#include "../qetxml.h"
|
||||
#include <QDebug>
|
||||
|
||||
void ElementData::toSettings(QSettings &settings, const QString& prefix) const {
|
||||
void ElementData::toSettings(QSettings &settings, const QString prefix) const {
|
||||
Q_UNUSED(settings)
|
||||
Q_UNUSED(prefix)
|
||||
}
|
||||
|
||||
void ElementData::fromSettings(QSettings &settings, const QString& prefix) {
|
||||
void ElementData::fromSettings(const QSettings &settings, const QString prefix) {
|
||||
Q_UNUSED(settings)
|
||||
Q_UNUSED(prefix)
|
||||
}
|
||||
|
||||
void ElementData::toXmlPriv(QDomElement& e) const {
|
||||
Q_UNUSED(e)
|
||||
QDomElement ElementData::toXml(QDomDocument &xml_element) const {
|
||||
Q_UNUSED(xml_element)
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +42,7 @@ void ElementData::toXmlPriv(QDomElement& e) const {
|
||||
* @param xml_element : tagName must be 'definition'
|
||||
* @return true is successfuly loaded
|
||||
*/
|
||||
bool ElementData::fromXmlPriv(const QDomElement &xml_element)
|
||||
bool ElementData::fromXml(const QDomElement &xml_element)
|
||||
{
|
||||
if(xml_element.tagName() != "definition" ||
|
||||
xml_element.attribute("type") != "element") {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#ifndef ELEMENTDATA_H
|
||||
#define ELEMENTDATA_H
|
||||
|
||||
#include "../properties/propertiesinterface.h"
|
||||
#include "propertiesinterface.h"
|
||||
#include "../diagramcontext.h"
|
||||
#include "../NameList/nameslist.h"
|
||||
|
||||
@@ -85,10 +85,10 @@ class ElementData : public PropertiesInterface
|
||||
ElementData() {}
|
||||
~ElementData() override {}
|
||||
|
||||
void toSettings(QSettings &settings, const QString& prefix = QString()) const override;
|
||||
void fromSettings(QSettings &settings, const QString& prefix = QString()) override;
|
||||
void toXmlPriv(QDomElement &) const override;
|
||||
bool fromXmlPriv(const QDomElement &xml_element) override;
|
||||
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;
|
||||
QDomElement kindInfoToXml(QDomDocument &document);
|
||||
|
||||
bool operator==(const ElementData &data) const;
|
||||
|
||||
@@ -16,230 +16,17 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "propertiesinterface.h"
|
||||
#include <QDebug>
|
||||
#include "../qetxml.h"
|
||||
|
||||
/*!
|
||||
* Available property types
|
||||
*/
|
||||
namespace {
|
||||
|
||||
const QString userPropertiesS = "userProperties";
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PropertiesInterface::PropertiesInterface
|
||||
*/
|
||||
PropertiesInterface::PropertiesInterface(const QString &tagname):
|
||||
mTagName(tagname)
|
||||
PropertiesInterface::PropertiesInterface()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PropertiesInterface::~PropertiesInterface
|
||||
*/
|
||||
PropertiesInterface::~PropertiesInterface()
|
||||
{
|
||||
}
|
||||
|
||||
void PropertiesInterface::setTagName(const QString& tagname)
|
||||
{
|
||||
mTagName = tagname;
|
||||
}
|
||||
|
||||
QString PropertiesInterface::tagName() const
|
||||
{
|
||||
return mTagName;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::toXml (QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement element = xml_document.createElement(mTagName);
|
||||
toXmlPriv(element);
|
||||
propertiesToXml(element);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
bool PropertiesInterface::fromXml (const QDomElement &xml_element)
|
||||
{
|
||||
if (!fromXmlPriv(xml_element))
|
||||
return false;
|
||||
|
||||
if (!propertiesFromXml(xml_element))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PropertiesInterface::valideXml(QDomElement& element) {
|
||||
qDebug(QString("ValideXml() is not implemented. File: %1, Line: %2").arg(__FILE__).arg(__LINE__).toStdString().data());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
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);
|
||||
}
|
||||
|
||||
void PropertiesInterface::deleteUserProperties()
|
||||
{
|
||||
properties.clear();
|
||||
}
|
||||
|
||||
int PropertiesInterface::userPropertiesCount() const
|
||||
{
|
||||
return properties.count();
|
||||
}
|
||||
|
||||
void PropertiesInterface::setUserProperty(const QString& key, const QVariant& value)
|
||||
{
|
||||
properties[key] = value;
|
||||
}
|
||||
|
||||
bool PropertiesInterface::existUserProperty(const QString& key) const
|
||||
{
|
||||
return properties.contains(key);
|
||||
}
|
||||
|
||||
QVariant PropertiesInterface::userPropertyValue(const QString& key)
|
||||
{
|
||||
if (!existUserProperty(key))
|
||||
return QVariant();
|
||||
|
||||
return properties[key];
|
||||
}
|
||||
|
||||
void PropertiesInterface::propertiesToXml(QDomElement& e) const
|
||||
{
|
||||
if (properties.count() == 0)
|
||||
return;
|
||||
|
||||
QDomDocument doc = e.ownerDocument();
|
||||
auto up = doc.createElement(userPropertiesS);
|
||||
for (auto i = properties.begin(); i != properties.end(); ++i)
|
||||
{
|
||||
auto type = i.value().type();
|
||||
switch(type) {
|
||||
case QVariant::Type::String:
|
||||
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toString())); break;
|
||||
case QVariant::Type::Int:
|
||||
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toInt())); break;
|
||||
case QVariant::Type::Double:
|
||||
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toDouble())); break;
|
||||
case QVariant::Type::Bool:
|
||||
up.appendChild(QETXML::createXmlProperty(i.key(), i.value().toBool())); break;
|
||||
case QVariant::Type::Color:
|
||||
up.appendChild(QETXML::createXmlProperty(i.key(), QColor(i.value().value<QColor>()))); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
e.appendChild(up);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PropertiesInterface::propertiesFromXml
|
||||
* Read all user properties from the DomElement& e
|
||||
* \param e
|
||||
* \return
|
||||
*/
|
||||
bool PropertiesInterface::propertiesFromXml(const QDomElement& e)
|
||||
{
|
||||
QDomNodeList l = e.childNodes();
|
||||
for (int i=0; i < l.count(); i++)
|
||||
{
|
||||
QDomElement userProperties = l.at(i).toElement();
|
||||
if (userProperties.tagName() != userPropertiesS)
|
||||
continue;
|
||||
|
||||
QDomElement userProperty;
|
||||
for (int up_index = 0; up_index < userProperties.childNodes().length(); up_index++)
|
||||
{
|
||||
userProperty = userProperties.childNodes().at(up_index).toElement();
|
||||
|
||||
QString name = userProperty.attribute("name");
|
||||
QString type = userProperty.attribute("type");
|
||||
QString value = userProperty.attribute("value");
|
||||
|
||||
if (type == QETXML::integerS)
|
||||
{
|
||||
int i;
|
||||
if (QETXML::propertyInteger(value, &i) == QETXML::PropertyFlags::Success)
|
||||
properties[name] = QVariant(i);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == QETXML::doubleS)
|
||||
{
|
||||
double d;
|
||||
if (QETXML::propertyDouble(value, &d) == QETXML::PropertyFlags::Success)
|
||||
properties[name] = QVariant(d);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == QETXML::boolS)
|
||||
{
|
||||
bool b;
|
||||
if (QETXML::propertyBool(value, &b) == QETXML::PropertyFlags::Success)
|
||||
properties[name] = QVariant(b);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == QETXML::uuidS)
|
||||
{
|
||||
QUuid u;
|
||||
if (QETXML::propertyUuid(value, &u) == QETXML::PropertyFlags::Success)
|
||||
properties[name] = QVariant(u);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == QETXML::colorS)
|
||||
{
|
||||
QColor c;
|
||||
if (QETXML::propertyColor(value, &c) == QETXML::PropertyFlags::Success)
|
||||
properties[name] = QVariant(c);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == QETXML::stringS)
|
||||
{
|
||||
properties[name] = QVariant(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Not a valid property type!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@@ -20,11 +20,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
#include <QColor>
|
||||
#include <QDomElement>
|
||||
#include <limits>
|
||||
#include "sources/qet.h"
|
||||
#include <QUuid>
|
||||
|
||||
/**
|
||||
@brief The PropertiesInterface class
|
||||
@@ -34,7 +30,7 @@
|
||||
class PropertiesInterface
|
||||
{
|
||||
public:
|
||||
PropertiesInterface(const QString& tagname = "Properties");
|
||||
PropertiesInterface();
|
||||
virtual ~PropertiesInterface();
|
||||
/**
|
||||
@brief toSettings
|
||||
@@ -43,8 +39,8 @@ class PropertiesInterface
|
||||
befor the name of each paramètre
|
||||
@param QString
|
||||
*/
|
||||
virtual void toSettings(QSettings &,
|
||||
const QString & = QString()) const =0;
|
||||
virtual void toSettings (QSettings &settings,
|
||||
const QString = QString()) const =0;
|
||||
/**
|
||||
@brief fromSettings
|
||||
load properties to setting file.
|
||||
@@ -52,98 +48,22 @@ class PropertiesInterface
|
||||
befor the name of each paramètre
|
||||
@param QString
|
||||
*/
|
||||
virtual void fromSettings(QSettings &,
|
||||
const QString & = QString()) = 0;
|
||||
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;
|
||||
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);
|
||||
|
||||
/*!
|
||||
* \brief deleteUserProperties
|
||||
* Delete all userproperties
|
||||
*/
|
||||
void deleteUserProperties();
|
||||
|
||||
/*!
|
||||
* \brief userPropertiesCount
|
||||
* Returns the number of user properties
|
||||
* \return
|
||||
*/
|
||||
int userPropertiesCount() const;
|
||||
|
||||
/*!
|
||||
* \brief setUserProperty
|
||||
* Adds a new property if \p key does not exist in the \p properties member,
|
||||
* otherwise overwrite the value
|
||||
* \param key
|
||||
* \param value
|
||||
*/
|
||||
void setUserProperty(const QString& key, const QVariant& value);
|
||||
|
||||
/*!
|
||||
* \brief existUserProperty
|
||||
* Checks if a user property with key \p key is available or not
|
||||
* \param key
|
||||
* \return
|
||||
*/
|
||||
bool existUserProperty(const QString& key) const;
|
||||
|
||||
/*!
|
||||
* \brief userProperty
|
||||
* Returns the value of a user property with key \p key
|
||||
* If \p key is not found, an invalid QVariant is returned.
|
||||
* Use QVariant::type() to get the type of the vale
|
||||
* \param key
|
||||
* \return
|
||||
*/
|
||||
QVariant userPropertyValue(const QString& key);
|
||||
|
||||
|
||||
static bool valideXml(QDomElement& element);
|
||||
|
||||
void setTagName(const QString& tagname);
|
||||
QString tagName() const;
|
||||
|
||||
/**
|
||||
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);
|
||||
|
||||
private:
|
||||
virtual void toXmlPriv (QDomElement &e) const =0;
|
||||
virtual bool fromXmlPriv (const QDomElement &e) =0;
|
||||
/*!
|
||||
* \brief PropertiesInterface::propertiesToXml
|
||||
* Write all user properties to the DomElement \p e
|
||||
* \param e
|
||||
*/
|
||||
void propertiesToXml(QDomElement& e) const;
|
||||
bool propertiesFromXml (const QDomElement &e);
|
||||
|
||||
QHash<QString, QVariant> properties;
|
||||
QString mTagName{""};
|
||||
virtual bool fromXml (const QDomElement &xml_element) =0;
|
||||
};
|
||||
|
||||
#endif // PROPERTIESINTERFACE_H
|
||||
|
||||
@@ -20,16 +20,14 @@
|
||||
#include <QGraphicsObject>
|
||||
#include <QDebug>
|
||||
|
||||
#include "../qetxml.h"
|
||||
|
||||
TerminalData::TerminalData():
|
||||
PropertiesInterface("terminaldata")
|
||||
PropertiesInterface()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
TerminalData::TerminalData(QGraphicsObject *parent):
|
||||
PropertiesInterface("terminaldata"),
|
||||
PropertiesInterface(),
|
||||
q(parent)
|
||||
{
|
||||
init();
|
||||
@@ -61,7 +59,7 @@ void TerminalData::setParent(QGraphicsObject* parent)
|
||||
@param settings UNUSED
|
||||
@param prefix UNUSED
|
||||
*/
|
||||
void TerminalData::toSettings(QSettings &settings, const QString &prefix) const
|
||||
void TerminalData::toSettings(QSettings &settings, const QString prefix) const
|
||||
|
||||
{
|
||||
Q_UNUSED(settings)
|
||||
@@ -76,39 +74,44 @@ void TerminalData::toSettings(QSettings &settings, const QString &prefix) const
|
||||
@param settings UNUSED
|
||||
@param prefix UNUSED
|
||||
*/
|
||||
void TerminalData::fromSettings(QSettings &settings, const QString& prefix)
|
||||
void TerminalData::fromSettings(const QSettings &settings, const QString prefix)
|
||||
{
|
||||
Q_UNUSED(settings)
|
||||
Q_UNUSED(prefix)
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::toXmlPriv
|
||||
@brief TerminalData::toXml
|
||||
Save properties to xml element
|
||||
write the name, number, position and orientation of the terminal
|
||||
to xml_element
|
||||
|
||||
@note This method is only called from the PartTerminal
|
||||
and should never called from the Terminal class
|
||||
@param e: element to store the properties
|
||||
@param xml_document
|
||||
@return xml_element : DomElement with
|
||||
the name, number, position and orientation of the terminal
|
||||
*/
|
||||
void TerminalData::toXmlPriv(QDomElement& xml_element) const
|
||||
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
|
||||
QDomElement xml_element = xml_document.createElement("terminal");
|
||||
|
||||
xml_element.setAttribute("uuid", m_uuid.toString());
|
||||
xml_element.setAttribute("name", m_name);
|
||||
xml_element.setAttribute("x", QString("%1").arg(q->scenePos().x()));
|
||||
xml_element.setAttribute("y", QString("%1").arg(q->scenePos().y()));
|
||||
|
||||
xml_element.setAttribute("orientation",
|
||||
orientationToString(m_orientation));
|
||||
xml_element.setAttribute("uuid", m_uuid.toString());
|
||||
xml_element.setAttribute("name", m_name);
|
||||
|
||||
xml_element.setAttribute("type", typeToString(m_type));
|
||||
xml_element.setAttribute("orientation",
|
||||
Qet::orientationToString(m_orientation));
|
||||
|
||||
xml_element.setAttribute("type", typeToString(m_type));
|
||||
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/*
|
||||
@brief TerminalData::fromXmlPriv
|
||||
/**
|
||||
@brief TerminalData::fromXml
|
||||
load properties to xml element
|
||||
|
||||
@note This method is only called from the PartTerminal
|
||||
@@ -116,67 +119,41 @@ void TerminalData::toXmlPriv(QDomElement& xml_element) const
|
||||
@param xml_element
|
||||
@return true if succeeded / false if the attribute is not real
|
||||
*/
|
||||
bool TerminalData::fromXmlPriv(const QDomElement &xml_element)
|
||||
bool TerminalData::fromXml (const QDomElement &xml_element)
|
||||
{
|
||||
qreal term_x = 0.0;
|
||||
qreal term_y = 0.0;
|
||||
|
||||
// reads the position of the terminal
|
||||
// lit la position de la borne
|
||||
|
||||
if (QETXML::propertyDouble(xml_element, "x", &term_x))
|
||||
if (!QET::attributeIsAReal(xml_element, "x", &term_x))
|
||||
return false;
|
||||
|
||||
if (QETXML::propertyDouble(xml_element, "y", &term_y))
|
||||
if (!QET::attributeIsAReal(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));
|
||||
|
||||
// do not write uuid from this class, because only PartTerminal::fromXml need
|
||||
// to write it to xml file. Terminal::fromXml does not need.
|
||||
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);
|
||||
|
||||
|
||||
//if (QETXML::propertyString(xml_element, "name", &m_name))
|
||||
// return false;
|
||||
QETXML::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 (QETXML::propertyString(xml_element, "orientation", &o))
|
||||
return false;
|
||||
m_name = xml_element.attribute("name");
|
||||
|
||||
// read the orientation of the terminal
|
||||
// lit l'orientation de la borne
|
||||
m_orientation = orientationFromString(o);
|
||||
|
||||
QString type;
|
||||
if (QETXML::propertyString(xml_element, "type", &type) == QETXML::PropertyFlags::Success)
|
||||
m_type = typeFromString(type);
|
||||
m_orientation = Qet::orientationFromString(
|
||||
xml_element.attribute("orientation"));
|
||||
|
||||
return true;
|
||||
}
|
||||
m_type = typeFromString(xml_element.attribute("type"));
|
||||
|
||||
bool TerminalData::valideXml(const QDomElement& xml_element) {
|
||||
if (QETXML::propertyDouble(xml_element, "x"))
|
||||
return false;
|
||||
|
||||
// Old projects do not have this property.
|
||||
// if (QETXML::propertyString(xml_element, "type"))
|
||||
// return false;
|
||||
|
||||
|
||||
// legacy elements do not have an uuid
|
||||
// if (QETXML::propertyUuid(xml_element, "uuid"))
|
||||
// return false;
|
||||
|
||||
//if (QETXML::propertyString(xml_element, "name")) // some parts do not have a name. Example: affuteuse_250h.qet, Terminal at x="0" y="-20"
|
||||
// return false;
|
||||
|
||||
if (QETXML::propertyString(xml_element, "orientation"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define TERMINALDATA_H
|
||||
|
||||
#include "../qet.h"
|
||||
#include "../properties/propertiesinterface.h"
|
||||
#include "propertiesinterface.h"
|
||||
|
||||
#include <QPointF>
|
||||
#include <QUuid>
|
||||
@@ -53,13 +53,11 @@ class TerminalData : public PropertiesInterface
|
||||
|
||||
void setParent(QGraphicsObject* parent);
|
||||
void toSettings(QSettings &settings,
|
||||
const QString& prefix = QString()) const override;
|
||||
void fromSettings(QSettings &settings,
|
||||
const QString& = QString()) override;
|
||||
void toXmlPriv(QDomElement &xml_element) const override;
|
||||
bool fromXmlPriv(const QDomElement &xml_element) override;
|
||||
|
||||
static bool valideXml(const QDomElement &xml_element);
|
||||
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;
|
||||
|
||||
static QString typeToString(TerminalData::Type type);
|
||||
static TerminalData::Type typeFromString(const QString &string);
|
||||
@@ -71,13 +69,13 @@ class TerminalData : public PropertiesInterface
|
||||
@brief m_orientation
|
||||
Orientation of the terminal
|
||||
*/
|
||||
Qet::Orientation m_orientation{Qet::Orientation::North};
|
||||
Qet::Orientation m_orientation;
|
||||
/**
|
||||
@brief m_second_point
|
||||
@brief second_point
|
||||
Position of the second point of the terminal
|
||||
in scene coordinates
|
||||
*/
|
||||
QPointF m_second_point{0,0};
|
||||
QPointF m_second_point;
|
||||
/**
|
||||
@brief m_uuid
|
||||
Uuid of the terminal.
|
||||
@@ -92,7 +90,7 @@ class TerminalData : public PropertiesInterface
|
||||
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.
|
||||
QUuid m_uuid;
|
||||
/**
|
||||
@brief m_name
|
||||
Name of the element.
|
||||
@@ -110,8 +108,10 @@ class TerminalData : public PropertiesInterface
|
||||
It is used to store the initial position so that
|
||||
PartTerminal and Terminal have access to it.
|
||||
*/
|
||||
QPointF m_pos{0,0};
|
||||
QPointF m_pos;
|
||||
|
||||
TerminalData::Type m_type = TerminalData::Generic;
|
||||
|
||||
private:
|
||||
QGraphicsObject* q{nullptr};
|
||||
};
|
||||
|
||||
@@ -22,15 +22,20 @@
|
||||
#include <QHash>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#include "../qetxml.h"
|
||||
|
||||
/**
|
||||
@brief XRefProperties::XRefProperties
|
||||
Default Constructor
|
||||
*/
|
||||
XRefProperties::XRefProperties()
|
||||
{
|
||||
setTagName("xref");
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +45,7 @@ XRefProperties::XRefProperties()
|
||||
@param prefix: prefix before properties name
|
||||
*/
|
||||
void XRefProperties::toSettings(QSettings &settings,
|
||||
const QString &prefix) const
|
||||
const QString prefix) const
|
||||
{
|
||||
settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
|
||||
QString display = m_display == Cross? "cross" : "contacts";
|
||||
@@ -69,8 +74,8 @@ void XRefProperties::toSettings(QSettings &settings,
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
*/
|
||||
void XRefProperties::fromSettings(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();
|
||||
@@ -95,66 +100,62 @@ void XRefProperties::fromSettings(QSettings &settings,
|
||||
@param xml_document : QDomElement to use for saving
|
||||
@return QDomElement
|
||||
*/
|
||||
void XRefProperties::toXmlPriv(QDomElement& xml_element) const
|
||||
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
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);
|
||||
QDomElement xml_element = xml_document.createElement("xref");
|
||||
xml_element.setAttribute("type", m_key);
|
||||
|
||||
QString xrefpos;
|
||||
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);
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
xml_element.setAttribute("xrefpos", var.valueToKey(m_xref_pos));
|
||||
QString xrefpos;
|
||||
|
||||
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));
|
||||
}
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
xml_element.setAttribute("xrefpos", var.valueToKey(m_xref_pos));
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
return xml_element;
|
||||
}
|
||||
|
||||
/** RETURNS True
|
||||
@brief XRefProperties::fromXmlPriv
|
||||
/**
|
||||
@brief XRefProperties::fromXml
|
||||
Load from xml
|
||||
@param xml_element: QDomElement to use for load
|
||||
*/
|
||||
bool XRefProperties::fromXmlPriv(const QDomElement &xml_element) {
|
||||
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;
|
||||
|
||||
if (QETXML::propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
|
||||
return false;
|
||||
QString xrefpos = xml_element.attribute("xrefpos","Left");
|
||||
|
||||
QString display;
|
||||
if (QETXML::propertyString(xml_element, "displayhas", &display) != QETXML::PropertyFlags::NotFound) {
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
}
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
|
||||
if(xml_element.hasAttribute("xrefpos"))
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue(xml_element.attribute("xrefpos").toStdString().data()));
|
||||
else
|
||||
m_xref_pos = Qt::AlignBottom;
|
||||
|
||||
QString snap;
|
||||
if (QETXML::propertyString(xml_element, "snapto", &snap) != QETXML::PropertyFlags::NotFound) {
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
}
|
||||
|
||||
QString xrefpos;
|
||||
if (QETXML::propertyString(xml_element, "xrefpos", &xrefpos) != QETXML::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??
|
||||
QETXML::propertyInteger(xml_element, "offset", &m_offset);
|
||||
QETXML::propertyString(xml_element, "master_label", &m_master_label);
|
||||
QETXML::propertyString(xml_element, "slave_label", &m_slave_label);
|
||||
QString value;
|
||||
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)");
|
||||
foreach (QString key, m_prefix_keys) {
|
||||
if (!QETXML::propertyString(xml_element, key + "prefix", &value))
|
||||
m_prefix.insert(key, value);
|
||||
m_prefix.insert(key, xml_element.attribute(key + "prefix"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -42,11 +42,12 @@ class XRefProperties : public PropertiesInterface
|
||||
Label
|
||||
};
|
||||
|
||||
void toSettings (QSettings &settings, const QString& = QString()) const override;
|
||||
void fromSettings (QSettings &settings,
|
||||
const QString& = QString()) override;
|
||||
void toXmlPriv(QDomElement&xml_element) const override;
|
||||
bool fromXmlPriv(const QDomElement &xml_element) 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();
|
||||
|
||||
@@ -79,15 +80,15 @@ class XRefProperties : public PropertiesInterface
|
||||
void setKey(QString& key) {m_key = key;}
|
||||
|
||||
private:
|
||||
bool m_show_power_ctc{true};
|
||||
DisplayHas m_display{Cross};
|
||||
SnapTo m_snap_to{Bottom};
|
||||
Qt::AlignmentFlag m_xref_pos{Qt::AlignBottom};
|
||||
bool m_show_power_ctc;
|
||||
DisplayHas m_display;
|
||||
SnapTo m_snap_to;
|
||||
Qt::AlignmentFlag m_xref_pos;
|
||||
QHash <QString, QString> m_prefix;
|
||||
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};
|
||||
QStringList m_prefix_keys;
|
||||
QString m_master_label;
|
||||
QString m_slave_label;
|
||||
int m_offset;
|
||||
QString m_key;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user