mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-03-03 20:19:59 +01:00
Add userProperties
This commit is contained in:
@@ -29,9 +29,8 @@ void ElementData::fromSettings(QSettings &settings, const QString& prefix) {
|
||||
Q_UNUSED(prefix)
|
||||
}
|
||||
|
||||
QDomElement ElementData::toXml(QDomDocument &xml_element) const {
|
||||
Q_UNUSED(xml_element)
|
||||
return QDomElement();
|
||||
void ElementData::toXmlPriv(QDomElement& e) const {
|
||||
Q_UNUSED(e)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +41,7 @@ QDomElement ElementData::toXml(QDomDocument &xml_element) const {
|
||||
* @param xml_element : tagName must be 'definition'
|
||||
* @return true is successfuly loaded
|
||||
*/
|
||||
bool ElementData::fromXml(const QDomElement &xml_element)
|
||||
bool ElementData::fromXmlPriv(const QDomElement &xml_element)
|
||||
{
|
||||
if(xml_element.tagName() != "definition" ||
|
||||
xml_element.attribute("type") != "element") {
|
||||
|
||||
@@ -87,8 +87,8 @@ class ElementData : public PropertiesInterface
|
||||
|
||||
void toSettings(QSettings &settings, const QString& prefix = QString()) const override;
|
||||
void fromSettings(QSettings &settings, const QString& prefix = QString()) override;
|
||||
QDomElement toXml(QDomDocument &xml_element) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
void toXmlPriv(QDomElement &) const override;
|
||||
bool fromXmlPriv(const QDomElement &xml_element) override;
|
||||
QDomElement kindInfoToXml(QDomDocument &document);
|
||||
|
||||
bool operator==(const ElementData &data) const;
|
||||
|
||||
@@ -28,12 +28,23 @@ namespace {
|
||||
const QString stringS = "string";
|
||||
const QString uuidS = "uuid";
|
||||
const QString colorS = "color";
|
||||
|
||||
const QString userPropertiesS = "userProperties";
|
||||
|
||||
PropertiesInterface::PropertyFlags debug(PropertiesInterface::PropertyFlags flag, const QDomElement &e, const QString& attribute_name, const QString& attr, const QString& type)
|
||||
{
|
||||
if (flag == PropertiesInterface::PropertyFlags::NoValidConversion)
|
||||
qDebug() << "\t\t\t" << "Tagname: " << e.tagName() << ". " << "No valid Conversion: " << attribute_name << ". type: " << type << ". value: " << attr;
|
||||
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PropertiesInterface::PropertiesInterface
|
||||
*/
|
||||
PropertiesInterface::PropertiesInterface()
|
||||
PropertiesInterface::PropertiesInterface(const QString &tagname):
|
||||
mTagName(tagname)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -44,61 +55,91 @@ PropertiesInterface::~PropertiesInterface()
|
||||
{
|
||||
}
|
||||
|
||||
void PropertiesInterface::setTagName(const QString& tagname)
|
||||
{
|
||||
mTagName = tagname;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
QDomElement PropertiesInterface::createXmlProperty(const QString& name, const QString value) {
|
||||
QDomDocument doc;
|
||||
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");
|
||||
QDomElement PropertiesInterface::createXmlProperty(const QString& name, const char* value) {
|
||||
QDomDocument doc;
|
||||
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");
|
||||
QDomElement PropertiesInterface::createXmlProperty(const QString& name, const int value) {
|
||||
QDomDocument doc;
|
||||
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");
|
||||
QDomElement PropertiesInterface::createXmlProperty(const QString& name, const double value) {
|
||||
QDomDocument doc;
|
||||
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");
|
||||
QDomElement PropertiesInterface::createXmlProperty(const QString& name, const bool value) {
|
||||
QDomDocument doc;
|
||||
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");
|
||||
QDomElement PropertiesInterface::createXmlProperty(const QString& name, const QUuid value) {
|
||||
QDomDocument doc;
|
||||
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");
|
||||
QDomElement PropertiesInterface::createXmlProperty(const QString& name, const QColor value) {
|
||||
QDomDocument doc;
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", colorS);
|
||||
p.setAttribute("value", value.name());
|
||||
@@ -167,18 +208,21 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QD
|
||||
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;
|
||||
}
|
||||
return debug(propertyInteger(attr, entier), e, attribute_name, attr, integerS);
|
||||
}
|
||||
|
||||
if (entier != nullptr)
|
||||
*entier = tmp;
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyInteger(const QString& value, int* entier) {
|
||||
// verifie la validite de l'attribut
|
||||
bool ok;
|
||||
int tmp = value.toInt(&ok);
|
||||
if (!ok) {
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
return PropertyFlags::Success;
|
||||
if (entier != nullptr)
|
||||
*entier = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) {
|
||||
@@ -189,18 +233,22 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo
|
||||
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;
|
||||
}
|
||||
return debug(propertyDouble(attr, reel), e, attribute_name, attr, doubleS);
|
||||
}
|
||||
|
||||
if (reel != nullptr)
|
||||
*reel = tmp;
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QString& value, double* reel)
|
||||
{
|
||||
// verifie la validite de l'attribut
|
||||
bool ok;
|
||||
double tmp = value.toDouble(&ok);
|
||||
if (!ok) {
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
return PropertyFlags::Success;
|
||||
if (reel != nullptr)
|
||||
*reel = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) {
|
||||
@@ -211,24 +259,28 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE
|
||||
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;
|
||||
}
|
||||
}
|
||||
return debug(propertyBool(attr, boolean), e, attribute_name, attr, boolS);
|
||||
}
|
||||
|
||||
if (boolean != nullptr)
|
||||
*boolean = tmp;
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QString& value, bool* boolean)
|
||||
{
|
||||
// verifie la validite de l'attribut
|
||||
bool ok;
|
||||
bool tmp = value.toInt(&ok);
|
||||
if (!ok) {
|
||||
if (value == "true" || value == "1")
|
||||
tmp = true;
|
||||
else if (value == "false" || value == "0")
|
||||
tmp = false;
|
||||
else {
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
}
|
||||
|
||||
return PropertyFlags::Success;
|
||||
if (boolean != nullptr)
|
||||
*boolean = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) {
|
||||
@@ -239,17 +291,21 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDom
|
||||
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;
|
||||
}
|
||||
return debug(propertyColor(attr, color), e, attribute_name, attr, colorS);
|
||||
}
|
||||
|
||||
if (color != nullptr)
|
||||
*color = tmp;
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QString& value, QColor* color)
|
||||
{
|
||||
// verifie la validite de l'attribut
|
||||
QColor tmp = QColor(value);
|
||||
if (!tmp.isValid()) {
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
return PropertyFlags::Success;
|
||||
if (color != nullptr)
|
||||
*color = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) {
|
||||
@@ -259,16 +315,20 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomE
|
||||
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;
|
||||
}
|
||||
return debug(propertyUuid(attr, uuid), e, attribute_name, attr, uuidS);
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QString& value, QUuid* uuid)
|
||||
{
|
||||
if (QUuid(value).isNull()){
|
||||
return PropertyFlags::NoValidConversion;
|
||||
}
|
||||
|
||||
|
||||
if (uuid != nullptr)
|
||||
*uuid = QUuid(attr);
|
||||
if (uuid != nullptr)
|
||||
*uuid = QUuid(value);
|
||||
|
||||
return PropertyFlags::Success;
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string) {
|
||||
@@ -336,3 +396,110 @@ QString PropertiesInterface::orientationToString(Qet::Orientation o) {
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PropertiesInterface::propertiesToXml
|
||||
* Write all user properties to the DomElement \p e
|
||||
* \param e
|
||||
*/
|
||||
void PropertiesInterface::propertiesToXml(QDomElement& e) const
|
||||
{
|
||||
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(createXmlProperty(i.key(), i.value().toString())); break;
|
||||
case QVariant::Type::Int:
|
||||
up.appendChild(createXmlProperty(i.key(), i.value().toInt())); break;
|
||||
case QVariant::Type::Double:
|
||||
up.appendChild(createXmlProperty(i.key(), i.value().toDouble())); break;
|
||||
case QVariant::Type::Bool:
|
||||
up.appendChild(createXmlProperty(i.key(), i.value().toBool())); break;
|
||||
// case QVariant::Type::Color:
|
||||
// // TODO: correct?
|
||||
// up.appendChild(createXmlProperty(i.key(), i.value().toString())); 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 == integerS)
|
||||
{
|
||||
int i;
|
||||
if (propertyInteger(value, &i) == PropertyFlags::Success)
|
||||
properties[name] = QVariant(i);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == doubleS)
|
||||
{
|
||||
double d;
|
||||
if (propertyDouble(value, &d) == PropertyFlags::Success)
|
||||
properties[name] = QVariant(d);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == boolS)
|
||||
{
|
||||
bool b;
|
||||
if (propertyBool(value, &b) == PropertyFlags::Success)
|
||||
properties[name] = QVariant(b);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == uuidS)
|
||||
{
|
||||
QUuid u;
|
||||
if (propertyUuid(value, &u) == PropertyFlags::Success)
|
||||
properties[name] = QVariant(u);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == colorS)
|
||||
{
|
||||
QColor c;
|
||||
if (propertyColor(value, &c) == PropertyFlags::Success)
|
||||
properties[name] = QVariant(c);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else if (type == stringS)
|
||||
{
|
||||
properties[name] = QVariant(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Not a valid property type!";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,52 @@
|
||||
#include "sources/qet.h"
|
||||
#include <QUuid>
|
||||
|
||||
//struct Property {
|
||||
// enum class Type {
|
||||
// String,
|
||||
// Int,
|
||||
// Double,
|
||||
// Bool,
|
||||
// Uuid,
|
||||
// Color
|
||||
// };
|
||||
// Property(enum Type type, QVariant& value): type(type), value(value) {};
|
||||
// enum Type type;
|
||||
// QVariant value;
|
||||
//};
|
||||
|
||||
//class Property_T
|
||||
//{
|
||||
//public:
|
||||
// enum class Type {
|
||||
// String,
|
||||
// Int,
|
||||
// Double,
|
||||
// Bool,
|
||||
// Uuid,
|
||||
// Color
|
||||
// };
|
||||
// Property_T(enum Type type): mType(type)
|
||||
// {}
|
||||
//public:
|
||||
// enum Type mType;
|
||||
//};
|
||||
|
||||
//class PropertyDouble: Property_T
|
||||
//{
|
||||
//public:
|
||||
// PropertyDouble(double& value): Property_T(Property_T::Type::Double), mValue(value) {};
|
||||
//public:
|
||||
// double mValue;
|
||||
//};
|
||||
|
||||
class DomElement: public QDomElement
|
||||
{
|
||||
public:
|
||||
DomElement(): QDomElement() {};
|
||||
DomElement(QDomElement& e): QDomElement(e) {};
|
||||
};
|
||||
|
||||
/**
|
||||
@brief The PropertiesInterface class
|
||||
This class is an interface for have common way
|
||||
@@ -34,7 +80,7 @@
|
||||
class PropertiesInterface
|
||||
{
|
||||
public:
|
||||
PropertiesInterface();
|
||||
PropertiesInterface(const QString& tagname = "Properties");
|
||||
virtual ~PropertiesInterface();
|
||||
/**
|
||||
@brief toSettings
|
||||
@@ -60,26 +106,26 @@ class PropertiesInterface
|
||||
@param xml_document
|
||||
@return QDomElement
|
||||
*/
|
||||
virtual QDomElement toXml (QDomDocument &xml_document) const =0;
|
||||
virtual QDomElement toXml (QDomDocument &xml_document) const;
|
||||
/**
|
||||
@brief fromXml
|
||||
load properties to xml element
|
||||
@param xml_element
|
||||
@return true / false
|
||||
*/
|
||||
virtual bool fromXml (const QDomElement &xml_element) =0;
|
||||
virtual bool fromXml (const QDomElement &xml_element);
|
||||
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 createXmlProperty(const QString& name, const QString value);
|
||||
static QDomElement createXmlProperty(const QString& name, const char* value);
|
||||
static QDomElement createXmlProperty(const QString& name, const int value);
|
||||
static QDomElement createXmlProperty(const QString& name, const double value);
|
||||
static QDomElement createXmlProperty(const QString& name, const bool value);
|
||||
static QDomElement createXmlProperty(const QString& name, const QUuid value);
|
||||
static QDomElement createXmlProperty(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);
|
||||
@@ -91,17 +137,23 @@ class PropertiesInterface
|
||||
// = 4
|
||||
};
|
||||
|
||||
static PropertyFlags propertyInteger(const QString& value, int* entry = nullptr);
|
||||
static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr);
|
||||
static PropertyFlags propertyDouble(const QString& value, double* entry = 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 QString& value, bool* entry = nullptr);
|
||||
static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr);
|
||||
static PropertyFlags propertyUuid(const QString& value, QUuid* entry = nullptr);
|
||||
static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr);
|
||||
static PropertyFlags propertyColor(const QString& value, QColor* entry = 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);
|
||||
void setTagName(const QString& tagname);
|
||||
|
||||
/**
|
||||
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w")
|
||||
@@ -118,6 +170,15 @@ class PropertiesInterface
|
||||
@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;
|
||||
void propertiesToXml(QDomElement& e) const;
|
||||
bool propertiesFromXml (const QDomElement &e);
|
||||
|
||||
QHash<QString, QVariant> properties;
|
||||
QString mTagName{""};
|
||||
};
|
||||
|
||||
#endif // PROPERTIESINTERFACE_H
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
#include <QDebug>
|
||||
|
||||
TerminalData::TerminalData():
|
||||
PropertiesInterface()
|
||||
PropertiesInterface("terminaldata")
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
TerminalData::TerminalData(QGraphicsObject *parent):
|
||||
PropertiesInterface(),
|
||||
PropertiesInterface("terminaldata"),
|
||||
q(parent)
|
||||
{
|
||||
init();
|
||||
@@ -81,35 +81,33 @@ void TerminalData::fromSettings(QSettings &settings, const QString& prefix)
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::toXml
|
||||
@brief TerminalData::toXmlPriv
|
||||
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 xml_document
|
||||
@return xml_element : DomElement with
|
||||
@param e: element to store the properties
|
||||
the name, number, position and orientation of the terminal
|
||||
*/
|
||||
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||
void TerminalData::toXmlPriv(QDomElement& e) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("terminaldata");
|
||||
// TODO:
|
||||
//QDomElement xml_element = xml_document.createElement("terminaldata");
|
||||
|
||||
// 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)));
|
||||
xml_element.appendChild(createXmlProperty(xml_document, "type", typeToString(m_type)));
|
||||
|
||||
return(xml_element);
|
||||
e.appendChild(createXmlProperty("x", m_pos.x()));
|
||||
e.appendChild(createXmlProperty("y", m_pos.y()));
|
||||
e.appendChild(createXmlProperty("name", m_name));
|
||||
e.appendChild(createXmlProperty("orientation", orientationToString(m_orientation)));
|
||||
e.appendChild(createXmlProperty("type", typeToString(m_type)));
|
||||
}
|
||||
|
||||
/*
|
||||
@brief TerminalData::fromXml
|
||||
@brief TerminalData::fromXmlPriv
|
||||
load properties to xml element
|
||||
|
||||
@note This method is only called from the PartTerminal
|
||||
@@ -117,7 +115,7 @@ QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||
@param xml_element
|
||||
@return true if succeeded / false if the attribute is not real
|
||||
*/
|
||||
bool TerminalData::fromXml (const QDomElement &xml_element) // RETURNS True
|
||||
bool TerminalData::fromXmlPriv(const QDomElement &xml_element)
|
||||
{
|
||||
qreal term_x = 0.0;
|
||||
qreal term_y = 0.0;
|
||||
|
||||
@@ -56,8 +56,8 @@ class TerminalData : public PropertiesInterface
|
||||
const QString& prefix = QString()) const override;
|
||||
void fromSettings(QSettings &settings,
|
||||
const QString& = QString()) override;
|
||||
QDomElement toXml(QDomDocument &xml_element) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
void toXmlPriv(QDomElement &) const override;
|
||||
bool fromXmlPriv(const QDomElement &xml_element) override;
|
||||
|
||||
static bool valideXml(const QDomElement &xml_element);
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
*/
|
||||
XRefProperties::XRefProperties()
|
||||
{
|
||||
setTagName("xref");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,36 +93,32 @@ void XRefProperties::fromSettings(QSettings &settings,
|
||||
@param xml_document : QDomElement to use for saving
|
||||
@return QDomElement
|
||||
*/
|
||||
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const
|
||||
void XRefProperties::toXmlPriv(QDomElement& e) const
|
||||
{
|
||||
|
||||
QDomElement xml_element = xml_document.createElement("xref");
|
||||
|
||||
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"));
|
||||
e.appendChild(createXmlProperty("type", m_key));
|
||||
e.appendChild(createXmlProperty("showpowerctc", m_show_power_ctc));
|
||||
e.appendChild(createXmlProperty("displayhas", m_display == Cross? "cross" : "contacts"));
|
||||
e.appendChild(createXmlProperty("snapto", m_snap_to == Bottom? "bottom" : "label"));
|
||||
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
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));
|
||||
e.appendChild(createXmlProperty("xrefpos", var.valueToKey(m_xref_pos)));
|
||||
e.appendChild(createXmlProperty("offset", m_offset));
|
||||
e.appendChild(createXmlProperty("master_label", m_master_label));
|
||||
e.appendChild(createXmlProperty("slave_label", m_slave_label));
|
||||
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key)));
|
||||
e.appendChild(createXmlProperty(key + "prefix", m_prefix.value(key)));
|
||||
}
|
||||
|
||||
return xml_element;
|
||||
}
|
||||
|
||||
/** RETURNS True
|
||||
@brief XRefProperties::fromXml
|
||||
@brief XRefProperties::fromXmlPriv
|
||||
Load from xml
|
||||
@param xml_element: QDomElement to use for load
|
||||
*/
|
||||
bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||
bool XRefProperties::fromXmlPriv(const QDomElement &xml_element) {
|
||||
|
||||
if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
|
||||
return false;
|
||||
|
||||
@@ -45,8 +45,8 @@ class XRefProperties : public PropertiesInterface
|
||||
void toSettings (QSettings &settings, const QString& = QString()) const override;
|
||||
void fromSettings (QSettings &settings,
|
||||
const QString& = QString()) override;
|
||||
QDomElement toXml (QDomDocument &xml_document) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
void toXmlPriv(QDomElement&) const override;
|
||||
bool fromXmlPriv(const QDomElement &xml_element) override;
|
||||
|
||||
static QHash<QString, XRefProperties> defaultProperties();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user