This commit is contained in:
Martin Marmsoler
2020-08-24 20:34:18 +02:00
parent 385d0ffd69
commit a10709157d
27 changed files with 276 additions and 167 deletions

View File

@@ -25,6 +25,7 @@ namespace {
const QString doubleS = "double";
const QString boolS = "bool";
const QString stringS = "string";
const QString uuidS = "uuid";
}
PropertiesInterface::PropertiesInterface()
@@ -63,11 +64,19 @@ QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QStr
return p;
}
QDomElement PropertiesInterface::createXmlProperty(QDomDocument& doc, const QString& name, const QUuid value) const {
QDomElement p = doc.createElement("property");
p.setAttribute("name", name);
p.setAttribute("type", uuidS);
p.setAttribute("value", value.toString());
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))
return QDomElement();
continue; // there might also non property childs
if (child.attribute("name") == name)
return child;
@@ -155,12 +164,12 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDo
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool defaulValue) {
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean, bool defaultValue) {
QString attr;
if (!attribute(e, attribute_name, integerS, &attr)) {
*boolean = defaulValue;
*boolean = defaultValue;
return PropertyFlags::NotFound;
}
@@ -176,6 +185,20 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomE
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid, QUuid defaultValue) {
QString attr;
if (!attribute(e, attribute_name, uuidS, &attr)) {
*uuid = defaultValue;
return PropertyFlags::NotFound;
}
if (uuid != nullptr)
*uuid = QUuid(attr);
return PropertyFlags::Success;
}
PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDomElement& e, const QString& attribute_name, QString* string, QString defaultValue) {
QString attr;

View File

@@ -23,6 +23,7 @@
#include <QDomElement>
#include <limits>
#include "qet.h"
#include <QUuid>
/**
* @brief The PropertiesInterface class
@@ -33,8 +34,8 @@ 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 =0;
virtual void fromSettings (const QSettings &settings, const QString& = QString()) =0;
// Save/load properties to xml element
virtual QDomElement toXml (QDomDocument &xml_document) const =0;
virtual bool fromXml (const QDomElement &xml_element) =0;
@@ -47,12 +48,13 @@ class PropertiesInterface
QDomElement createXmlProperty(QDomDocument& doc, const QString& name, const int value) const;
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;
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,
Success = 0,
NotFound,
NoValidConversion,
};
@@ -60,7 +62,8 @@ class PropertiesInterface
static PropertyFlags propertyInteger(const QDomElement &e, const QString& attribute_name, int *entier = nullptr, int defaultValue = std::numeric_limits<int>::quiet_NaN());
static PropertyFlags propertyDouble(const QDomElement &e, const QString& attribute_name, double *reel = nullptr, double defaultValue = std::numeric_limits<double>::quiet_NaN());
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 defaulValue = false);
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 bool validXmlProperty(const QDomElement& e);

View File

@@ -41,7 +41,7 @@ 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";
settings.setValue(prefix + "displayhas", display);
@@ -69,7 +69,7 @@ void XRefProperties::toSettings(QSettings &settings, const QString prefix) const
* @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();

View File

@@ -40,8 +40,8 @@ class XRefProperties : public PropertiesInterface
Label
};
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;
QDomElement toXml (QDomDocument &xml_document) const override;
bool fromXml(const QDomElement &xml_element) override;
bool valideXml(QDomElement& element) const override;