From 5ad42fb491d50c8d820502a6d367eb54910da650 Mon Sep 17 00:00:00 2001 From: blacksun Date: Tue, 31 Dec 2013 14:39:34 +0000 Subject: [PATCH] Folio report are save/load in .qet file git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2688 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagram.cpp | 5 ++++ sources/diagram.h | 1 + sources/elementprovider.cpp | 20 +++++++++++++ sources/elementprovider.h | 1 + sources/qetgraphicsitem/element.cpp | 35 +++++++++++++++++++++++ sources/qetgraphicsitem/element.h | 16 +++++++++++ sources/qetgraphicsitem/reportelement.cpp | 1 + sources/qetproject.cpp | 5 ++++ 8 files changed, 84 insertions(+) diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 12fa11d22..588068227 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -686,6 +686,11 @@ QDomElement Diagram::writeXml(QDomDocument &xml_doc) const { return(new_node.toElement()); } +void Diagram::initElementsLinks() { + foreach (Element *elmt, elements()) + elmt->initLink(project()); +} + /** Ajoute un element sur le schema @param element Element a ajouter diff --git a/sources/diagram.h b/sources/diagram.h index 694bca2b8..b66f580bd 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -133,6 +133,7 @@ class Diagram : public QGraphicsScene { QDomElement writeXml(QDomDocument &) const; // methods related to graphics items addition/removal on the diagram + void initElementsLinks(); void addElement(Element *); void addConductor(Conductor *); void addIndependentTextItem(IndependentTextItem *); diff --git a/sources/elementprovider.cpp b/sources/elementprovider.cpp index db125f026..5ef5d33e7 100644 --- a/sources/elementprovider.cpp +++ b/sources/elementprovider.cpp @@ -16,6 +16,7 @@ along with QElectroTech. If not, see . */ #include "elementprovider.h" +#include "QUuid" /** * @brief ElementProvider::ElementProvider Constructor @@ -52,3 +53,22 @@ QList ElementProvider::FreeElement(const int filter) const{ } return (free_elmt); } + +/** + * @brief ElementProvider::fromUuids + * @param uuid_list list of uuid must be found + * @return all elements with uuid corresponding to uuid in @uuid_list + */ +QList ElementProvider::fromUuids(QList uuid_list) const { + QList found_element; + + foreach (Diagram *d, diag_list) { + foreach(Element *elmt, d->elements()) { + if (uuid_list.contains(elmt->uuid())) { + found_element << elmt; + uuid_list.removeAll(elmt->uuid()); + } + } + } + return found_element; +} diff --git a/sources/elementprovider.h b/sources/elementprovider.h index 76d1a38a5..9ab95ae13 100644 --- a/sources/elementprovider.h +++ b/sources/elementprovider.h @@ -33,6 +33,7 @@ class ElementProvider public: ElementProvider(QETProject *prj, Diagram *diagram=0); QList FreeElement(const int filter) const; + QList fromUuids(QList ) const; private: QList diag_list; diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 4c27c07f9..5d80a8fbe 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -23,6 +23,7 @@ #include "diagramcommands.h" #include #include +#include "elementprovider.h" /** Constructeur pour un element sans scene ni parent @@ -32,6 +33,7 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) : internal_connections_(false), must_highlight_(false) { + uuid_ = QUuid::createUuid(); setZValue(10); } @@ -385,7 +387,14 @@ bool Element::fromXml(QDomElement &e, QHash &table_id_adr, bool foreach(QDomElement input, inputs) eti -> fromXml(input); } } + + //load uuid of connected elements + QList uuid_list = QET::findInDomElement(e, "links_uuids", "link_uuid"); + foreach (QDomElement qdo, uuid_list) tmp_uuids_link << qdo.attribute("uuid"); + //uuid of this element + uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString())); + // position, selection setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble()); setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); @@ -415,6 +424,8 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table // type element.setAttribute("type", typeId()); + // uuid + element.setAttribute("uuid", uuid().toString()); // position, selection et orientation element.setAttribute("x", QString("%1").arg(pos().x())); @@ -450,6 +461,30 @@ QDomElement Element::toXml(QDomDocument &document, QHash &table inputs.appendChild(eti -> toXml(document)); } element.appendChild(inputs); + + //if this element is linked to other elements, + //save the uuid of each other elements + if (! isFree()) { + QDomElement links_uuids = document.createElement("links_uuids"); + foreach (Element *elmt, connected_elements) { + QDomElement link_uuid = document.createElement("link_uuid"); + link_uuid.setAttribute("uuid", elmt->uuid().toString()); + links_uuids.appendChild(link_uuid); + } + element.appendChild(links_uuids); + } return(element); } + +// Initialise link for this element +void Element::initLink(QETProject *prj) { + // if nothing to link return now + if (tmp_uuids_link.isEmpty()) return; + + ElementProvider ep(prj); + foreach (Element *elmt, ep.fromUuids(tmp_uuids_link)) { + elmt->linkToElement(this); + } + tmp_uuids_link.clear(); +} diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 9415f6db1..fb0e4f654 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -20,6 +20,7 @@ #include #include "terminal.h" #include "qetgraphicsitem.h" +#include class Diagram; class ElementTextItem; @@ -54,11 +55,13 @@ class Element : public QetGraphicsItem { protected: QList connected_elements; + QList tmp_uuids_link; private: QSize dimensions; QPoint hotspot_coord; QPixmap preview; + QUuid uuid_; // methods public: @@ -82,9 +85,13 @@ class Element : public QetGraphicsItem { virtual int minTerminalsCount() const = 0; /// @return the maximum number of terminals for this element virtual int maxTerminalsCount() const = 0; + + // related method for link between element bool isFree () const; virtual void linkToElement(Element *) {} virtual void unLinkAllElements() {} + void initLink(QETProject *); + /** Draw this element */ @@ -122,6 +129,7 @@ class Element : public QetGraphicsItem { static bool valideXml(QDomElement &); virtual bool fromXml(QDomElement &, QHash &, bool = false); virtual QDomElement toXml(QDomDocument &, QHash &) const; + QUuid uuid() const; // orientation-related methods int orientation() const; @@ -171,4 +179,12 @@ inline int Element::orientation() const { return(QET::correctAngle(rotation())/90); } +/** + * @brief Element::uuid + * @return the uuid of this element + */ +inline QUuid Element::uuid() const { + return uuid_; +} + #endif diff --git a/sources/qetgraphicsitem/reportelement.cpp b/sources/qetgraphicsitem/reportelement.cpp index 8360e35af..495e185bf 100644 --- a/sources/qetgraphicsitem/reportelement.cpp +++ b/sources/qetgraphicsitem/reportelement.cpp @@ -44,6 +44,7 @@ void ReportElement::linkToElement(Element * elmt) { connected_elements << elmt; connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); updateLabel(); + tmp_uuids_link.removeAll(elmt->uuid()); elmt->linkToElement(this); } } diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index 1473629a8..473ea2f7f 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -990,6 +990,11 @@ void QETProject::readDiagramsXml() { foreach(Diagram *diagram, loaded_diagrams.values()) { addDiagram(diagram); } + // Initialise links between elements in this project + foreach (Diagram *d, diagrams()) { + d->initElementsLinks(); + } + //delete dialog object delete dlgWaiting; }