mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Read terminal strip from xml
This commit is contained in:
parent
89f3ce1eb3
commit
dbb21373e1
@ -19,6 +19,8 @@
|
||||
#include "../qetproject.h"
|
||||
#include "../qetgraphicsitem/element.h"
|
||||
#include "../qetgraphicsitem/terminalelement.h"
|
||||
#include "../elementprovider.h"
|
||||
#include "../qetxml.h"
|
||||
|
||||
using shared_real_terminal = QSharedPointer<RealTerminal>;
|
||||
using shared_physical_terminal = QSharedPointer<PhysicalTerminal>;
|
||||
@ -121,6 +123,36 @@ class RealTerminal
|
||||
return root_elmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief fromXml
|
||||
* @param xml_element
|
||||
* @return
|
||||
*/
|
||||
bool fromXml(QDomElement xml_element, const QVector<TerminalElement *> &terminal_vector)
|
||||
{
|
||||
if (xml_element.tagName() != xmlTagName()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto is_draw = xml_element.attribute(QStringLiteral("is_draw")) == QLatin1String("true")
|
||||
? true : false;
|
||||
auto uuid_ = QUuid::fromString(xml_element.attribute(QStringLiteral("uuid")));
|
||||
|
||||
if (is_draw) {
|
||||
for (auto terminal : terminal_vector) {
|
||||
if (terminal->uuid() == uuid_)
|
||||
{
|
||||
m_element = terminal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_uuid = uuid_;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private :
|
||||
QPointer<Element> m_element;
|
||||
QPointer<TerminalStrip> m_parent_terminal_strip;
|
||||
@ -241,6 +273,15 @@ class PhysicalTerminal
|
||||
/************************************************************************************/
|
||||
/************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::TerminalStrip
|
||||
* @param project
|
||||
*/
|
||||
TerminalStrip::TerminalStrip(QETProject *project) :
|
||||
QObject(project),
|
||||
m_project(project)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::TerminalStrip
|
||||
* @param installation
|
||||
@ -418,6 +459,59 @@ QDomElement TerminalStrip::toXml(QDomDocument &parent_document)
|
||||
return root_elmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::fromXml
|
||||
* @param xml_element
|
||||
* @return Set up this terminal strip from the xml description \p xml_element
|
||||
*/
|
||||
bool TerminalStrip::fromXml(QDomElement &xml_element)
|
||||
{
|
||||
if (xml_element.tagName() != xmlTagName()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Read terminal strip data
|
||||
auto xml_data = xml_element.firstChildElement(m_data.xmlTagName());
|
||||
if (!xml_data.isNull()) {
|
||||
m_data.fromXml(xml_data);
|
||||
}
|
||||
|
||||
//Read layout
|
||||
auto xml_layout = xml_element.firstChildElement(QStringLiteral("layout"));
|
||||
if (!xml_layout.isNull())
|
||||
{
|
||||
//Get all free elements terminal of the project
|
||||
ElementProvider ep(m_project);
|
||||
auto free_terminals = ep.freeTerminal();
|
||||
|
||||
//Read each physical terminal
|
||||
for(auto &xml_physical : QETXML::findInDomElement(xml_layout, PhysicalTerminal::xmlTagName()))
|
||||
{
|
||||
QVector<shared_real_terminal> real_t_vector;
|
||||
|
||||
//Read each real terminal of the current physical terminal of the loop
|
||||
for (auto &xml_real : QETXML::findInDomElement(xml_physical, RealTerminal::xmlTagName()))
|
||||
{
|
||||
shared_real_terminal real_t(new RealTerminal(this));
|
||||
real_t->fromXml(xml_real, free_terminals);
|
||||
if(real_t->isElement())
|
||||
{
|
||||
m_terminal_elements_vector.append(real_t->element());
|
||||
static_cast<TerminalElement*>(real_t->element())->setParentTerminalStrip(this);
|
||||
}
|
||||
real_t_vector.append(real_t);
|
||||
}
|
||||
|
||||
shared_physical_terminal phy_t(new PhysicalTerminal(this, real_t_vector));
|
||||
m_physical_terminals.append(phy_t);
|
||||
m_real_terminals.append(real_t_vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TerminalStrip::realTerminal
|
||||
* @param terminal
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
@ -32,7 +32,7 @@ class TerminalStrip : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TerminalStrip(const QString &name, QETProject *project);
|
||||
TerminalStrip(QETProject *project);
|
||||
|
||||
TerminalStrip(const QString &installation,
|
||||
const QString &location,
|
||||
@ -62,6 +62,7 @@ class TerminalStrip : public QObject
|
||||
|
||||
static QString xmlTagName() {return QStringLiteral("terminal_strip");}
|
||||
QDomElement toXml(QDomDocument &parent_document);
|
||||
bool fromXml(QDomElement &xml_element);
|
||||
|
||||
private:
|
||||
QSharedPointer<RealTerminal> realTerminal(Element *terminal);
|
||||
|
@ -107,29 +107,27 @@ void TerminalStripTreeWidget::dropEvent(QDropEvent *event)
|
||||
return;
|
||||
}
|
||||
|
||||
auto old_parent_type = dragged_item->parent()->type();
|
||||
|
||||
dragged_item->parent()->removeChild(dragged_item);
|
||||
auto old_parent = dragged_item->parent();
|
||||
old_parent->removeChild(dragged_item);
|
||||
overred_item->addChild(dragged_item);
|
||||
|
||||
//Move terminal
|
||||
if (old_parent_type == FreeTerminal && //From free to strip
|
||||
if (old_parent->type() == FreeTerminal && //From free to strip
|
||||
overred_item->type() == Strip) {
|
||||
emit terminalAddedToStrip(QUuid::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
||||
QUuid::fromString(overred_item->data(0, UUID_USER_ROLE).toString()));
|
||||
}
|
||||
else if (old_parent_type == Strip) //From strip to ...
|
||||
else if (old_parent->type() == Strip) //From strip to ...
|
||||
{
|
||||
if (overred_item->type() == FreeTerminal) //Free terminal
|
||||
{
|
||||
emit terminalRemovedFromStrip(QUuid::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
||||
QUuid::fromString(overred_item->data(0, UUID_USER_ROLE).toString()));
|
||||
}
|
||||
else if (overred_item->type() == Strip && //Another strip
|
||||
dragged_item->parent() != overred_item)
|
||||
else if (overred_item->type() == Strip)
|
||||
{
|
||||
emit terminalMovedFromStripToStrip(QUuid::fromString(dragged_item->data(0, UUID_USER_ROLE).toString()),
|
||||
QUuid::fromString(dragged_item->parent()->data(0, UUID_USER_ROLE).toString()),
|
||||
QUuid::fromString(old_parent->data(0, UUID_USER_ROLE).toString()),
|
||||
QUuid::fromString(overred_item->data(0, UUID_USER_ROLE).toString()));
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "ui/dialogwaiting.h"
|
||||
#include "ui/importelementdialog.h"
|
||||
#include "TerminalStrip/terminalstrip.h"
|
||||
#include "qetxml.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QStandardPaths>
|
||||
@ -1352,16 +1353,26 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
|
||||
}
|
||||
|
||||
m_data_base.blockSignals(true);
|
||||
|
||||
//Load the project-wide properties
|
||||
readProjectPropertiesXml(xml_project);
|
||||
|
||||
//Load the default properties for the new diagrams
|
||||
readDefaultPropertiesXml(xml_project);
|
||||
|
||||
//load the embedded titleblock templates
|
||||
m_titleblocks_collection.fromXml(xml_project.documentElement());
|
||||
|
||||
//Load the embedded elements collection
|
||||
readElementsCollectionXml(xml_project);
|
||||
|
||||
//Load the diagrams
|
||||
readDiagramsXml(xml_project);
|
||||
|
||||
//Load the terminal strip
|
||||
readTerminalStripXml(xml_project);
|
||||
|
||||
|
||||
m_data_base.blockSignals(false);
|
||||
m_data_base.updateDB();
|
||||
|
||||
@ -1579,6 +1590,26 @@ void QETProject::readDefaultPropertiesXml(QDomDocument &xml_project)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETProject::readTerminalStripXml
|
||||
* Read the terminal strips of this project
|
||||
* @param xml_project
|
||||
*/
|
||||
void QETProject::readTerminalStripXml(const QDomDocument &xml_project)
|
||||
{
|
||||
auto xml_elmt = xml_project.documentElement();
|
||||
auto xml_strips = xml_elmt.firstChildElement(QStringLiteral("terminal_strips"));
|
||||
if (!xml_strips.isNull())
|
||||
{
|
||||
for (auto xml_strip : QETXML::findInDomElement(xml_strips, TerminalStrip::xmlTagName()))
|
||||
{
|
||||
auto terminal_strip = new TerminalStrip(this);
|
||||
terminal_strip->fromXml(xml_strip);
|
||||
addTerminalStrip(terminal_strip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Export project properties under the \a xml_element XML element.
|
||||
*/
|
||||
|
@ -225,6 +225,7 @@ class QETProject : public QObject
|
||||
void readElementsCollectionXml(QDomDocument &xml_project);
|
||||
void readProjectPropertiesXml(QDomDocument &xml_project);
|
||||
void readDefaultPropertiesXml(QDomDocument &xml_project);
|
||||
void readTerminalStripXml(const QDomDocument &xml_project);
|
||||
|
||||
void writeProjectPropertiesXml(QDomElement &);
|
||||
void writeDefaultPropertiesXml(QDomElement &);
|
||||
|
Loading…
x
Reference in New Issue
Block a user