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
This commit is contained in:
blacksun 2013-12-31 14:39:34 +00:00
parent b7186468d0
commit 5ad42fb491
8 changed files with 84 additions and 0 deletions

View File

@ -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

View File

@ -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 *);

View File

@ -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 @@ QList <Element *> 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 <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;
}

View File

@ -33,6 +33,7 @@ class ElementProvider
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;

View File

@ -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 @@ 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<int, Terminal *> &table_id_adr, bool
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 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &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<Terminal *, int> &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();
}

View File

@ -20,6 +20,7 @@
#include <QtGui>
#include "terminal.h"
#include "qetgraphicsitem.h"
#include <QUuid>
class Diagram;
class ElementTextItem;
@ -54,11 +55,13 @@ class Element : public QetGraphicsItem {
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 @@ 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<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 @@ 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

View File

@ -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);
}
}

View File

@ -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;
}