add base for master element feature

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2863 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-02-18 20:44:54 +00:00
parent 9d68da7fff
commit cddc841916
14 changed files with 162 additions and 19 deletions

View File

@@ -33,6 +33,7 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) :
internal_connections_(false),
must_highlight_(false)
{
link_type_ = 0;
uuid_ = QUuid::createUuid();
setZValue(10);
}

View File

@@ -107,6 +107,7 @@ class Element : public QetGraphicsItem {
virtual void unlinkElement(Element *) {}
void initLink(QETProject *);
QList<Element *> linkedElements () const;
virtual int linkType() const {return link_type_;} // @return the linkable type
void newUuid() {uuid_ = QUuid::createUuid();} //create new uuid for this element
//ATTRIBUTES related to linked element
@@ -114,6 +115,7 @@ class Element : public QetGraphicsItem {
QList <Element *> connected_elements;
QList <QUuid> tmp_uuids_link;
QUuid uuid_;
int link_type_;
//METHODS related to information
public:
@@ -133,8 +135,6 @@ class Element : public QetGraphicsItem {
virtual QString typeId() const = 0;
/// @return the human name for this element
virtual QString name() const = 0;
/// @return the linkable type
virtual int linkType() const = 0;
virtual bool isHighlighted() const;
virtual void setHighlighted(bool);

View File

@@ -0,0 +1,67 @@
#include "masterelement.h"
/**
* @brief MasterElement::MasterElement
* 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
*/
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
CustomElement(location, qgi, s, state)
{
link_type_ = Master;
}
/**
* @brief MasterElement::~MasterElement
* default destructor
*/
MasterElement::~MasterElement() {
unlinkAllElements();
}
/**
* @brief MasterElement::linkToElement
* Link this master to another element
* 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) {
///TODO create the cross ref and connection
connected_elements << elmt;
elmt->linkToElement(this);
}
}
/**
* @brief MasterElement::unlinkAllElements
* Unlink all of the element in the QList connected_elements
*/
void MasterElement::unlinkAllElements() {
// if this element is free no need to do something
if (!isFree()) {
foreach(Element *elmt, connected_elements) {
unlinkElement(elmt);
}
}
}
/**
* @brief MasterElement::unlinkElement
* Unlink the given elmt in parametre
* @param elmt element to unlink from this
*/
void MasterElement::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,23 @@
#ifndef MASTERELEMENT_H
#define MASTERELEMENT_H
#include "customelement.h"
class MasterElement : public CustomElement
{
Q_OBJECT
public:
explicit MasterElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
~MasterElement();
virtual void linkToElement(Element *elmt);
virtual void unlinkAllElements();
virtual void unlinkElement(Element *elmt);
signals:
public slots:
};
#endif // MASTERELEMENT_H

View File

@@ -92,14 +92,6 @@ void ReportElement::unlinkElement(Element *elmt) {
unlinkAllElements();
}
/**
* @brief ReportElement::linkType
* @return the kind of link type
*/
int ReportElement::linkType() const {
return link_type_;
}
/**
* @brief ReportElement::setLabel
* Set new label and call updatelabel

View File

@@ -35,10 +35,8 @@ class ReportElement : public CustomElement {
virtual void linkToElement(Element *);
virtual void unlinkAllElements();
virtual void unlinkElement(Element *elmt);
virtual int linkType() const;
private:
int link_type_;
int inverse_report;
QString label_;

View File

@@ -19,8 +19,6 @@
SimpleElement::SimpleElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
CustomElement(location, qgi, s, state)
{}
int SimpleElement::linkType() const {
return Simple;
{
link_type_ = Simple;
}

View File

@@ -31,8 +31,6 @@ class SimpleElement : public CustomElement {
public :
explicit SimpleElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0);
virtual int linkType() const;
signals:
public slots: