[qet] qet/qet: [4780] minor fix : master element doesn' t properly update her tagged text 'label' when he contain %F and %F contain himself %f or %id.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4780
Author:   blacksun
Date:     2016-11-15 11:18:32 +0100 (Tue, 15 Nov 2016)
Log Message:
-----------
minor fix : master element doesn't properly update her tagged text 'label' when he contain %F and %F contain himself %f or %id.

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/masterelement.cpp

Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp	2016-11-15 09:23:36 UTC (rev 4779)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp	2016-11-15 10:18:32 UTC (rev 4780)
@@ -19,6 +19,7 @@
 #include "crossrefitem.h"
 #include "elementtextitem.h"
 #include "diagram.h"
+#include <QRegularExpression>
 
 /**
  * @brief MasterElement::MasterElement
@@ -149,33 +150,48 @@
  * update label of this element
  * and the comment item if he's displayed.
  */
-void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
-	QString newstr = new_info["label"].toString();
-	newstr = autonum::AssignVariables::formulaToLabel(newstr, m_autoNum_seq, diagram(), this);
+void MasterElement::updateLabel(DiagramContext old_info, DiagramContext new_info)
+{
+	const QString old_label = old_info["label"].toString();
+	const QString new_label = new_info["label"].toString();
 
+	QString newstr = autonum::AssignVariables::formulaToLabel(new_label, m_autoNum_seq, diagram(), this);
+
+	ElementTextItem *eti = taggedText("label");
+
 		//Label of element
-	if (old_info["label"].toString() != newstr) {
-		if (new_info["label"].toString().isEmpty())
+	if (eti && (eti->toPlainText() != newstr))
+	{
+		if (new_label.isEmpty())
+		{
 			setTaggedText("label", "_", false);
-		else {
+		}
+		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")) {
+			//If autonum formula have %id %f or %F (because %F can itself contain %id or %f),
+			//we connect the change of folio position, to keep up to date the label.
+		if (diagram() && diagram()->project())
+		{
+			if (old_label.contains(QRegularExpression("%id|%f|%F"))  && !new_label.contains(QRegularExpression("%id|%f|%F")))
+			{
 				disconnect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
 			}
-			else if (new_info["label"].toString().contains("%id")) {
+			else if (new_label.contains(QRegularExpression("%id|%f|%F")))
+			{
 				connect(diagram()->project(), &QETProject::projectDiagramsOrderChanged, this, &MasterElement::folioIdChange);
 			}
 		}
 	}
 
-	if (ElementTextItem *eti = taggedText("label")) {
-		new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
+	if (eti)
+	{
+		new_label.isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
 	}
 
+
 	//Delete or update the xref
 	if (cri_) {
 		cri_ -> updateLabel();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/