mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
terminal strip can be saved to xml
This commit is contained in:
@@ -94,9 +94,37 @@ class RealTerminal
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief uuid
|
||||
* @return the uuid of this real terminal
|
||||
*/
|
||||
QUuid uuid() const {
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
static QString xmlTagName() {
|
||||
return QStringLiteral("real_terminal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief toXml
|
||||
* @param parent_document
|
||||
* @return this real terminal to xml
|
||||
*/
|
||||
QDomElement toXml(QDomDocument &parent_document) const
|
||||
{
|
||||
auto root_elmt = parent_document.createElement(this->xmlTagName());
|
||||
root_elmt.setAttribute("is_draw", m_element ? "true" : "false");
|
||||
root_elmt.setAttribute("uuid", m_element ? m_element->uuid().toString() :
|
||||
m_uuid.toString());
|
||||
|
||||
return root_elmt;
|
||||
}
|
||||
|
||||
private :
|
||||
QPointer<Element> m_element;
|
||||
QPointer<TerminalStrip> m_parent_terminal_strip;
|
||||
QUuid m_uuid = QUuid::createUuid();
|
||||
};
|
||||
|
||||
|
||||
@@ -182,6 +210,25 @@ class PhysicalTerminal
|
||||
return m_real_terminal;
|
||||
}
|
||||
|
||||
static QString xmlTagName() {
|
||||
return QStringLiteral("physical_terminal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief toXml
|
||||
* @param parent_document
|
||||
* @return this physical terminal to xml
|
||||
*/
|
||||
QDomElement toXml(QDomDocument &parent_document) const
|
||||
{
|
||||
auto root_elmt = parent_document.createElement(this->xmlTagName());
|
||||
for (auto &real_t : m_real_terminal) {
|
||||
root_elmt.appendChild(real_t->toXml(parent_document));
|
||||
}
|
||||
|
||||
return root_elmt;
|
||||
}
|
||||
|
||||
private:
|
||||
QPointer<TerminalStrip> m_parent_terminal_strip;
|
||||
QVector<shared_real_terminal> m_real_terminal;
|
||||
@@ -350,6 +397,27 @@ QVector<QPointer<Element> > TerminalStrip::terminalElement() const {
|
||||
return m_terminal_elements_vector;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::toXml
|
||||
* @param parent_document
|
||||
* @return
|
||||
*/
|
||||
QDomElement TerminalStrip::toXml(QDomDocument &parent_document)
|
||||
{
|
||||
auto root_elmt = parent_document.createElement(this->xmlTagName());
|
||||
|
||||
root_elmt.appendChild(m_data.toXml(parent_document));
|
||||
|
||||
//Undrawed terminals
|
||||
auto xml_layout = parent_document.createElement("layout");
|
||||
for (auto &phy_t : m_physical_terminals) {
|
||||
xml_layout.appendChild(phy_t->toXml(parent_document));
|
||||
}
|
||||
root_elmt.appendChild(xml_layout);
|
||||
|
||||
return root_elmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::realTerminal
|
||||
* @param terminal
|
||||
|
||||
@@ -60,6 +60,9 @@ class TerminalStrip : public QObject
|
||||
|
||||
QVector<QPointer<Element>> terminalElement() const;
|
||||
|
||||
static QString xmlTagName() {return QStringLiteral("terminal_strip");}
|
||||
QDomElement toXml(QDomDocument &parent_document);
|
||||
|
||||
private:
|
||||
QSharedPointer<RealTerminal> realTerminal(Element *terminal);
|
||||
QSharedPointer<PhysicalTerminal> physicalTerminal(QSharedPointer<RealTerminal> terminal);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "terminalstripdata.h"
|
||||
#include "../qetxml.h"
|
||||
#include <QDebug>
|
||||
|
||||
TerminalStripData::TerminalStripData()
|
||||
{
|
||||
@@ -24,10 +26,65 @@ TerminalStripData::TerminalStripData()
|
||||
|
||||
QDomElement TerminalStripData::toXml(QDomDocument &xml_document) const
|
||||
{
|
||||
auto root_elmt = xml_document.createElement(this->xmlTagName());
|
||||
|
||||
root_elmt.setAttribute(QStringLiteral("uuid"), m_uuid.toString());
|
||||
|
||||
auto info_elmt = xml_document.createElement("informations");
|
||||
root_elmt.appendChild(info_elmt);
|
||||
|
||||
if (!m_installation.isEmpty()) {
|
||||
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("installation"), m_installation));
|
||||
}
|
||||
if (!m_location.isEmpty()) {
|
||||
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("location"), m_location));
|
||||
}
|
||||
if (!m_name.isEmpty()) {
|
||||
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("name"), m_name));
|
||||
}
|
||||
if (!m_comment.isEmpty()) {
|
||||
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("comment"), m_comment));
|
||||
}
|
||||
if (!m_description.isEmpty()) {
|
||||
info_elmt.appendChild(infoToXml(xml_document, QStringLiteral("description"), m_description));
|
||||
}
|
||||
|
||||
return root_elmt;
|
||||
}
|
||||
|
||||
bool TerminalStripData::fromXml(const QDomElement &xml_element)
|
||||
{
|
||||
if (xml_element.tagName() != this->xmlTagName())
|
||||
{
|
||||
qDebug() << "TerminalStripData::fromXml : failed to load from xml " \
|
||||
"due to wrong tag name. Expected " << this->xmlTagName() << " used " << xml_element.tagName();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_uuid.fromString(xml_element.attribute("uuid"));
|
||||
|
||||
for (auto &xml_info :
|
||||
QETXML::findInDomElement(xml_element.firstChildElement("informations"),
|
||||
QStringLiteral("information")))
|
||||
{
|
||||
auto name = xml_info.attribute("name");
|
||||
auto value = xml_info.text();
|
||||
|
||||
if (name == QStringLiteral("installation")) { m_installation = value;}
|
||||
else if (name == QStringLiteral("location")) {m_location = value;}
|
||||
else if (name == QStringLiteral("name")) {m_name = value;}
|
||||
else if (name == QStringLiteral("comment")) {m_comment = value;}
|
||||
else if (name == QStringLiteral("description")) {m_description = value;}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QDomElement TerminalStripData::infoToXml(QDomDocument &xml_doc, const QString &name, const QString &value)
|
||||
{
|
||||
auto xml_elmt = xml_doc.createElement("information");
|
||||
xml_elmt.setAttribute(QStringLiteral("name"), name);
|
||||
xml_elmt.appendChild(xml_doc.createTextNode(value));
|
||||
|
||||
return xml_elmt;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,11 @@ class TerminalStripData : public PropertiesInterface
|
||||
QDomElement toXml (QDomDocument &xml_document) const override;
|
||||
bool fromXml (const QDomElement &xml_element) override;
|
||||
|
||||
static QString xmlTagName() {return QStringLiteral("terminal_strip_data");}
|
||||
|
||||
private :
|
||||
static QDomElement infoToXml(QDomDocument &xml_doc, const QString &name, const QString &value);
|
||||
|
||||
QString m_installation = QStringLiteral("="),
|
||||
m_location = QStringLiteral("+"),
|
||||
m_name,
|
||||
|
||||
@@ -913,6 +913,16 @@ QDomDocument QETProject::toXml()
|
||||
appended_diagram.toElement().setAttribute("order", order_num ++);
|
||||
}
|
||||
|
||||
//Write terminal strip to xml
|
||||
if (m_terminal_strip_vector.count())
|
||||
{
|
||||
auto xml_strip = xml_doc.createElement(QStringLiteral("terminal_strips"));
|
||||
for (auto &strip : m_terminal_strip_vector) {
|
||||
xml_strip.appendChild(strip->toXml(xml_doc));
|
||||
}
|
||||
project_root.appendChild(xml_strip);
|
||||
}
|
||||
|
||||
// Write the elements collection.
|
||||
project_root.appendChild(m_elements_collection->root().cloneNode(true));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user