[qet] [2688] Folio report are save/load in .qet file |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2688
Author: blacksun
Date: 2013-12-31 15:39:34 +0100 (Tue, 31 Dec 2013)
Log Message:
-----------
Folio report are save/load in .qet file
Modified Paths:
--------------
trunk/sources/diagram.cpp
trunk/sources/diagram.h
trunk/sources/elementprovider.cpp
trunk/sources/elementprovider.h
trunk/sources/qetgraphicsitem/element.cpp
trunk/sources/qetgraphicsitem/element.h
trunk/sources/qetgraphicsitem/reportelement.cpp
trunk/sources/qetproject.cpp
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/diagram.cpp 2013-12-31 14:39:34 UTC (rev 2688)
@@ -686,6 +686,11 @@
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
Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/diagram.h 2013-12-31 14:39:34 UTC (rev 2688)
@@ -133,6 +133,7 @@
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 *);
Modified: trunk/sources/elementprovider.cpp
===================================================================
--- trunk/sources/elementprovider.cpp 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/elementprovider.cpp 2013-12-31 14:39:34 UTC (rev 2688)
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "elementprovider.h"
+#include "QUuid"
/**
* @brief ElementProvider::ElementProvider Constructor
@@ -52,3 +53,22 @@
}
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 <Element *> ElementProvider::fromUuids(QList<QUuid> uuid_list) const {
+ QList <Element *> 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;
+}
Modified: trunk/sources/elementprovider.h
===================================================================
--- trunk/sources/elementprovider.h 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/elementprovider.h 2013-12-31 14:39:34 UTC (rev 2688)
@@ -33,6 +33,7 @@
public:
ElementProvider(QETProject *prj, Diagram *diagram=0);
QList <Element *> FreeElement(const int filter) const;
+ QList <Element *> fromUuids(QList <QUuid>) const;
private:
QList <Diagram *> diag_list;
Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/qetgraphicsitem/element.cpp 2013-12-31 14:39:34 UTC (rev 2688)
@@ -23,6 +23,7 @@
#include "diagramcommands.h"
#include <QtDebug>
#include <ui/elementpropertieswidget.h>
+#include "elementprovider.h"
/**
Constructeur pour un element sans scene ni parent
@@ -32,6 +33,7 @@
internal_connections_(false),
must_highlight_(false)
{
+ uuid_ = QUuid::createUuid();
setZValue(10);
}
@@ -385,7 +387,14 @@
foreach(QDomElement input, inputs) eti -> fromXml(input);
}
}
+
+ //load uuid of connected elements
+ QList <QDomElement> 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 @@
// 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 @@
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();
+}
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/qetgraphicsitem/element.h 2013-12-31 14:39:34 UTC (rev 2688)
@@ -20,6 +20,7 @@
#include <QtGui>
#include "terminal.h"
#include "qetgraphicsitem.h"
+#include <QUuid>
class Diagram;
class ElementTextItem;
@@ -54,11 +55,13 @@
protected:
QList <Element *> connected_elements;
+ QList <QUuid> tmp_uuids_link;
private:
QSize dimensions;
QPoint hotspot_coord;
QPixmap preview;
+ QUuid uuid_;
// methods
public:
@@ -82,9 +85,13 @@
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 @@
static bool valideXml(QDomElement &);
virtual bool fromXml(QDomElement &, QHash<int, Terminal *> &, bool = false);
virtual QDomElement toXml(QDomDocument &, QHash<Terminal *, int> &) const;
+ QUuid uuid() const;
// orientation-related methods
int orientation() const;
@@ -171,4 +179,12 @@
return(QET::correctAngle(rotation())/90);
}
+/**
+ * @brief Element::uuid
+ * @return the uuid of this element
+ */
+inline QUuid Element::uuid() const {
+ return uuid_;
+}
+
#endif
Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp 2013-12-31 14:39:34 UTC (rev 2688)
@@ -44,6 +44,7 @@
connected_elements << elmt;
connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel()));
updateLabel();
+ tmp_uuids_link.removeAll(elmt->uuid());
elmt->linkToElement(this);
}
}
Modified: trunk/sources/qetproject.cpp
===================================================================
--- trunk/sources/qetproject.cpp 2013-12-31 12:53:22 UTC (rev 2687)
+++ trunk/sources/qetproject.cpp 2013-12-31 14:39:34 UTC (rev 2688)
@@ -990,6 +990,11 @@
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;
}