From cddc841916b269ab1abea67eaccf88353e9c396c Mon Sep 17 00:00:00 2001 From: blacksun Date: Tue, 18 Feb 2014 20:44:54 +0000 Subject: [PATCH] add base for master element feature git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2863 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/factory/elementfactory.cpp | 3 + sources/qetgraphicsitem/element.cpp | 1 + sources/qetgraphicsitem/element.h | 4 +- sources/qetgraphicsitem/masterelement.cpp | 67 +++++++++++++++++++++++ sources/qetgraphicsitem/masterelement.h | 23 ++++++++ sources/qetgraphicsitem/reportelement.cpp | 8 --- sources/qetgraphicsitem/reportelement.h | 2 - sources/qetgraphicsitem/simpleelement.cpp | 6 +- sources/qetgraphicsitem/simpleelement.h | 2 - sources/ui/elementpropertieswidget.cpp | 6 +- sources/ui/elementpropertieswidget.h | 2 + sources/ui/masterpropertieswidget.cpp | 14 +++++ sources/ui/masterpropertieswidget.h | 22 ++++++++ sources/ui/masterpropertieswidget.ui | 21 +++++++ 14 files changed, 162 insertions(+), 19 deletions(-) create mode 100644 sources/qetgraphicsitem/masterelement.cpp create mode 100644 sources/qetgraphicsitem/masterelement.h create mode 100644 sources/ui/masterpropertieswidget.cpp create mode 100644 sources/ui/masterpropertieswidget.h create mode 100644 sources/ui/masterpropertieswidget.ui diff --git a/sources/factory/elementfactory.cpp b/sources/factory/elementfactory.cpp index d5084127f..4ad66ea11 100644 --- a/sources/factory/elementfactory.cpp +++ b/sources/factory/elementfactory.cpp @@ -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)); } diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 4214b38a5..99bcbfa12 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -33,6 +33,7 @@ Element::Element(QGraphicsItem *parent, Diagram *scene) : internal_connections_(false), must_highlight_(false) { + link_type_ = 0; uuid_ = QUuid::createUuid(); setZValue(10); } diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 988763a16..e4192b76d 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -107,6 +107,7 @@ class Element : public QetGraphicsItem { virtual void unlinkElement(Element *) {} void initLink(QETProject *); QList 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 connected_elements; QList 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); diff --git a/sources/qetgraphicsitem/masterelement.cpp b/sources/qetgraphicsitem/masterelement.cpp new file mode 100644 index 000000000..04b0e4350 --- /dev/null +++ b/sources/qetgraphicsitem/masterelement.cpp @@ -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); + } +} diff --git a/sources/qetgraphicsitem/masterelement.h b/sources/qetgraphicsitem/masterelement.h new file mode 100644 index 000000000..eb3f354f3 --- /dev/null +++ b/sources/qetgraphicsitem/masterelement.h @@ -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 diff --git a/sources/qetgraphicsitem/reportelement.cpp b/sources/qetgraphicsitem/reportelement.cpp index 66074c90c..1cbf703bf 100644 --- a/sources/qetgraphicsitem/reportelement.cpp +++ b/sources/qetgraphicsitem/reportelement.cpp @@ -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 diff --git a/sources/qetgraphicsitem/reportelement.h b/sources/qetgraphicsitem/reportelement.h index 6e86b2785..a3fd78348 100644 --- a/sources/qetgraphicsitem/reportelement.h +++ b/sources/qetgraphicsitem/reportelement.h @@ -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_; diff --git a/sources/qetgraphicsitem/simpleelement.cpp b/sources/qetgraphicsitem/simpleelement.cpp index 077eeeeba..657e8c314 100644 --- a/sources/qetgraphicsitem/simpleelement.cpp +++ b/sources/qetgraphicsitem/simpleelement.cpp @@ -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; } diff --git a/sources/qetgraphicsitem/simpleelement.h b/sources/qetgraphicsitem/simpleelement.h index b9666bb70..a0d326a40 100644 --- a/sources/qetgraphicsitem/simpleelement.h +++ b/sources/qetgraphicsitem/simpleelement.h @@ -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: diff --git a/sources/ui/elementpropertieswidget.cpp b/sources/ui/elementpropertieswidget.cpp index 352a50cdf..6d447ce41 100644 --- a/sources/ui/elementpropertieswidget.cpp +++ b/sources/ui/elementpropertieswidget.cpp @@ -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*))); diff --git a/sources/ui/elementpropertieswidget.h b/sources/ui/elementpropertieswidget.h index f2bd3d119..26a698230 100644 --- a/sources/ui/elementpropertieswidget.h +++ b/sources/ui/elementpropertieswidget.h @@ -23,6 +23,7 @@ #include #include #include +#include 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_; diff --git a/sources/ui/masterpropertieswidget.cpp b/sources/ui/masterpropertieswidget.cpp new file mode 100644 index 000000000..bbfc333ae --- /dev/null +++ b/sources/ui/masterpropertieswidget.cpp @@ -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; +} diff --git a/sources/ui/masterpropertieswidget.h b/sources/ui/masterpropertieswidget.h new file mode 100644 index 000000000..7d95bb93c --- /dev/null +++ b/sources/ui/masterpropertieswidget.h @@ -0,0 +1,22 @@ +#ifndef MASTERPROPERTIESWIDGET_H +#define MASTERPROPERTIESWIDGET_H + +#include + +namespace Ui { + class MasterPropertiesWidget; +} + +class MasterPropertiesWidget : public QWidget +{ + Q_OBJECT + + public: + explicit MasterPropertiesWidget(QWidget *parent = 0); + ~MasterPropertiesWidget(); + + private: + Ui::MasterPropertiesWidget *ui; +}; + +#endif // MASTERPROPERTIESWIDGET_H diff --git a/sources/ui/masterpropertieswidget.ui b/sources/ui/masterpropertieswidget.ui new file mode 100644 index 000000000..2d6a14bbd --- /dev/null +++ b/sources/ui/masterpropertieswidget.ui @@ -0,0 +1,21 @@ + + + + + MasterPropertiesWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + +