diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 83224d611..05c2a556d 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -51,12 +51,12 @@ class Element : public QetGraphicsItem { enum { Type = UserType + 1000 }; protected: + QList connected_elements; private: QSize dimensions; QPoint hotspot_coord; QPixmap preview; - QList connected_elements; // methods public: @@ -82,6 +82,7 @@ class Element : public QetGraphicsItem { virtual int maxTerminalsCount() const = 0; bool isFree () const; virtual void linkToElement(Element *) {} + virtual void unLinkAllElements() {} /** Draw this element */ diff --git a/sources/qetgraphicsitem/qetgraphicsitem.cpp b/sources/qetgraphicsitem/qetgraphicsitem.cpp index 946d83aae..b49447498 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.cpp +++ b/sources/qetgraphicsitem/qetgraphicsitem.cpp @@ -54,6 +54,7 @@ void QetGraphicsItem::setPos(const QPointF &p) { // arrondit l'ordonnee a 10 px pres int p_y = qRound(p.y() / (Diagram::yGrid * 1.0)) * Diagram::yGrid; QGraphicsItem::setPos(p_x, p_y); + emit positionChange(pos()); } else QGraphicsItem::setPos(p); } diff --git a/sources/qetgraphicsitem/qetgraphicsitem.h b/sources/qetgraphicsitem/qetgraphicsitem.h index 9b9de507d..096b4ac78 100644 --- a/sources/qetgraphicsitem/qetgraphicsitem.h +++ b/sources/qetgraphicsitem/qetgraphicsitem.h @@ -37,6 +37,7 @@ class QetGraphicsItem : public QGraphicsObject { virtual void editProperty ()=0; signals: + void positionChange(QPointF); public slots: diff --git a/sources/qetgraphicsitem/reportelement.cpp b/sources/qetgraphicsitem/reportelement.cpp index 39b957de2..f7b0cb3c4 100644 --- a/sources/qetgraphicsitem/reportelement.cpp +++ b/sources/qetgraphicsitem/reportelement.cpp @@ -25,11 +25,68 @@ ReportElement::ReportElement(const ElementsLocation &location, QGraphicsItem *qg texts().at(0)->setNoEditable(); } +/** + * @brief ReportElement::linkToElement + * Link this element to the other element + * @param elmt + * element to be linked with this + */ void ReportElement::linkToElement(Element * elmt) { - texts().at(0)->setPlainText(QString ("%1-%2").arg(elmt->diagram()->folioIndex() + 1) - .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString())); + //ensure elmt isn't already linked + bool i=true; + if (!this->isFree()){ + if (connected_elements.first() == elmt) i = false; + } + + //ensure elmt is a report + if (elmt->linkType() == REPORT && i) { + unLinkAllElements(); + connected_elements << elmt; + connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + updateLabel(); + elmt->linkToElement(this); + } } +/** + * @brief ReportElement::unLinkAllElements + * Unlink all of the element in the QList connected_elements + */ +void ReportElement::unLinkAllElements(){ + if (!isFree()){ + QList tmp_elmt = connected_elements; + + foreach(Element *elmt, connected_elements) { + disconnect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel())); + } + connected_elements.clear(); + updateLabel(); + + foreach(Element *elmt, tmp_elmt){ + elmt->unLinkAllElements(); + } + } +} + +/** + * @brief ReportElement::linkType + * @return the kind of link type + */ int ReportElement::linkType() const { return REPORT; } + +/** + * @brief ReportElement::updateLabel + * Update the displayed label. + * ie the folio and position of the linked folio report + */ +void ReportElement::updateLabel() { + if (!connected_elements.isEmpty()){ + Element *elmt = connected_elements.at(0); + texts().at(0)->setPlainText(QString ("%1-%2").arg(elmt->diagram()->folioIndex() + 1) + .arg(elmt->diagram() -> convertPosition(elmt -> scenePos()).toString())); + } else { + texts().at(0)->setPlainText("_"); + } +} diff --git a/sources/qetgraphicsitem/reportelement.h b/sources/qetgraphicsitem/reportelement.h index 6e2151cd5..edcbc5c9d 100644 --- a/sources/qetgraphicsitem/reportelement.h +++ b/sources/qetgraphicsitem/reportelement.h @@ -32,12 +32,15 @@ class ReportElement : public CustomElement { public : explicit ReportElement(const ElementsLocation &, QGraphicsItem * = 0, Diagram * = 0, int * = 0); virtual void linkToElement(Element *); - + virtual void unLinkAllElements(); virtual int linkType() const; + private: + signals: - public slots: + private slots: + void updateLabel(); }; #endif // REPORTELEMENT_H diff --git a/sources/ui/folioreportproperties.cpp b/sources/ui/folioreportproperties.cpp index e6d94b719..a9bd1b22d 100644 --- a/sources/ui/folioreportproperties.cpp +++ b/sources/ui/folioreportproperties.cpp @@ -66,9 +66,5 @@ void FolioReportProperties::BuildRadioList() { * Apply the new properties for this folio report */ void FolioReportProperties::Apply() { - if (element_to_link) { - element_to_link->linkToElement(element_); - element_->linkToElement(element_to_link); - } - + if (element_to_link) element_to_link->linkToElement(element_); }