mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-30 15:50:52 +01:00
replace 4 spaces by a tab
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "propertiesinterface.h"
|
||||
|
||||
@@ -21,99 +21,99 @@
|
||||
* 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";
|
||||
const QString integerS = "int";
|
||||
const QString doubleS = "double";
|
||||
const QString boolS = "bool";
|
||||
const QString stringS = "string";
|
||||
const QString uuidS = "uuid";
|
||||
const QString colorS = "color";
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PropertiesInterface::PropertiesInterface
|
||||
@brief PropertiesInterface::PropertiesInterface
|
||||
*/
|
||||
PropertiesInterface::PropertiesInterface()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@brief 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;
|
||||
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 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 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 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 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 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 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 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
|
||||
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();
|
||||
if (child.attribute("name") == name)
|
||||
return child;
|
||||
}
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -126,27 +126,27 @@ QDomElement PropertiesInterface::property(const QDomElement& e, const QString& n
|
||||
* \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;
|
||||
}
|
||||
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);
|
||||
*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;
|
||||
}
|
||||
} 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");
|
||||
*attr = p.attribute("value");
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -156,132 +156,132 @@ bool PropertiesInterface::attribute(const QDomElement& e, const QString& attribu
|
||||
* \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
|
||||
* \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;
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, integerS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
if (entier != nullptr)
|
||||
*entier = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyDouble(const QDomElement &e, const QString& attribute_name, double* reel) {
|
||||
|
||||
QString attr;
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, doubleS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
if (reel != nullptr)
|
||||
*reel = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyBool(const QDomElement &e, const QString& attribute_name, bool* boolean) {
|
||||
|
||||
QString attr;
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, boolS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
if (boolean != nullptr)
|
||||
*boolean = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyColor(const QDomElement &e, const QString& attribute_name, QColor* color) {
|
||||
|
||||
QString attr;
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, colorS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
if (color != nullptr)
|
||||
*color = tmp;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
PropertiesInterface::PropertyFlags PropertiesInterface::propertyUuid(const QDomElement &e, const QString& attribute_name, QUuid* uuid) {
|
||||
QString attr;
|
||||
QString attr;
|
||||
|
||||
if (!attribute(e, attribute_name, uuidS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
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 (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);
|
||||
if (uuid != nullptr)
|
||||
*uuid = QUuid(attr);
|
||||
|
||||
return PropertyFlags::Success;
|
||||
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;
|
||||
}
|
||||
QString attr;
|
||||
if (!attribute(e, attribute_name, stringS, &attr)) {
|
||||
return PropertyFlags::NotFound;
|
||||
}
|
||||
|
||||
// verifie la validite de l'attribut
|
||||
if (string != nullptr)
|
||||
*string = attr;
|
||||
// verifie la validite de l'attribut
|
||||
if (string != nullptr)
|
||||
*string = attr;
|
||||
|
||||
return PropertyFlags::Success;
|
||||
return PropertyFlags::Success;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -291,47 +291,47 @@ PropertiesInterface::PropertyFlags PropertiesInterface::propertyString(const QDo
|
||||
* \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("name"))
|
||||
return false;
|
||||
|
||||
if (!e.hasAttribute("type"))
|
||||
return false;
|
||||
if (!e.hasAttribute("type"))
|
||||
return false;
|
||||
|
||||
if (!e.hasAttribute("value"))
|
||||
return false;
|
||||
if (!e.hasAttribute("value"))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
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
|
||||
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'
|
||||
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
|
||||
@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);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PROPERTIESINTERFACE_H
|
||||
#define PROPERTIESINTERFACE_H
|
||||
@@ -27,100 +27,100 @@
|
||||
#include <QUuid>
|
||||
|
||||
/**
|
||||
@brief The PropertiesInterface class
|
||||
This class is an interface for have common way
|
||||
to use properties in QElectroTech
|
||||
@brief The PropertiesInterface class
|
||||
This class is an interface for have common way
|
||||
to use properties in QElectroTech
|
||||
*/
|
||||
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;
|
||||
static bool valideXml(QDomElement& element);
|
||||
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;
|
||||
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);
|
||||
/*!
|
||||
* 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);
|
||||
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
|
||||
};
|
||||
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);
|
||||
/*!
|
||||
* 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);
|
||||
static bool validXmlProperty(const QDomElement& e);
|
||||
|
||||
QVariant XmlProperty(const QDomElement& element);
|
||||
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);
|
||||
/**
|
||||
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);
|
||||
/**
|
||||
@param o une orientation
|
||||
@return une chaine de caractere representant l'orientation
|
||||
*/
|
||||
static QString orientationToString(Qet::Orientation o);
|
||||
};
|
||||
|
||||
#endif // PROPERTIESINTERFACE_H
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
#include <QGraphicsObject>
|
||||
|
||||
TerminalData::TerminalData():
|
||||
PropertiesInterface()
|
||||
PropertiesInterface()
|
||||
{
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
TerminalData::TerminalData(QGraphicsObject *parent):
|
||||
PropertiesInterface(),
|
||||
q(parent)
|
||||
PropertiesInterface(),
|
||||
q(parent)
|
||||
{
|
||||
init();
|
||||
init();
|
||||
}
|
||||
|
||||
void TerminalData::init()
|
||||
@@ -25,135 +25,135 @@ TerminalData::~TerminalData()
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::setParent
|
||||
@param parent
|
||||
@brief TerminalData::setParent
|
||||
@param parent
|
||||
*/
|
||||
void TerminalData::setParent(QGraphicsObject* parent)
|
||||
{
|
||||
q = parent;
|
||||
q = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::toSettings
|
||||
Save properties to setting file.
|
||||
@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
|
||||
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
|
||||
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
Q_UNUSED(prefix);
|
||||
Q_UNUSED(settings);
|
||||
Q_UNUSED(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::fromSettings
|
||||
load properties to setting file.
|
||||
@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
|
||||
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)
|
||||
{
|
||||
Q_UNUSED(settings);
|
||||
Q_UNUSED(prefix);
|
||||
Q_UNUSED(settings);
|
||||
Q_UNUSED(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief TerminalData::toXml
|
||||
Save properties to xml element
|
||||
write the name, number, position and orientation of the terminal
|
||||
to xml_element
|
||||
@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 xml_document
|
||||
@return xml_element : DomElement with
|
||||
the name, number, position and orientation of the terminal
|
||||
@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
|
||||
the name, number, position and orientation of the terminal
|
||||
*/
|
||||
QDomElement TerminalData::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
QDomElement xml_element = xml_document.createElement("terminaldata");
|
||||
QDomElement xml_element = xml_document.createElement("terminaldata");
|
||||
|
||||
// write the position of the terminal
|
||||
// Write name and number to XML
|
||||
// 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)));
|
||||
// write the position of the terminal
|
||||
// Write name and number to XML
|
||||
// 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);
|
||||
return(xml_element);
|
||||
}
|
||||
|
||||
/*
|
||||
@brief TerminalData::fromXml
|
||||
load properties to 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
|
||||
@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) // RETURNS True
|
||||
{
|
||||
qreal term_x = 0.0;
|
||||
qreal term_y = 0.0;
|
||||
qreal term_x = 0.0;
|
||||
qreal term_y = 0.0;
|
||||
|
||||
// reads the position of the terminal
|
||||
// lit la position de la borne
|
||||
// reads the position of the terminal
|
||||
// lit la position de la borne
|
||||
|
||||
if (propertyDouble(xml_element, "x", &term_x))
|
||||
return false;
|
||||
if (propertyDouble(xml_element, "x", &term_x))
|
||||
return false;
|
||||
|
||||
if (propertyDouble(xml_element, "y", &term_y))
|
||||
return false;
|
||||
if (propertyDouble(xml_element, "y", &term_y))
|
||||
return false;
|
||||
|
||||
m_pos = QPointF(term_x, term_y);
|
||||
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.
|
||||
// if the attribute not exists, means, the element is created with an
|
||||
// older version of qet. So use the legacy approach
|
||||
// do not write uuid from this class, because only PartTerminal::fromXml need
|
||||
// to write it to xml file. Terminal::fromXml does not need.
|
||||
// if the attribute not exists, means, the element is created with an
|
||||
// older version of qet. So use the legacy approach
|
||||
|
||||
|
||||
//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"
|
||||
//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;
|
||||
QString o;
|
||||
if (propertyString(xml_element, "orientation", &o))
|
||||
return false;
|
||||
|
||||
// read the orientation of the terminal
|
||||
// lit l'orientation de la borne
|
||||
m_orientation = Qet::orientationFromString(
|
||||
xml_element.attribute("orientation"));
|
||||
return true;
|
||||
// read the orientation of the terminal
|
||||
// lit l'orientation de la borne
|
||||
m_orientation = Qet::orientationFromString(
|
||||
xml_element.attribute("orientation"));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TerminalData::valideXml(const QDomElement& xml_element) {
|
||||
if (propertyDouble(xml_element, "x"))
|
||||
return false;
|
||||
if (propertyDouble(xml_element, "x"))
|
||||
return false;
|
||||
|
||||
if (propertyDouble(xml_element, "y"))
|
||||
return false;
|
||||
if (propertyDouble(xml_element, "y"))
|
||||
return false;
|
||||
|
||||
// legacy elements do not have an uuid
|
||||
// if (propertyUuid(xml_element, "uuid"))
|
||||
// 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, "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;
|
||||
if (propertyString(xml_element, "orientation"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,78 +10,78 @@
|
||||
class QGraphicsObject;
|
||||
|
||||
/**
|
||||
@brief The TerminalData class
|
||||
Data of the terminal.
|
||||
Stored in extra class so it can be used by PartTerminal
|
||||
and Terminal without defining everything again.
|
||||
@note tis class needs to be work on
|
||||
@brief The TerminalData class
|
||||
Data of the terminal.
|
||||
Stored in extra class so it can be used by PartTerminal
|
||||
and Terminal without defining everything again.
|
||||
@note tis class needs to be work on
|
||||
*/
|
||||
class TerminalData : public PropertiesInterface
|
||||
{
|
||||
public:
|
||||
TerminalData();
|
||||
TerminalData(QGraphicsObject* parent);
|
||||
~TerminalData();
|
||||
public:
|
||||
TerminalData();
|
||||
TerminalData(QGraphicsObject* parent);
|
||||
~TerminalData();
|
||||
|
||||
void init();
|
||||
void init();
|
||||
|
||||
void setParent(QGraphicsObject* parent);
|
||||
void toSettings(QSettings &settings,
|
||||
const QString prefix = QString()) const override;
|
||||
void toSettings(QSettings &settings, const QString& = QString()) const override;
|
||||
void fromSettings(const QSettings &settings, const QString& = QString()) override;
|
||||
QDomElement toXml(QDomDocument &xml_element) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
void setParent(QGraphicsObject* parent);
|
||||
void toSettings(QSettings &settings,
|
||||
const QString prefix = QString()) const override;
|
||||
void toSettings(QSettings &settings, const QString& = QString()) const override;
|
||||
void fromSettings(const QSettings &settings, const QString& = QString()) override;
|
||||
QDomElement toXml(QDomDocument &xml_element) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
|
||||
static bool valideXml(const QDomElement &xml_element);
|
||||
static bool valideXml(const QDomElement &xml_element);
|
||||
|
||||
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.
|
||||
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;
|
||||
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
|
||||
@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{0,0};
|
||||
private:
|
||||
QGraphicsObject* q{nullptr};
|
||||
/**
|
||||
@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{0,0};
|
||||
private:
|
||||
QGraphicsObject* q{nullptr};
|
||||
};
|
||||
|
||||
#endif // TERMINALDATA_H
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <QMetaEnum>
|
||||
#include <QHash>
|
||||
@@ -22,176 +22,176 @@
|
||||
#include "qetapp.h"
|
||||
|
||||
/**
|
||||
@brief XRefProperties::XRefProperties
|
||||
Default Constructor
|
||||
@brief XRefProperties::XRefProperties
|
||||
Default Constructor
|
||||
*/
|
||||
XRefProperties::XRefProperties()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::toSettings
|
||||
Save to settings
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
@brief XRefProperties::toSettings
|
||||
Save to settings
|
||||
@param settings: QSettings to use
|
||||
@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";
|
||||
settings.setValue(prefix + "displayhas", display);
|
||||
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
||||
settings.setValue(prefix + "snapto", snap);
|
||||
int offset = m_offset;
|
||||
settings.setValue(prefix + "offset", offset);
|
||||
QString master_label = m_master_label;
|
||||
settings.setValue(prefix + "master_label", master_label);
|
||||
QString slave_label = m_slave_label;
|
||||
settings.setValue(prefix + "slave_label", slave_label);
|
||||
settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
|
||||
QString display = m_display == Cross? "cross" : "contacts";
|
||||
settings.setValue(prefix + "displayhas", display);
|
||||
QString snap = m_snap_to == Bottom? "bottom" : "label";
|
||||
settings.setValue(prefix + "snapto", snap);
|
||||
int offset = m_offset;
|
||||
settings.setValue(prefix + "offset", offset);
|
||||
QString master_label = m_master_label;
|
||||
settings.setValue(prefix + "master_label", master_label);
|
||||
QString slave_label = m_slave_label;
|
||||
settings.setValue(prefix + "slave_label", slave_label);
|
||||
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
settings.setValue(prefix + "xrefpos", var.valueToKey(m_xref_pos));
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
settings.setValue(prefix + "xrefpos", var.valueToKey(m_xref_pos));
|
||||
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
settings.setValue(prefix + key + "prefix", m_prefix.value(key));
|
||||
}
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
settings.setValue(prefix + key + "prefix", m_prefix.value(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::fromSettings
|
||||
load from settings
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
@brief XRefProperties::fromSettings
|
||||
load from settings
|
||||
@param settings: QSettings to use
|
||||
@param prefix: prefix before properties name
|
||||
*/
|
||||
void XRefProperties::fromSettings(const QSettings &settings,
|
||||
const QString prefix)
|
||||
const QString prefix)
|
||||
{
|
||||
m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool();
|
||||
QString display = settings.value(prefix + "displayhas", "cross").toString();
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
QString snap = settings.value(prefix + "snapto", "label").toString();
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
m_offset = settings.value(prefix + "offset", "0").toInt();
|
||||
m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
|
||||
m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
|
||||
m_show_power_ctc = settings.value(prefix + "showpowerctc", true).toBool();
|
||||
QString display = settings.value(prefix + "displayhas", "cross").toString();
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
QString snap = settings.value(prefix + "snapto", "label").toString();
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
m_offset = settings.value(prefix + "offset", "0").toInt();
|
||||
m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
|
||||
m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
|
||||
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue((settings.value(prefix + "xrefpos").toString()).toStdString().data()));
|
||||
QMetaEnum var = QMetaEnum::fromType<Qt::Alignment>();
|
||||
m_xref_pos = Qt::AlignmentFlag(var.keyToValue((settings.value(prefix + "xrefpos").toString()).toStdString().data()));
|
||||
|
||||
for (QString key : m_prefix_keys) {
|
||||
m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
|
||||
}
|
||||
for (QString key : m_prefix_keys) {
|
||||
m_prefix.insert(key, settings.value(prefix + key + "prefix").toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::toXml
|
||||
Save to xml
|
||||
@param xml_document : QDomElement to use for saving
|
||||
@return QDomElement
|
||||
@brief XRefProperties::toXml
|
||||
Save to xml
|
||||
@param xml_document : QDomElement to use for saving
|
||||
@return QDomElement
|
||||
*/
|
||||
QDomElement XRefProperties::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
|
||||
QDomElement xml_element = xml_document.createElement("xref");
|
||||
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"));
|
||||
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.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));
|
||||
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));
|
||||
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key)));
|
||||
}
|
||||
foreach (QString key, m_prefix.keys()) {
|
||||
xml_element.appendChild(createXmlProperty(xml_document, key + "prefix", m_prefix.value(key)));
|
||||
}
|
||||
|
||||
return xml_element;
|
||||
return xml_element;
|
||||
}
|
||||
|
||||
/** RETURNS True
|
||||
@brief XRefProperties::fromXml
|
||||
Load from xml
|
||||
@param xml_element: QDomElement to use for load
|
||||
@brief XRefProperties::fromXml
|
||||
Load from xml
|
||||
@param xml_element: QDomElement to use for load
|
||||
*/
|
||||
bool XRefProperties::fromXml(const QDomElement &xml_element) {
|
||||
|
||||
if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
|
||||
return false;
|
||||
if (propertyBool(xml_element, "showpowerctc", &m_show_power_ctc))
|
||||
return false;
|
||||
|
||||
QString display;
|
||||
if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) {
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
}
|
||||
QString display;
|
||||
if (propertyString(xml_element, "displayhas", &display) != PropertyFlags::NotFound) {
|
||||
display == "cross"? m_display = Cross : m_display = Contacts;
|
||||
}
|
||||
|
||||
|
||||
QString snap;
|
||||
if (propertyString(xml_element, "snapto", &snap) != PropertyFlags::NotFound) {
|
||||
snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
|
||||
}
|
||||
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) {
|
||||
if (!propertyString(xml_element, key + "prefix", &value));
|
||||
m_prefix.insert(key, value);
|
||||
}
|
||||
return true;
|
||||
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) {
|
||||
if (!propertyString(xml_element, key + "prefix", &value));
|
||||
m_prefix.insert(key, value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief XRefProperties::defaultProperties
|
||||
@return the default properties stored in the setting file
|
||||
For the xref, there is 2 propreties.
|
||||
For coil, stored with the string "coil" in the returned QHash.
|
||||
For protection, stored with the string "protection" in the returned QHash.
|
||||
@brief XRefProperties::defaultProperties
|
||||
@return the default properties stored in the setting file
|
||||
For the xref, there is 2 propreties.
|
||||
For coil, stored with the string "coil" in the returned QHash.
|
||||
For protection, stored with the string "protection" in the returned QHash.
|
||||
*/
|
||||
QHash<QString, XRefProperties> XRefProperties::defaultProperties()
|
||||
{
|
||||
QHash <QString, XRefProperties> hash;
|
||||
QStringList keys;
|
||||
keys << "coil" << "protection" << "commutator";
|
||||
QHash <QString, XRefProperties> hash;
|
||||
QStringList keys;
|
||||
keys << "coil" << "protection" << "commutator";
|
||||
|
||||
QSettings settings;
|
||||
QSettings settings;
|
||||
|
||||
foreach (QString key, keys)
|
||||
{
|
||||
XRefProperties properties;
|
||||
QString str("diagrameditor/defaultxref");
|
||||
properties.fromSettings(settings, str += key);
|
||||
hash.insert(key, properties);
|
||||
}
|
||||
foreach (QString key, keys)
|
||||
{
|
||||
XRefProperties properties;
|
||||
QString str("diagrameditor/defaultxref");
|
||||
properties.fromSettings(settings, str += key);
|
||||
hash.insert(key, properties);
|
||||
}
|
||||
|
||||
return hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool XRefProperties::operator ==(const XRefProperties &xrp) const{
|
||||
return (m_show_power_ctc == xrp.m_show_power_ctc &&
|
||||
m_display == xrp.m_display &&
|
||||
m_snap_to == xrp.m_snap_to &&
|
||||
m_prefix == xrp.m_prefix &&
|
||||
m_master_label == xrp.m_master_label &&
|
||||
m_offset == xrp.m_offset &&
|
||||
m_xref_pos == xrp.m_xref_pos );
|
||||
return (m_show_power_ctc == xrp.m_show_power_ctc &&
|
||||
m_display == xrp.m_display &&
|
||||
m_snap_to == xrp.m_snap_to &&
|
||||
m_prefix == xrp.m_prefix &&
|
||||
m_master_label == xrp.m_master_label &&
|
||||
m_offset == xrp.m_offset &&
|
||||
m_xref_pos == xrp.m_xref_pos );
|
||||
}
|
||||
|
||||
bool XRefProperties::operator !=(const XRefProperties &xrp) const
|
||||
{
|
||||
return (! (*this == xrp));
|
||||
return (! (*this == xrp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef XREFPROPERTIES_H
|
||||
#define XREFPROPERTIES_H
|
||||
@@ -24,72 +24,72 @@
|
||||
#include "propertiesinterface.h"
|
||||
|
||||
/**
|
||||
@brief The XRefProperties class
|
||||
this class store properties used by XrefItem
|
||||
@brief The XRefProperties class
|
||||
this class store properties used by XrefItem
|
||||
*/
|
||||
class XRefProperties : public PropertiesInterface
|
||||
{
|
||||
public:
|
||||
XRefProperties();
|
||||
public:
|
||||
XRefProperties();
|
||||
|
||||
enum DisplayHas {
|
||||
Cross,
|
||||
Contacts
|
||||
};
|
||||
enum DisplayHas {
|
||||
Cross,
|
||||
Contacts
|
||||
};
|
||||
|
||||
enum SnapTo {
|
||||
Bottom,
|
||||
Label
|
||||
};
|
||||
enum SnapTo {
|
||||
Bottom,
|
||||
Label
|
||||
};
|
||||
|
||||
void toSettings (QSettings &settings, const QString& = QString()) const override;
|
||||
void fromSettings (const QSettings &settings, const QString& = QString()) override;
|
||||
void fromSettings (const QSettings &settings,
|
||||
const QString = QString()) override;
|
||||
QDomElement toXml (QDomDocument &xml_document) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
void toSettings (QSettings &settings, const QString& = QString()) const override;
|
||||
void fromSettings (const QSettings &settings, const QString& = QString()) 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();
|
||||
static QHash<QString, XRefProperties> defaultProperties();
|
||||
|
||||
bool operator == (const XRefProperties &xrp) const;
|
||||
bool operator != (const XRefProperties &xrp) const;
|
||||
bool operator == (const XRefProperties &xrp) const;
|
||||
bool operator != (const XRefProperties &xrp) const;
|
||||
|
||||
void setShowPowerContac (const bool a) {m_show_power_ctc = a;}
|
||||
bool showPowerContact () const {return m_show_power_ctc;}
|
||||
void setShowPowerContac (const bool a) {m_show_power_ctc = a;}
|
||||
bool showPowerContact () const {return m_show_power_ctc;}
|
||||
|
||||
void setDisplayHas (const DisplayHas dh) {m_display = dh;}
|
||||
DisplayHas displayHas () const {return m_display;}
|
||||
void setDisplayHas (const DisplayHas dh) {m_display = dh;}
|
||||
DisplayHas displayHas () const {return m_display;}
|
||||
|
||||
void setSnapTo (const SnapTo st) {m_snap_to = st;}
|
||||
SnapTo snapTo () const {return m_snap_to;}
|
||||
void setSnapTo (const SnapTo st) {m_snap_to = st;}
|
||||
SnapTo snapTo () const {return m_snap_to;}
|
||||
|
||||
void setXrefPos(const Qt::AlignmentFlag xref) {m_xref_pos = xref;}
|
||||
Qt::AlignmentFlag getXrefPos() const {return m_xref_pos;}
|
||||
void setPrefix (const QString &key, const QString &value) {m_prefix.insert(key, value);}
|
||||
QString prefix (const QString &key) const {return m_prefix.value(key);}
|
||||
void setXrefPos(const Qt::AlignmentFlag xref) {m_xref_pos = xref;}
|
||||
Qt::AlignmentFlag getXrefPos() const {return m_xref_pos;}
|
||||
void setPrefix (const QString &key, const QString &value) {m_prefix.insert(key, value);}
|
||||
QString prefix (const QString &key) const {return m_prefix.value(key);}
|
||||
|
||||
void setMasterLabel (const QString master) {m_master_label = master;}
|
||||
QString masterLabel () const {return m_master_label;}
|
||||
void setMasterLabel (const QString master) {m_master_label = master;}
|
||||
QString masterLabel () const {return m_master_label;}
|
||||
|
||||
void setSlaveLabel(const QString slave) {m_slave_label = slave;}
|
||||
QString slaveLabel () const {return m_slave_label;}
|
||||
void setSlaveLabel(const QString slave) {m_slave_label = slave;}
|
||||
QString slaveLabel () const {return m_slave_label;}
|
||||
|
||||
void setOffset(const int offset) {m_offset = offset;}
|
||||
int offset() const {return m_offset;}
|
||||
void setOffset(const int offset) {m_offset = offset;}
|
||||
int offset() const {return m_offset;}
|
||||
|
||||
void setKey(QString& key) {m_key = key;}
|
||||
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};
|
||||
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};
|
||||
QString m_key;
|
||||
private:
|
||||
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{"power","delay","switch"};
|
||||
QString m_master_label{"%f-%l%c"};
|
||||
QString m_slave_label{"(%f-%l%c)"};
|
||||
int m_offset{0};
|
||||
QString m_key;
|
||||
};
|
||||
|
||||
#endif // XREFPROPERTIES_H
|
||||
|
||||
Reference in New Issue
Block a user