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

@@ -22,6 +22,7 @@
#include "QDomElement"
#include "qetgraphicsitem/simpleelement.h"
#include "qetgraphicsitem/reportelement.h"
#include "qetgraphicsitem/masterelement.h"
ElementFactory* ElementFactory::factory_ = 0;
/**
@@ -46,7 +47,9 @@ Element * ElementFactory::createElement(const ElementsLocation &location, QGraph
if (element_definition->xml().hasAttribute("link_type")) {
QString link_type = element_definition->xml().attribute("link_type");
if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, s, state));
if (link_type == "master") return (new MasterElement(location, qgi, s, state));
}
//default if nothing match for link_type
return (new SimpleElement(location, qgi, s, state));
}

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:

View File

@@ -33,6 +33,7 @@ elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent)
{
frp_ = 0;
eiw_ = 0;
mpw_ = 0;
buildInterface();
}
@@ -105,7 +106,6 @@ void elementpropertieswidget::buildInterface() {
setWindowTitle(tr("Propri\351t\351s de l'\351l\351ment"));
tab_ = new QTabWidget(this);
tab_ -> addTab(generalWidget(), tr("G\351n\351ral"));
//Add tab according to the element
switch (element_ -> linkType()) {
@@ -122,6 +122,8 @@ void elementpropertieswidget::buildInterface() {
tab_ -> addTab(frp_, tr("Report de folio"));
break;
case Element::Master:
mpw_ = new MasterPropertiesWidget(this);
tab_ -> addTab(mpw_, tr("R\351f\351rence crois\351 (maitre)"));
eiw_ = new ElementInfoWidget(element_, this);
tab_ -> addTab(eiw_, tr("Information"));
break;
@@ -135,6 +137,8 @@ void elementpropertieswidget::buildInterface() {
break;
}
tab_ -> addTab(generalWidget(), tr("G\351n\351ral"));
dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset,
Qt::Horizontal, this);
connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*)));

View File

@@ -23,6 +23,7 @@
#include <diagram.h>
#include <folioreportproperties.h>
#include <elementinfowidget.h>
#include <masterpropertieswidget.h>
class elementpropertieswidget : public QDialog
{
@@ -48,6 +49,7 @@ class elementpropertieswidget : public QDialog
private:
FolioReportProperties *frp_;
ElementInfoWidget *eiw_;
MasterPropertiesWidget *mpw_;
QDialogButtonBox *dbb;
Element *element_;
Diagram *diagram_;

View File

@@ -0,0 +1,14 @@
#include "masterpropertieswidget.h"
#include "ui_masterpropertieswidget.h"
MasterPropertiesWidget::MasterPropertiesWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::MasterPropertiesWidget)
{
ui->setupUi(this);
}
MasterPropertiesWidget::~MasterPropertiesWidget()
{
delete ui;
}

View File

@@ -0,0 +1,22 @@
#ifndef MASTERPROPERTIESWIDGET_H
#define MASTERPROPERTIESWIDGET_H
#include <QWidget>
namespace Ui {
class MasterPropertiesWidget;
}
class MasterPropertiesWidget : public QWidget
{
Q_OBJECT
public:
explicit MasterPropertiesWidget(QWidget *parent = 0);
~MasterPropertiesWidget();
private:
Ui::MasterPropertiesWidget *ui;
};
#endif // MASTERPROPERTIESWIDGET_H

View File

@@ -0,0 +1,21 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>MasterPropertiesWidget</class>
<widget class="QWidget" name="MasterPropertiesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>