[qet] qet/qet: [4744] Keep up to date the label of element when folio position change ( Formula contain %id) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 4744
Author: blacksun
Date: 2016-10-17 14:17:45 +0200 (Mon, 17 Oct 2016)
Log Message:
-----------
Keep up to date the label of element when folio position change (Formula contain %id)
Modified Paths:
--------------
trunk/sources/qetgraphicsitem/masterelement.cpp
trunk/sources/qetgraphicsitem/masterelement.h
trunk/sources/qetgraphicsitem/simpleelement.cpp
trunk/sources/qetgraphicsitem/simpleelement.h
Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp 2016-10-15 13:39:02 UTC (rev 4743)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp 2016-10-17 12:17:45 UTC (rev 4744)
@@ -18,6 +18,7 @@
#include "masterelement.h"
#include "crossrefitem.h"
#include "elementtextitem.h"
+#include "diagram.h"
/**
* @brief MasterElement::MasterElement
@@ -123,6 +124,15 @@
}
/**
+ * @brief MasterElement::folioIdChange
+ * Used to update the label of this item when the folio id change
+ */
+void MasterElement::folioIdChange() {
+ DiagramContext dc =elementInformations();
+ setTaggedText("label", assignVariables(dc["label"].toString(), this), true);
+}
+
+/**
* @brief MasterElement::changeElementInfo()
* Update label if it contains %c, %l, %f or %F variables
*/
@@ -144,7 +154,7 @@
Element *elmt = this;
newstr = assignVariables(newstr, elmt);
- //Label of element
+ //Label of element
if (old_info["label"].toString() != newstr) {
if (new_info["label"].toString().isEmpty())
setTaggedText("label", "_", false);
@@ -151,6 +161,16 @@
else {
setTaggedText("label", newstr, true);
}
+
+ //If autonum formula have %id we connect the change of folio position, to keep up to date the label.
+ if (diagram() && diagram()->project()) {
+ if (old_info["label"].toString().contains("%id") && !new_info["label"].toString().contains("%id")) {
+ disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
+ }
+ else if (new_info["label"].toString().contains("%id")) {
+ connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
+ }
+ }
}
if (ElementTextItem *eti = taggedText("label")) {
Modified: trunk/sources/qetgraphicsitem/masterelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.h 2016-10-15 13:39:02 UTC (rev 4743)
+++ trunk/sources/qetgraphicsitem/masterelement.h 2016-10-17 12:17:45 UTC (rev 4744)
@@ -43,6 +43,9 @@
signals:
+ private:
+ void folioIdChange();
+
public slots:
void updateLabel(DiagramContext old_info, DiagramContext new_info);
void changeElementInfo();
Modified: trunk/sources/qetgraphicsitem/simpleelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.cpp 2016-10-15 13:39:02 UTC (rev 4743)
+++ trunk/sources/qetgraphicsitem/simpleelement.cpp 2016-10-17 12:17:45 UTC (rev 4744)
@@ -18,6 +18,7 @@
#include "simpleelement.h"
#include "commentitem.h"
#include "elementtextitem.h"
+#include "diagram.h"
/**
* @brief SimpleElement::SimpleElement
@@ -57,6 +58,15 @@
}
/**
+ * @brief SimpleElement::folioIdChange
+ * Use to update the label of this item when the foio id change
+ */
+void SimpleElement::folioIdChange() {
+ DiagramContext dc =elementInformations();
+ setTaggedText("label", assignVariables(dc["label"].toString(), this), true);
+}
+
+/**
* @brief SimpleElement::changeElementInfo()
* Update label if it contains %c, %l, %f or %F variables
*/
@@ -77,7 +87,7 @@
Element *elmt = this;
label = assignVariables(label,elmt);
- //Label of element
+ //Label of element
if (old_info["label"].toString() != label) {
if (new_info["label"].toString().isEmpty())
setTaggedText("label", "_", false);
@@ -84,7 +94,17 @@
else {
setTaggedText("label", label, true);
}
+
+ //If autonum formula have %id we connect the change of folio position, to keep up to date the label.
+ if (diagram() && diagram()->project()) {
+ if (old_info["label"].toString().contains("%id") && !new_info["label"].toString().contains("%id")) {
+ disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &SimpleElement::folioIdChange);
+ }
+ else if (new_info["label"].toString().contains("%id")) {
+ connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &SimpleElement::folioIdChange);
+ }
}
+ }
if (ElementTextItem *eti = taggedText("label")) {
new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
Modified: trunk/sources/qetgraphicsitem/simpleelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.h 2016-10-15 13:39:02 UTC (rev 4743)
+++ trunk/sources/qetgraphicsitem/simpleelement.h 2016-10-17 12:17:45 UTC (rev 4744)
@@ -39,6 +39,9 @@
signals:
+ private:
+ void folioIdChange();
+
public slots:
void updateLabel(DiagramContext old_info, DiagramContext new_info);
void changeElementInfo();
@@ -46,7 +49,6 @@
private:
CommentItem *m_comment_item;
CommentItem *m_location_item;
-
};
#endif // SIMPLEELEMENT_H