[qet] [2682] report element: label update when the linked folio report position change |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2682
Author: blacksun
Date: 2013-12-29 23:47:31 +0100 (Sun, 29 Dec 2013)
Log Message:
-----------
report element: label update when the linked folio report position change
Modified Paths:
--------------
trunk/sources/qetgraphicsitem/element.h
trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
trunk/sources/qetgraphicsitem/qetgraphicsitem.h
trunk/sources/qetgraphicsitem/reportelement.cpp
trunk/sources/qetgraphicsitem/reportelement.h
trunk/sources/ui/folioreportproperties.cpp
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2013-12-29 18:39:03 UTC (rev 2681)
+++ trunk/sources/qetgraphicsitem/element.h 2013-12-29 22:47:31 UTC (rev 2682)
@@ -51,12 +51,12 @@
enum { Type = UserType + 1000 };
protected:
+ QList <Element *> connected_elements;
private:
QSize dimensions;
QPoint hotspot_coord;
QPixmap preview;
- QList <Element *> connected_elements;
// methods
public:
@@ -82,6 +82,7 @@
virtual int maxTerminalsCount() const = 0;
bool isFree () const;
virtual void linkToElement(Element *) {}
+ virtual void unLinkAllElements() {}
/**
Draw this element
*/
Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2013-12-29 18:39:03 UTC (rev 2681)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.cpp 2013-12-29 22:47:31 UTC (rev 2682)
@@ -54,6 +54,7 @@
// 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);
}
Modified: trunk/sources/qetgraphicsitem/qetgraphicsitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/qetgraphicsitem.h 2013-12-29 18:39:03 UTC (rev 2681)
+++ trunk/sources/qetgraphicsitem/qetgraphicsitem.h 2013-12-29 22:47:31 UTC (rev 2682)
@@ -37,6 +37,7 @@
virtual void editProperty ()=0;
signals:
+ void positionChange(QPointF);
public slots:
Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp 2013-12-29 18:39:03 UTC (rev 2681)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp 2013-12-29 22:47:31 UTC (rev 2682)
@@ -25,11 +25,68 @@
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 <Element *> 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("_");
+ }
+}
Modified: trunk/sources/qetgraphicsitem/reportelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.h 2013-12-29 18:39:03 UTC (rev 2681)
+++ trunk/sources/qetgraphicsitem/reportelement.h 2013-12-29 22:47:31 UTC (rev 2682)
@@ -32,12 +32,15 @@
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
Modified: trunk/sources/ui/folioreportproperties.cpp
===================================================================
--- trunk/sources/ui/folioreportproperties.cpp 2013-12-29 18:39:03 UTC (rev 2681)
+++ trunk/sources/ui/folioreportproperties.cpp 2013-12-29 22:47:31 UTC (rev 2682)
@@ -66,9 +66,5 @@
* 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_);
}