element master widget property: improve gui.

add slave element class.
element class: replace diagramcontext informations by elementInformations because informations is already used in xml file for element.
minor improvement.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2869 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-02-22 17:24:20 +00:00
parent 680fded375
commit 105c1c87b6
12 changed files with 365 additions and 37 deletions

View File

@@ -33,7 +33,7 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) :
internal_connections_(false),
must_highlight_(false)
{
link_type_ = 0;
link_type_ = Simple;
uuid_ = QUuid::createUuid();
setZValue(10);
}
@@ -397,7 +397,9 @@ bool Element::fromXml(QDomElement &e, QHash<int, Terminal *> &table_id_adr, bool
uuid_= QUuid(e.attribute("uuid", QUuid::createUuid().toString()));
//load informations
informations_.fromXml(e.firstChildElement("informations"), "information");
element_informations_.fromXml(e.firstChildElement("elementInformations"), "elementInformation");
//load kind informations
kind_informations_.fromXml(e.firstChildElement("kindInformations"), "kindInformation");
// position, selection
setPos(e.attribute("x").toDouble(), e.attribute("y").toDouble());
@@ -479,9 +481,19 @@ QDomElement Element::toXml(QDomDocument &document, QHash<Terminal *, int> &table
}
//save information of this element
QDomElement infos = document.createElement("informations");
informations_.toXml(infos, "information");
element.appendChild(infos);
if (! element_informations_.keys().isEmpty()) {
QDomElement infos = document.createElement("elementInformations");
element_informations_.toXml(infos, "elementInformation");
element.appendChild(infos);
}
//save kind_informations of this element
if (! kind_informations_.keys().isEmpty()) {
QDomElement kind_infos = document.createElement("kindInformations");
kind_informations_.toXml(kind_infos, "kindInformation");
element.appendChild(kind_infos);
}
return(element);
}

View File

@@ -44,15 +44,13 @@ class Element : public QetGraphicsItem {
enum { Type = UserType + 1000 };
// this enum is use to know the kind of element and
// to use flag for element provider class
enum {Simple = 1,
enum kind {Simple = 1,
NextReport = 2,
PreviousReport = 4,
AllReport = 6,
Master = 8,
SlaveNO = 16,
SlaveNC = 32,
AllSlave = 48,
Bornier = 64};
Slave = 16,
Bornier = 32};
private:
QSize dimensions;
@@ -115,16 +113,19 @@ class Element : public QetGraphicsItem {
QList <Element *> connected_elements;
QList <QUuid> tmp_uuids_link;
QUuid uuid_;
int link_type_;
kind link_type_;
//METHODS related to information
public:
DiagramContext informations()const {return informations_;}
void setInformations(DiagramContext dc) {informations_ = dc;}
DiagramContext elementInformations()const {return element_informations_;}
void setElementInformations(DiagramContext dc) {element_informations_ = dc;}
DiagramContext kindInformations() const {return kind_informations_;} //@kind_information_ is used to store more information
//about the herited class like contactelement for know
// kind of contact (simple tempo) or number of contact show by the element.
//ATTRIBUTES
protected:
DiagramContext informations_;
DiagramContext element_informations_, kind_informations_;
/**
Draw this element

View File

@@ -1,3 +1,20 @@
/*
Copyright 2006-2014 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 "masterelement.h"
/**
@@ -28,12 +45,9 @@ MasterElement::~MasterElement() {
* For this class element must be a slave
* @param elmt
*/
void MasterElement::linkToElement(Element *elmt) {
// check if this element is already linked
if (connected_elements.contains(elmt)) return;
//check if elmt is a slave
if (elmt->linkType() == SlaveNO || elmt->linkType() == SlaveNC) {
void MasterElement::linkToElement(Element *elmt) {
// check if element is slave and if isn't already linked
if (elmt->linkType() == Slave && !connected_elements.contains(elmt)) {
///TODO create the cross ref and connection
connected_elements << elmt;
elmt->linkToElement(this);
@@ -49,7 +63,7 @@ void MasterElement::unlinkAllElements() {
if (!isFree()) {
foreach(Element *elmt, connected_elements) {
unlinkElement(elmt);
}
}
}
}

View File

@@ -1,3 +1,20 @@
/*
Copyright 2006-2014 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 MASTERELEMENT_H
#define MASTERELEMENT_H

View File

@@ -0,0 +1,81 @@
/*
Copyright 2006-2014 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 "slaveelement.h"
/**
* @brief SlaveElement::SlaveElement
* Default constructor
* @param location location of xml definition
* @param qgi parent QGraphicItem
* @param s parent diagram
* @param state int used to know if the creation of element have error
*/
SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
CustomElement(location, qgi, s, state)
{
link_type_ = Slave;
}
/**
* @brief SlaveElement::~SlaveElement
* default destructor
*/
SlaveElement::~SlaveElement() {
unlinkAllElements();
}
/**
* @brief SlaveElement::linkToElement
* Link this slave to another element
* For this class element must be a master
* @param elmt
*/
void SlaveElement::linkToElement(Element *elmt) {
// check if element is master and if isn't already linked
if (elmt->linkType() == Master && !connected_elements.contains(elmt)) {
if(!isFree()) unlinkAllElements();
connected_elements << elmt;
elmt->linkToElement(this);
}
}
/**
* @brief SlaveElement::unlinkAllElements
* Unlink all of the element in the QList connected_elements
*/
void SlaveElement::unlinkAllElements() {
// if this element is free no need to do something
if (!isFree()) {
foreach(Element *elmt, connected_elements) {
unlinkElement(elmt);
}
}
}
/**
* @brief SlaveElement::unlinkElement
* Unlink the given elmt in parametre
* @param elmt
*/
void SlaveElement::unlinkElement(Element *elmt) {
//Ensure elmt is linked to this element
if (connected_elements.contains(elmt)) {
connected_elements.removeOne(elmt);
elmt->unlinkElement(this);
}
}

View File

@@ -0,0 +1,39 @@
/*
Copyright 2006-2014 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 SLAVEELEMENT_H
#define SLAVEELEMENT_H
#include "customelement.h"
class SlaveElement : public CustomElement
{
Q_OBJECT
public:
explicit SlaveElement (const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
~SlaveElement();
virtual void linkToElement(Element *elmt);
virtual void unlinkAllElements();
virtual void unlinkElement(Element *elmt);
signals:
public slots:
};
#endif // SLAVEELEMENT_H