mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Add element data class
This commit is contained in:
parent
dea926e4b4
commit
ffe3d98279
232
sources/properties/elementdata.cpp
Normal file
232
sources/properties/elementdata.cpp
Normal file
@ -0,0 +1,232 @@
|
||||
/*
|
||||
Copyright 2006-2021 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 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/>.
|
||||
*/
|
||||
#include "elementdata.h"
|
||||
#include "../qetxml.h"
|
||||
#include <QDebug>
|
||||
|
||||
void ElementData::toSettings(QSettings &settings, const QString prefix) const {
|
||||
Q_UNUSED(settings)
|
||||
Q_UNUSED(prefix)
|
||||
}
|
||||
|
||||
void ElementData::fromSettings(const QSettings &settings, const QString prefix) {
|
||||
Q_UNUSED(settings)
|
||||
Q_UNUSED(prefix)
|
||||
}
|
||||
|
||||
QDomElement ElementData::toXml(QDomDocument &xml_element) const {
|
||||
Q_UNUSED(xml_element)
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementData::fromXml
|
||||
* load properties from xml element.
|
||||
* The tag name of xml_element must be definition
|
||||
* and have an attribute "type"
|
||||
* @param xml_element : tagName must be 'definition'
|
||||
* @return true is successfuly loaded
|
||||
*/
|
||||
bool ElementData::fromXml(const QDomElement &xml_element)
|
||||
{
|
||||
if(xml_element.tagName() != "definition" ||
|
||||
xml_element.attribute("type") != "element") {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_type = typeFromString(xml_element.attribute("link_type", "simple"));
|
||||
kindInfoFromXml(xml_element);
|
||||
m_informations.fromXml(xml_element.firstChildElement("elementInformations"),
|
||||
"elementInformation");
|
||||
m_names_list.fromXml(xml_element);
|
||||
|
||||
auto xml_draw_info = xml_element.firstChildElement("informations");
|
||||
if(xml_draw_info.tagName() == "informations") {
|
||||
m_drawing_information = xml_draw_info.text();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString ElementData::typeToString(ElementData::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case ElementData::Simple :
|
||||
return QString("simple");
|
||||
case ElementData::NextReport :
|
||||
return QString ("next_report");
|
||||
case ElementData::PreviousReport :
|
||||
return QString("previous_report");
|
||||
case ElementData::Master :
|
||||
return QString("master");
|
||||
case ElementData::Slave :
|
||||
return QString("slave");
|
||||
case ElementData::Terminale :
|
||||
return QString("terminal");
|
||||
default:
|
||||
qDebug() << "ElementData::typeToString : type don't exist"
|
||||
<< "return failsafe value 'simple'";
|
||||
return QString("simple");
|
||||
}
|
||||
}
|
||||
|
||||
ElementData::Type ElementData::typeFromString(const QString &string)
|
||||
{
|
||||
if (string == "simple") {
|
||||
return ElementData::Simple;
|
||||
} else if (string == "next_report") {
|
||||
return ElementData::NextReport;
|
||||
} else if (string == "previous_report") {
|
||||
return ElementData::PreviousReport;
|
||||
} else if (string == "master") {
|
||||
return ElementData::Master;
|
||||
} else if (string == "slave") {
|
||||
return ElementData::Slave;
|
||||
} else if (string == "terminal") {
|
||||
return ElementData::Terminale;
|
||||
}
|
||||
|
||||
//Return simple if nothing match
|
||||
qDebug() << "ElementData::typeFromString : string "
|
||||
<< string
|
||||
<< " don't exist, return failsafe value 'simple";
|
||||
return ElementData::Simple;
|
||||
}
|
||||
|
||||
QString ElementData::masterTypeToString(ElementData::MasterType type)
|
||||
{
|
||||
switch (type) {
|
||||
case ElementData::Coil:
|
||||
return QString ("coil");
|
||||
case ElementData::Protection:
|
||||
return QString ("protection");
|
||||
case ElementData::Commutator:
|
||||
return QString ("commutator");
|
||||
}
|
||||
}
|
||||
|
||||
ElementData::MasterType ElementData::masterTypeFromString(const QString &string)
|
||||
{
|
||||
if (string == "coil") {
|
||||
return ElementData::Coil;
|
||||
} else if (string == "protection") {
|
||||
return ElementData::Protection;
|
||||
} else if (string == "commutator") {
|
||||
return ElementData::Commutator;
|
||||
}
|
||||
|
||||
qDebug() << "ElementData::masterTypeFromString : string "
|
||||
<< string
|
||||
<< " don't exist, return failsafe value 'coil'";
|
||||
return ElementData::Coil;
|
||||
}
|
||||
|
||||
QString ElementData::slaveTypeToString(ElementData::SlaveType type)
|
||||
{
|
||||
switch (type) {
|
||||
case ElementData::SSimple:
|
||||
return QString ("simple");
|
||||
case ElementData::Power:
|
||||
return QString ("power");
|
||||
case ElementData::DelayOn:
|
||||
return QString("delayOn");
|
||||
case ElementData::DelayOff:
|
||||
return QString("delayOff");
|
||||
case ElementData::delayOnOff:
|
||||
return QString("delayOnOff");
|
||||
}
|
||||
}
|
||||
|
||||
ElementData::SlaveType ElementData::slaveTypeFromString(const QString &string)
|
||||
{
|
||||
if (string == "simple") {
|
||||
return ElementData::SSimple;
|
||||
} else if (string == "power") {
|
||||
return ElementData::Power;
|
||||
} else if (string == "delayOn") {
|
||||
return ElementData::DelayOn;
|
||||
} else if (string == "delayOff") {
|
||||
return ElementData::DelayOff;
|
||||
} else if (string == "delayOnOff") {
|
||||
return ElementData::delayOnOff;
|
||||
}
|
||||
|
||||
qDebug() << "ElementData::slaveTypeFromSting : string "
|
||||
<< string
|
||||
<< " don't exist, return failsafe value 'simple'";
|
||||
return ElementData::SSimple;
|
||||
}
|
||||
|
||||
QString ElementData::slaveStateToString(ElementData::SlaveState type)
|
||||
{
|
||||
switch (type) {
|
||||
case NO:
|
||||
return QString("NO");
|
||||
case NC:
|
||||
return QString("NC");
|
||||
case SW:
|
||||
return QString("SW");
|
||||
}
|
||||
}
|
||||
|
||||
ElementData::SlaveState ElementData::slaveStateFromString(const QString &string)
|
||||
{
|
||||
if (string == "NO") {
|
||||
return ElementData::NO;
|
||||
} else if (string == "NC") {
|
||||
return ElementData::NC;
|
||||
} else if (string == "SW") {
|
||||
return ElementData::SW;
|
||||
}
|
||||
|
||||
qDebug() << "ElementData::slaveStateFromString : string : "
|
||||
<< string
|
||||
<< " don't exist, return failsafe value 'NO'";
|
||||
return ElementData::NO;
|
||||
}
|
||||
|
||||
void ElementData::kindInfoFromXml(const QDomElement &xml_element)
|
||||
{
|
||||
if (m_type != ElementData::Master ||
|
||||
m_type != ElementData::Slave) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto xml_kind = xml_element.firstChildElement("kindInformations");
|
||||
for (auto dom_elmt : QETXML::findInDomElement(xml_kind, "kindInformation"))
|
||||
{
|
||||
if (!dom_elmt.hasAttribute("name")) {
|
||||
continue;
|
||||
}
|
||||
auto name = dom_elmt.attribute("name");
|
||||
|
||||
if (m_type == ElementData::Master &&
|
||||
name == "type") {
|
||||
m_master_type = masterTypeFromString(dom_elmt.text());
|
||||
}
|
||||
else if (m_type == ElementData::Slave ) {
|
||||
if (name == "type") {
|
||||
m_slave_type = slaveTypeFromString(dom_elmt.text());
|
||||
} else if (name == "state") {
|
||||
m_slave_state = slaveStateFromString(dom_elmt.text());
|
||||
} else if (name == "number") {
|
||||
m_contact_count = dom_elmt.text().toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
103
sources/properties/elementdata.h
Normal file
103
sources/properties/elementdata.h
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright 2006-2021 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 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/>.
|
||||
*/
|
||||
#ifndef ELEMENTDATA_H
|
||||
#define ELEMENTDATA_H
|
||||
|
||||
#include "propertiesinterface.h"
|
||||
#include "../diagramcontext.h"
|
||||
#include "../NameList/nameslist.h"
|
||||
|
||||
/**
|
||||
* @brief The ElementData class
|
||||
* WARNING
|
||||
* This class inherit from PropertiesInterface but
|
||||
* only fromXml is actually reimplemented.
|
||||
*/
|
||||
class ElementData : public PropertiesInterface
|
||||
{
|
||||
Q_GADGET
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
Simple = 1,
|
||||
NextReport = 2,
|
||||
PreviousReport = 4,
|
||||
AllReport = 6,
|
||||
Master = 8,
|
||||
Slave = 16,
|
||||
Terminale = 32};
|
||||
Q_ENUM(Type)
|
||||
|
||||
enum MasterType {
|
||||
Coil,
|
||||
Protection,
|
||||
Commutator
|
||||
};
|
||||
Q_ENUM(MasterType)
|
||||
|
||||
enum SlaveType {
|
||||
SSimple,
|
||||
Power,
|
||||
DelayOn,
|
||||
DelayOff,
|
||||
delayOnOff
|
||||
};
|
||||
Q_ENUM(SlaveType)
|
||||
|
||||
enum SlaveState {
|
||||
NO,
|
||||
NC,
|
||||
SW
|
||||
};
|
||||
Q_ENUM(SlaveState)
|
||||
|
||||
ElementData() {}
|
||||
~ElementData() override {}
|
||||
|
||||
void toSettings(QSettings &settings, const QString prefix = QString()) const override;
|
||||
void fromSettings(const QSettings &settings, const QString prefix = QString()) override;
|
||||
QDomElement toXml(QDomDocument &xml_element) const override;
|
||||
bool fromXml(const QDomElement &xml_element) override;
|
||||
|
||||
static QString typeToString(ElementData::Type type);
|
||||
static ElementData::Type typeFromString(const QString &string);
|
||||
|
||||
static QString masterTypeToString(ElementData::MasterType type);
|
||||
static ElementData::MasterType masterTypeFromString(const QString &string);
|
||||
|
||||
static QString slaveTypeToString (ElementData::SlaveType type);
|
||||
static ElementData::SlaveType slaveTypeFromString(const QString &string);
|
||||
|
||||
static QString slaveStateToString(ElementData::SlaveState type);
|
||||
static ElementData::SlaveState slaveStateFromString(const QString &string);
|
||||
|
||||
// must be public, because this class is a private member
|
||||
// of Element/ element editor and they must access this data
|
||||
ElementData::Type m_type = ElementData::Simple;
|
||||
ElementData::MasterType m_master_type = ElementData::Coil;
|
||||
ElementData::SlaveType m_slave_type = ElementData::SSimple;
|
||||
ElementData::SlaveState m_slave_state = ElementData::NO;
|
||||
int m_contact_count = 1;
|
||||
DiagramContext m_informations;
|
||||
NamesList m_names_list;
|
||||
QString m_drawing_information;
|
||||
|
||||
private:
|
||||
void kindInfoFromXml(const QDomElement &xml_element);
|
||||
};
|
||||
#endif // ELEMENTDATA_H
|
Loading…
x
Reference in New Issue
Block a user