mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-19 10:09:58 +01:00
go on with the work
This commit is contained in:
@@ -26,12 +26,18 @@ namespace {
|
||||
const QString boolS = "bool";
|
||||
const QString stringS = "string";
|
||||
const QString uuidS = "uuid";
|
||||
const QString colorS = "color";
|
||||
}
|
||||
|
||||
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) const {
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
@@ -44,7 +50,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", integerS);
|
||||
p.setAttribute("value", value);
|
||||
p.setAttribute("value", QString::number(value));
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -52,7 +58,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", doubleS);
|
||||
p.setAttribute("value", value);
|
||||
p.setAttribute("value", QString::number(value));
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -60,7 +66,7 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr
|
||||
QDomElement p = doc.createElement("property");
|
||||
p.setAttribute("name", name);
|
||||
p.setAttribute("type", boolS);
|
||||
p.setAttribute("value", value);
|
||||
p.setAttribute("value", QString::number(value));
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -72,6 +78,14 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr
|
||||
return p;
|
||||
}
|
||||
|
||||
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) const {
|
||||
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();
|
||||
@@ -86,7 +100,7 @@ QDomElement PropertiesInterface::property(const QDomElement& e, const QString& n
|
||||
|
||||
/*!
|
||||
* \brief PropertiesInterface::attribute
|
||||
* Returns the property with the name \p attribute_name
|
||||
* 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
|
||||
@@ -185,6 +199,26 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color, QColor defaultValue) {
|
||||
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, colorS, &attr)) {
|
||||
*color = defaultValue;
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
// verifie la validite de l'attribut
|
||||
QColor tmp = QColor(attr);
|
||||
if (!tmp.isValid())
|
||||
return PropertyFlags::NoValidConversion;
|
||||
|
||||
if (color != nullptr)
|
||||
*color = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, QUuid defaultValue) {
|
||||
QString attr;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QSettings>
|
||||
#include <QColor>
|
||||
#include <QDomElement>
|
||||
#include <limits>
|
||||
#include "qet.h"
|
||||
@@ -34,12 +35,12 @@ class PropertiesInterface
|
||||
public:
|
||||
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 =0;
|
||||
virtual void fromSettings (const QSettings &settings, const QString& = QString()) =0;
|
||||
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;
|
||||
virtual bool valideXml(QDomElement& element) const = 0;
|
||||
static bool valideXml(QDomElement& element);
|
||||
|
||||
/*!
|
||||
* Use this functions to add properties to the xml document
|
||||
@@ -49,14 +50,16 @@ class PropertiesInterface
|
||||
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const double value) const;
|
||||
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const bool value) const;
|
||||
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) const;
|
||||
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const QColor value) const;
|
||||
|
||||
static QDomElement property(const QDomElement& e, const QString& name);
|
||||
static bool attribute(const QDomElement& e, const QString& attribute_name, const QString& type, QString* attr);
|
||||
|
||||
typedef enum PropertyFlags {
|
||||
Success = 0,
|
||||
NotFound,
|
||||
NoValidConversion,
|
||||
NotFound = 1,
|
||||
NoValidConversion = 2,
|
||||
// = 4
|
||||
};
|
||||
|
||||
static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, int defaultValue = std::numeric_limits<int>::quiet_NaN());
|
||||
@@ -64,6 +67,8 @@ class PropertiesInterface
|
||||
static PropertyFlags propertyString(const QDomElement& e, const QString& attribute_name, QString* string = nullptr, QString defaultValue = QString());
|
||||
static PropertyFlags propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean = nullptr, bool defaultValue = false);
|
||||
static PropertyFlags propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid = nullptr, QUuid defaultValue = QUuid());
|
||||
static PropertyFlags propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color = nullptr, QColor defaultValue = QColor());
|
||||
|
||||
|
||||
static bool validXmlProperty(const QDomElement& e);
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ void TerminalData::setParent(QGraphicsObject* parent)
|
||||
q = parent;
|
||||
}
|
||||
|
||||
void TerminalData::toSettings(QSettings &settings, const QString) const
|
||||
void TerminalData::toSettings(QSettings& settings, const QString&) const
|
||||
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
}
|
||||
|
||||
void TerminalData::fromSettings(const QSettings &settings, const QString)
|
||||
void TerminalData::fromSettings(const QSettings& settings, const QString&)
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
}
|
||||
@@ -89,6 +89,20 @@ bool TerminalData::fromXml (const QDomElement &xml_element)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TerminalData::valideXml(QDomElement& element) const {
|
||||
bool TerminalData::valideXml(QDomElement& xml_element) {
|
||||
if (propertyDouble(xml_element, "x"))
|
||||
return false;
|
||||
|
||||
if (propertyDouble(xml_element, "y"))
|
||||
return false;
|
||||
|
||||
if (propertyString(xml_element, "uuid"))
|
||||
return false;
|
||||
|
||||
if (propertyString(xml_element, "name"))
|
||||
return false;
|
||||
|
||||
if (propertyString(xml_element, "orientation"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,30 +28,14 @@ public:
|
||||
void setParent(QGraphicsObject* parent);
|
||||
|
||||
// Save/load properties to setting file. QString is use for prefix a word befor the name of each paramètre
|
||||
void toSettings(QSettings &settings, const QString = QString()) const override;
|
||||
void fromSettings(const QSettings &settings, const QString = QString()) override;
|
||||
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;
|
||||
|
||||
bool valideXml(QDomElement &element) const override;
|
||||
|
||||
/**
|
||||
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);
|
||||
static bool valideXml(QDomElement &xml_element);
|
||||
|
||||
// must be public, because this class is a private member of PartTerminal/Terminal and they must
|
||||
// access this data
|
||||
|
||||
@@ -153,11 +153,6 @@ bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XRefProperties::valideXml(QDomElement& element) const {
|
||||
// TODO: implement
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XRefProperties::defaultProperties
|
||||
* @return the default properties stored in the setting file
|
||||
|
||||
@@ -44,7 +44,6 @@ class XRefProperties : public PropertiesInterface
|
||||
void fromSettings (const QSettings &settings, const QString& = QString()) override;
|
||||
QDomElement toXml (QDomDocument &xml_document) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
bool valideXml(QDomElement& element) const override;
|
||||
|
||||
static QHash<QString, XRefProperties> defaultProperties();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user