mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Terminal strip item can saved / loaded to .qet file
This commit is contained in:
@@ -164,7 +164,8 @@ HEADERS += $$files(sources/*.h) $$files(sources/ui/*.h) \
|
|||||||
$$files(sources/TerminalStrip/*.h) \
|
$$files(sources/TerminalStrip/*.h) \
|
||||||
$$files(sources/TerminalStrip/ui/*.h) \
|
$$files(sources/TerminalStrip/ui/*.h) \
|
||||||
$$files(sources/TerminalStrip/UndoCommand/*.h) \
|
$$files(sources/TerminalStrip/UndoCommand/*.h) \
|
||||||
$$files(sources/TerminalStrip/GraphicsItem/*.h)
|
$$files(sources/TerminalStrip/GraphicsItem/*.h) \
|
||||||
|
$$files(sources/xml/*.h)
|
||||||
|
|
||||||
SOURCES += $$files(sources/*.cpp) \
|
SOURCES += $$files(sources/*.cpp) \
|
||||||
$$files(sources/editor/*.cpp) \
|
$$files(sources/editor/*.cpp) \
|
||||||
@@ -201,7 +202,8 @@ SOURCES += $$files(sources/*.cpp) \
|
|||||||
$$files(sources/TerminalStrip/*.cpp) \
|
$$files(sources/TerminalStrip/*.cpp) \
|
||||||
$$files(sources/TerminalStrip/ui/*.cpp) \
|
$$files(sources/TerminalStrip/ui/*.cpp) \
|
||||||
$$files(sources/TerminalStrip/UndoCommand/*.cpp) \
|
$$files(sources/TerminalStrip/UndoCommand/*.cpp) \
|
||||||
$$files(sources/TerminalStrip/GraphicsItem/*.cpp)
|
$$files(sources/TerminalStrip/GraphicsItem/*.cpp) \
|
||||||
|
$$files(sources/xml/*.cpp)
|
||||||
|
|
||||||
# Needed for use promote QTreeWidget in terminalstripeditor.ui
|
# Needed for use promote QTreeWidget in terminalstripeditor.ui
|
||||||
INCLUDEPATH += sources/TerminalStrip/ui
|
INCLUDEPATH += sources/TerminalStrip/ui
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ TerminalStripDrawer::TerminalStripDrawer(QPointer<TerminalStrip> strip) :
|
|||||||
m_strip(strip)
|
m_strip(strip)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void TerminalStripDrawer::setStrip(TerminalStrip *strip)
|
||||||
|
{
|
||||||
|
m_strip = strip;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief TerminalStripDrawer::paint
|
* @brief TerminalStripDrawer::paint
|
||||||
* @param painter
|
* @param painter
|
||||||
|
|||||||
@@ -27,9 +27,10 @@ class TerminalStrip;
|
|||||||
class TerminalStripDrawer
|
class TerminalStripDrawer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TerminalStripDrawer(QPointer<TerminalStrip> strip);
|
TerminalStripDrawer(QPointer<TerminalStrip> strip = QPointer<TerminalStrip>());
|
||||||
void paint(QPainter *painter);
|
|
||||||
|
|
||||||
|
void setStrip(TerminalStrip *strip);
|
||||||
|
void paint(QPainter *painter);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "terminalstripitem.h"
|
#include "terminalstripitem.h"
|
||||||
|
|
||||||
|
#include "../diagram.h"
|
||||||
#include "../../qetgraphicsitem/qgraphicsitemutility.h"
|
#include "../../qetgraphicsitem/qgraphicsitemutility.h"
|
||||||
#include "../terminalstrip.h"
|
#include "../terminalstrip.h"
|
||||||
#include "../ui/terminalstripeditorwindow.h"
|
#include "../ui/terminalstripeditorwindow.h"
|
||||||
@@ -26,7 +28,29 @@ TerminalStripItem::TerminalStripItem(QPointer<TerminalStrip> strip, QGraphicsIte
|
|||||||
m_drawer{strip}
|
m_drawer{strip}
|
||||||
{
|
{
|
||||||
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
setAcceptHoverEvents(true);
|
setAcceptHoverEvents(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
TerminalStripItem::TerminalStripItem(QGraphicsItem *parent) :
|
||||||
|
QetGraphicsItem { parent }
|
||||||
|
{
|
||||||
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalStripItem::setTerminalStrip(TerminalStrip *strip)
|
||||||
|
{
|
||||||
|
m_strip = strip;
|
||||||
|
m_drawer.setStrip(strip);
|
||||||
|
m_pending_strip_uuid = QUuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripItem::terminalStrip
|
||||||
|
* @return The strip drawed by this item
|
||||||
|
*/
|
||||||
|
QPointer<TerminalStrip> TerminalStripItem::terminalStrip() const {
|
||||||
|
return m_strip;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerminalStripItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void TerminalStripItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
@@ -62,5 +86,22 @@ void TerminalStripItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED (event);
|
Q_UNUSED (event);
|
||||||
|
|
||||||
TerminalStripEditorWindow::edit(m_strip);
|
if (m_strip) {
|
||||||
|
TerminalStripEditorWindow::edit(m_strip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalStripItem::refreshPending()
|
||||||
|
{
|
||||||
|
if (!m_pending_strip_uuid.isNull()
|
||||||
|
&& diagram()
|
||||||
|
&& diagram()->project())
|
||||||
|
{
|
||||||
|
for (const auto &strip_ : diagram()->project()->terminalStrip()) {
|
||||||
|
if (strip_->uuid() == m_pending_strip_uuid) {
|
||||||
|
setTerminalStrip(strip_);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#define TERMINALSTRIPITEM_H
|
#define TERMINALSTRIPITEM_H
|
||||||
|
|
||||||
#include <QGraphicsObject>
|
#include <QGraphicsObject>
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
#include "terminalstripdrawer.h"
|
#include "terminalstripdrawer.h"
|
||||||
#include "../../qetgraphicsitem/qetgraphicsitem.h"
|
#include "../../qetgraphicsitem/qetgraphicsitem.h"
|
||||||
@@ -27,10 +28,16 @@ class TerminalStrip;
|
|||||||
|
|
||||||
class TerminalStripItem : public QetGraphicsItem
|
class TerminalStripItem : public QetGraphicsItem
|
||||||
{
|
{
|
||||||
|
friend class TerminalStripItemXml;
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TerminalStripItem(QPointer<TerminalStrip> strip, QGraphicsItem *parent = nullptr);
|
TerminalStripItem(QPointer<TerminalStrip> strip, QGraphicsItem *parent = nullptr);
|
||||||
|
TerminalStripItem(QGraphicsItem *parent = nullptr);
|
||||||
|
|
||||||
|
void setTerminalStrip(TerminalStrip *strip);
|
||||||
|
QPointer<TerminalStrip> terminalStrip() const;
|
||||||
|
|
||||||
enum {Type = UserType + 1011};
|
enum {Type = UserType + 1011};
|
||||||
int type() const override {return Type;}
|
int type() const override {return Type;}
|
||||||
@@ -41,9 +48,12 @@ class TerminalStripItem : public QetGraphicsItem
|
|||||||
|
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
||||||
|
void refreshPending();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<TerminalStrip> m_strip;
|
QPointer<TerminalStrip> m_strip;
|
||||||
TerminalStripDrawer m_drawer;
|
TerminalStripDrawer m_drawer;
|
||||||
|
QUuid m_pending_strip_uuid;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
|
|
||||||
#include "ElementsCollection/elementcollectionhandler.h"
|
#include "ElementsCollection/elementcollectionhandler.h"
|
||||||
|
#include "TerminalStrip/GraphicsItem/terminalstripitem.h"
|
||||||
|
#include "xml/terminalstripitemxml.h"
|
||||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
#include "diagramcommands.h"
|
#include "diagramcommands.h"
|
||||||
#include "diagramcontent.h"
|
#include "diagramcontent.h"
|
||||||
@@ -873,6 +875,7 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
QVector<DiagramImageItem *> list_images;
|
QVector<DiagramImageItem *> list_images;
|
||||||
QVector<QetShapeItem *> list_shapes;
|
QVector<QetShapeItem *> list_shapes;
|
||||||
QVector<QetGraphicsTableItem *> table_vector;
|
QVector<QetGraphicsTableItem *> table_vector;
|
||||||
|
QVector<TerminalStripItem *> strip_vector;
|
||||||
|
|
||||||
//Ckeck graphics item to "XMLise"
|
//Ckeck graphics item to "XMLise"
|
||||||
for(QGraphicsItem *qgi : items())
|
for(QGraphicsItem *qgi : items())
|
||||||
@@ -922,6 +925,12 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
if (whole_content || table->isSelected())
|
if (whole_content || table->isSelected())
|
||||||
table_vector << table;
|
table_vector << table;
|
||||||
}
|
}
|
||||||
|
case TerminalStripItem::Type: {
|
||||||
|
const auto strip = static_cast<TerminalStripItem *>(qgi);
|
||||||
|
if (whole_content || strip->isSelected()) {
|
||||||
|
strip_vector << strip;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -979,6 +988,11 @@ QDomDocument Diagram::toXml(bool whole_content) {
|
|||||||
dom_root.appendChild(tables);
|
dom_root.appendChild(tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strip_vector.isEmpty()) {
|
||||||
|
dom_root.appendChild(TerminalStripItemXml::toXml(strip_vector, document));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return(document);
|
return(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1423,6 +1437,9 @@ bool Diagram::fromXml(QDomElement &document,
|
|||||||
added_tables << table;
|
added_tables << table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Load terminal strip item
|
||||||
|
QVector<TerminalStripItem *> added_strips { TerminalStripItemXml::fromXml(this, root) };
|
||||||
|
|
||||||
//Translate items if a new position was given in parameter
|
//Translate items if a new position was given in parameter
|
||||||
if (position != QPointF())
|
if (position != QPointF())
|
||||||
{
|
{
|
||||||
@@ -1433,6 +1450,7 @@ bool Diagram::fromXml(QDomElement &document,
|
|||||||
for (auto text : qAsConst(added_texts )) added_items << text;
|
for (auto text : qAsConst(added_texts )) added_items << text;
|
||||||
for (auto image : qAsConst(added_images )) added_items << image;
|
for (auto image : qAsConst(added_images )) added_items << image;
|
||||||
for (auto table : qAsConst(added_tables )) added_items << table;
|
for (auto table : qAsConst(added_tables )) added_items << table;
|
||||||
|
for (const auto &strip : qAsConst(added_strips)) added_items << strip;
|
||||||
|
|
||||||
//Get the top left corner of the rectangle that contain all added items
|
//Get the top left corner of the rectangle that contain all added items
|
||||||
QRectF items_rect;
|
QRectF items_rect;
|
||||||
@@ -1473,8 +1491,9 @@ bool Diagram::fromXml(QDomElement &document,
|
|||||||
content_ptr -> m_shapes = QSet<QetShapeItem *>(
|
content_ptr -> m_shapes = QSet<QetShapeItem *>(
|
||||||
added_shapes.begin(),
|
added_shapes.begin(),
|
||||||
added_shapes.end());
|
added_shapes.end());
|
||||||
|
content_ptr->m_terminal_strip.swap(added_strips);
|
||||||
#endif
|
#endif
|
||||||
content_ptr -> m_tables = added_tables;
|
content_ptr->m_tables.swap(added_tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
adjustSceneRect();
|
adjustSceneRect();
|
||||||
@@ -1528,20 +1547,25 @@ void Diagram::folioSequentialsFromXml(const QDomElement &root,
|
|||||||
*/
|
*/
|
||||||
void Diagram::refreshContents()
|
void Diagram::refreshContents()
|
||||||
{
|
{
|
||||||
ElementProvider provider_(this);
|
DiagramContent dc_(this, false);
|
||||||
|
|
||||||
for (Element *elmt : elements())
|
for (auto &elmt : dc_.m_elements) {
|
||||||
{
|
|
||||||
elmt->initLink(project());
|
elmt->initLink(project());
|
||||||
for (DynamicElementTextItem *deti : elmt->dynamicTextItems())
|
for (auto &deti : elmt->dynamicTextItems())
|
||||||
deti->refreshLabelConnection();
|
deti->refreshLabelConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Conductor *conductor : conductors())
|
for (auto &conductor : dc_.conductors()) {
|
||||||
conductor->refreshText();
|
conductor->refreshText();
|
||||||
|
}
|
||||||
|
|
||||||
for (auto table : provider_.table())
|
for (auto &table : qAsConst(dc_.m_tables)) {
|
||||||
table->initLink();
|
table->initLink();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &strip :qAsConst(dc_.m_terminal_strip)) {
|
||||||
|
strip->refreshPending();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -225,7 +225,33 @@ QETProject::ProjectState QETProject::openFile(QFile *file)
|
|||||||
if(opened_here) {
|
if(opened_here) {
|
||||||
file->close();
|
file->close();
|
||||||
}
|
}
|
||||||
return ProjectState::Ok;
|
return ProjectState::Ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief QETProject::refresh
|
||||||
|
* Refresh everything in the project.
|
||||||
|
* This is notably use when open a project from file.
|
||||||
|
*/
|
||||||
|
void QETProject::refresh()
|
||||||
|
{
|
||||||
|
DialogWaiting *dlgWaiting { nullptr };
|
||||||
|
if(DialogWaiting::hasInstance())
|
||||||
|
{
|
||||||
|
dlgWaiting = DialogWaiting::instance();
|
||||||
|
dlgWaiting->setModal(true);
|
||||||
|
dlgWaiting->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const auto &diagram : diagrams())
|
||||||
|
{
|
||||||
|
if(dlgWaiting)
|
||||||
|
{
|
||||||
|
dlgWaiting->setProgressBar(dlgWaiting->progressBarValue()+1);
|
||||||
|
dlgWaiting->setDetail(diagram->title());
|
||||||
|
}
|
||||||
|
diagram->refreshContents();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1388,6 +1414,9 @@ void QETProject::readProjectXml(QDomDocument &xml_project)
|
|||||||
//Load the terminal strip
|
//Load the terminal strip
|
||||||
readTerminalStripXml(xml_project);
|
readTerminalStripXml(xml_project);
|
||||||
|
|
||||||
|
//Now that all are loaded we refresh content of the project.
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
|
||||||
m_data_base.blockSignals(false);
|
m_data_base.blockSignals(false);
|
||||||
m_data_base.updateDB();
|
m_data_base.updateDB();
|
||||||
@@ -1461,18 +1490,6 @@ void QETProject::readDiagramsXml(QDomDocument &xml_project)
|
|||||||
"Mise en place des références croisées"
|
"Mise en place des références croisées"
|
||||||
"</p>"));
|
"</p>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data_base.updateDB(); //All diagrams and items are created we need to update the database
|
|
||||||
|
|
||||||
for(const auto &diagram : diagrams())
|
|
||||||
{
|
|
||||||
if(dlgWaiting)
|
|
||||||
{
|
|
||||||
dlgWaiting->setProgressBar(dlgWaiting->progressBarValue()+1);
|
|
||||||
dlgWaiting->setDetail(diagram->title());
|
|
||||||
}
|
|
||||||
diagram->refreshContents();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ class QETProject : public QObject
|
|||||||
void writeBackup();
|
void writeBackup();
|
||||||
void init();
|
void init();
|
||||||
ProjectState openFile(QFile *file);
|
ProjectState openFile(QFile *file);
|
||||||
|
void refresh();
|
||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QGraphicsItem>
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -917,7 +918,39 @@ bool validXmlProperty(const QDomElement& e) {
|
|||||||
if (!e.hasAttribute("value"))
|
if (!e.hasAttribute("value"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief qGraphicsItemPosToXml
|
||||||
|
* Save the pos of a QGraphicsItem into an xml element.
|
||||||
|
* The tag name of the xml element is pos and there is 3 attributes:
|
||||||
|
* x, y, z.
|
||||||
|
* @param item
|
||||||
|
* @param document
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QDomElement qGraphicsItemPosToXml(QGraphicsItem *item, QDomDocument &document)
|
||||||
|
{
|
||||||
|
auto dom_pos = document.createElement(QStringLiteral("pos"));
|
||||||
|
dom_pos.setAttribute(QStringLiteral("x"), QString::number(item->pos().x()));
|
||||||
|
dom_pos.setAttribute(QStringLiteral("y"), QString::number(item->pos().y()));
|
||||||
|
dom_pos.setAttribute(QStringLiteral("z"), QString::number(item->zValue()));
|
||||||
|
|
||||||
|
return dom_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool qGraphicsItemPosFromXml(QGraphicsItem *item, const QDomElement &xml_elmt)
|
||||||
|
{
|
||||||
|
if (xml_elmt.tagName() == QLatin1String("pos"))
|
||||||
|
{
|
||||||
|
item->setX(xml_elmt.attribute(QStringLiteral("x"), QStringLiteral("0")).toDouble());
|
||||||
|
item->setY(xml_elmt.attribute(QStringLiteral("y"), QStringLiteral("0")).toDouble());
|
||||||
|
item->setZValue(xml_elmt.attribute(QStringLiteral("z"), QStringLiteral("0")).toInt());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class QDomDocument;
|
|||||||
class QDir;
|
class QDir;
|
||||||
class QFile;
|
class QFile;
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
|
class QGraphicsItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*This namespace contain some function to use xml with QET.
|
*This namespace contain some function to use xml with QET.
|
||||||
@@ -89,6 +90,10 @@ namespace QETXML
|
|||||||
|
|
||||||
QVector<QDomElement> findInDomElement(const QDomElement &dom_elmt,
|
QVector<QDomElement> findInDomElement(const QDomElement &dom_elmt,
|
||||||
const QString &tag_name);
|
const QString &tag_name);
|
||||||
|
|
||||||
|
QDomElement qGraphicsItemPosToXml(QGraphicsItem *item, QDomDocument &document);
|
||||||
|
bool qGraphicsItemPosFromXml(QGraphicsItem *item, const QDomElement &xml_elmt);
|
||||||
|
|
||||||
QString boolToString(bool value);
|
QString boolToString(bool value);
|
||||||
bool boolFromString(const QString &value,
|
bool boolFromString(const QString &value,
|
||||||
bool default_value = true,
|
bool default_value = true,
|
||||||
|
|||||||
131
sources/xml/terminalstripitemxml.cpp
Normal file
131
sources/xml/terminalstripitemxml.cpp
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2022 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 "terminalstripitemxml.h"
|
||||||
|
|
||||||
|
#include "../diagram.h"
|
||||||
|
#include "../qetproject.h"
|
||||||
|
#include "../qetxml.h"
|
||||||
|
#include "../TerminalStrip/GraphicsItem/terminalstripitem.h"
|
||||||
|
#include "../TerminalStrip/terminalstrip.h"
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
const QString STRIP_ITEM_TAG_NAME { QStringLiteral("terminal_strip_item") };
|
||||||
|
const QString STRIP_ITEMS_TAG_NAME { QStringLiteral("terminal_strip_items") };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripItemXml::toXml
|
||||||
|
* Save the vector of @a items as child of an xml element with tag "terminal_strip_tems"
|
||||||
|
* @param items : items to save in xml
|
||||||
|
* @param document : parent document used to create the QDomElement returned by this function.
|
||||||
|
* @return QDomElement where are saved @a items.
|
||||||
|
*/
|
||||||
|
QDomElement TerminalStripItemXml::toXml(const QVector<TerminalStripItem *> &items, QDomDocument &document)
|
||||||
|
{
|
||||||
|
auto dom_element = document.createElement(STRIP_ITEMS_TAG_NAME);
|
||||||
|
for (const auto &item : items) {
|
||||||
|
dom_element.appendChild(toXml(item, document));
|
||||||
|
}
|
||||||
|
|
||||||
|
return dom_element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripItemXml::fromXml
|
||||||
|
* Load items stored in @a xml_elmt into @a diagram
|
||||||
|
* @a xml_elmt must have a child element with tag name "terminal_strip_tems"
|
||||||
|
* @param diagram
|
||||||
|
* @param xml_elmt
|
||||||
|
* @return a vector of added terminal strip item
|
||||||
|
*/
|
||||||
|
QVector<TerminalStripItem *> TerminalStripItemXml::fromXml(Diagram *diagram, const QDomElement &xml_elmt)
|
||||||
|
{
|
||||||
|
QVector<TerminalStripItem *> returned_vector;
|
||||||
|
|
||||||
|
for (const auto &dom_elmt : QETXML::subChild(xml_elmt,
|
||||||
|
STRIP_ITEMS_TAG_NAME,
|
||||||
|
STRIP_ITEM_TAG_NAME))
|
||||||
|
{
|
||||||
|
auto strip_item = new TerminalStripItem();
|
||||||
|
diagram->addItem(strip_item);
|
||||||
|
returned_vector << strip_item;
|
||||||
|
|
||||||
|
TerminalStripItemXml::fromXml(strip_item, diagram->project(), dom_elmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returned_vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripItemXml::toXml
|
||||||
|
* Save @a item to an xml element with tag "terminal_strip_item"
|
||||||
|
* @param item : item to save in xml
|
||||||
|
* @param document : parent document used to create the QDomElement returned by this function.
|
||||||
|
* @return QDomElement where are saved @a item.
|
||||||
|
*/
|
||||||
|
QDomElement TerminalStripItemXml::toXml(TerminalStripItem *item, QDomDocument &document)
|
||||||
|
{
|
||||||
|
//Terminal strip item dom element
|
||||||
|
auto dom_element = document.createElement(STRIP_ITEM_TAG_NAME);
|
||||||
|
|
||||||
|
auto dom_strip = document.createElement(QStringLiteral("terminal_strip"));
|
||||||
|
dom_strip.setAttribute(QStringLiteral("uuid"), item->terminalStrip()->uuid().toString());
|
||||||
|
dom_element.appendChild(dom_strip);
|
||||||
|
|
||||||
|
dom_element.appendChild(QETXML::qGraphicsItemPosToXml(item, document));
|
||||||
|
|
||||||
|
return dom_element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief TerminalStripItemXml::fromXml
|
||||||
|
* Restor the state of a terminal strip item from @a xml_elmt.
|
||||||
|
* The @a xml_elmt tag name must be "terminal_strip_item"
|
||||||
|
* @param item
|
||||||
|
* @param project
|
||||||
|
* @param xml_elmt
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
bool TerminalStripItemXml::fromXml(TerminalStripItem *item, QETProject *project, const QDomElement &xml_elmt)
|
||||||
|
{
|
||||||
|
if (xml_elmt.tagName() == STRIP_ITEM_TAG_NAME)
|
||||||
|
{
|
||||||
|
bool a{false};
|
||||||
|
|
||||||
|
const auto ts = xml_elmt.firstChildElement(QStringLiteral("terminal_strip"));
|
||||||
|
if (!ts.isNull())
|
||||||
|
{
|
||||||
|
const QUuid uuid_(ts.attribute(QStringLiteral("uuid")));
|
||||||
|
item->m_pending_strip_uuid = uuid_;
|
||||||
|
|
||||||
|
for (const auto &ts : project->terminalStrip()) {
|
||||||
|
if (ts->uuid() == uuid_) {
|
||||||
|
item->setTerminalStrip(ts);
|
||||||
|
a = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool b{QETXML::qGraphicsItemPosFromXml(item,
|
||||||
|
xml_elmt.firstChildElement(QStringLiteral("pos")))};
|
||||||
|
|
||||||
|
return (a && b);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
37
sources/xml/terminalstripitemxml.h
Normal file
37
sources/xml/terminalstripitemxml.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2022 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 TERMINALSTRIPITEMXML_H
|
||||||
|
#define TERMINALSTRIPITEMXML_H
|
||||||
|
|
||||||
|
#include <QDomElement>
|
||||||
|
|
||||||
|
class TerminalStripItem;
|
||||||
|
class QETProject;
|
||||||
|
class Diagram;
|
||||||
|
|
||||||
|
class TerminalStripItemXml
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static QDomElement toXml(const QVector<TerminalStripItem *> &items, QDomDocument &document);
|
||||||
|
static QVector<TerminalStripItem *> fromXml(Diagram *diagram, const QDomElement &xml_elmt);
|
||||||
|
|
||||||
|
static QDomElement toXml(TerminalStripItem *item, QDomDocument &document);
|
||||||
|
static bool fromXml(TerminalStripItem *item, QETProject *project, const QDomElement &xml_elmt);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TERMINALSTRIPITEMXML_H
|
||||||
Reference in New Issue
Block a user