[qet] [4514] Added position and folios variables handling to Elements (Master, Slave and Simple) Label

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


Revision: 4514
Author:   dfochi
Date:     2016-05-24 20:21:52 +0200 (Tue, 24 May 2016)
Log Message:
-----------
Added position and folios variables handling to Elements (Master, Slave and Simple) Label

Modified Paths:
--------------
    trunk/sources/projectconfigpages.cpp
    trunk/sources/qetgraphicsitem/customelement.cpp
    trunk/sources/qetgraphicsitem/customelement.h
    trunk/sources/qetgraphicsitem/masterelement.cpp
    trunk/sources/qetgraphicsitem/masterelement.h
    trunk/sources/qetgraphicsitem/simpleelement.cpp
    trunk/sources/qetgraphicsitem/simpleelement.h
    trunk/sources/qetgraphicsitem/slaveelement.cpp

Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/projectconfigpages.cpp	2016-05-24 18:21:52 UTC (rev 4514)
@@ -382,7 +382,6 @@
 
 	//	Auto Folio Numbering
 	connect (m_faw, SIGNAL (applyPressed()),				 this, SLOT (applyAutoNum()));
-	connect (m_faw, SIGNAL (m_autonumber_tabs_rb_clicked()), this, SLOT (tabChanged(int)));
 }
 
 /**

Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/qetgraphicsitem/customelement.cpp	2016-05-24 18:21:52 UTC (rev 4514)
@@ -23,6 +23,7 @@
 #include "elementdefinition.h"
 #include <iostream>
 #include "terminal.h"
+#include "diagramposition.h"
 
 /**
 	Constructeur de la classe CustomElement. Permet d'instancier un element
@@ -986,3 +987,11 @@
 	}
 	return NULL;
 }
+
+QString CustomElement::assignVariables(QString label, Element *elmt){
+	label.replace("%f", QString::number(elmt->diagram()->folioIndex()+1));
+	label.replace("%F", elmt->diagram() -> border_and_titleblock.folio());
+	label.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number()));
+	label.replace("%l", elmt->diagram() -> convertPosition(elmt -> scenePos()).letter());
+	return label;
+}

Modified: trunk/sources/qetgraphicsitem/customelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.h	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/qetgraphicsitem/customelement.h	2016-05-24 18:21:52 UTC (rev 4514)
@@ -93,6 +93,7 @@
 	virtual bool validOrientationAttribute(const QDomElement &);
 	virtual void setPainterStyle(QDomElement &, QPainter &);
 	ElementTextItem* setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable=false);
+	QString assignVariables (QString, Element *);
 };
 
 /**

Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp	2016-05-24 18:21:52 UTC (rev 4514)
@@ -33,6 +33,8 @@
 {
 	link_type_ = Master;
 	connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
+	connect(this, SIGNAL(xChanged()),this, SLOT(changeElementInfo()));
+	connect(this, SIGNAL(yChanged()),this, SLOT(changeElementInfo()));
 }
 
 /**
@@ -118,17 +120,34 @@
 }
 
 /**
+ * @brief MasterElement::changeElementInfo()
+ * Update label if it contains %c, %l, %f or %F variables
+ */
+void MasterElement::changeElementInfo(){
+	QString temp_label = this->elementInformations()["label"].toString();
+	if (temp_label.contains("\%l")||temp_label.contains("\%c")||temp_label.contains("\%f")||temp_label.contains("\%F")) {
+		if (this->diagram()!=NULL)
+			this->updateLabel(this->elementInformations(),this->elementInformations());
+	}
+}
+
+/**
  * @brief MasterElement::updateLabel
  * 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();
+	Element	*elmt = this;
+	newstr = assignVariables(newstr, elmt);
+
 	//Label of element
-	if (old_info["label"].toString() != new_info["label"].toString()) {
+	if (old_info["label"].toString() != newstr) {
 		if (new_info["label"].toString().isEmpty())
 			setTaggedText("label", "_", false);
-		else
-			setTaggedText("label", new_info["label"].toString(), true);
+		else {
+			setTaggedText("label", newstr, true);
+		}
 	}
 
 	if (ElementTextItem *eti = taggedText("label")) {

Modified: trunk/sources/qetgraphicsitem/masterelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.h	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/qetgraphicsitem/masterelement.h	2016-05-24 18:21:52 UTC (rev 4514)
@@ -45,6 +45,7 @@
 
 	public slots:
 		void updateLabel(DiagramContext old_info, DiagramContext new_info);
+		void changeElementInfo();
 
 	private:
 		bool aboutDeleteXref ();

Modified: trunk/sources/qetgraphicsitem/simpleelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.cpp	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/qetgraphicsitem/simpleelement.cpp	2016-05-24 18:21:52 UTC (rev 4514)
@@ -18,6 +18,7 @@
 #include "simpleelement.h"
 #include "commentitem.h"
 #include "elementtextitem.h"
+
 /**
  * @brief SimpleElement::SimpleElement
  * @param location
@@ -31,6 +32,8 @@
 {
 	link_type_ = Simple;
 	connect(this, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)), this, SLOT(updateLabel(DiagramContext, DiagramContext)));
+	connect(this, SIGNAL(xChanged()),this, SLOT(changeElementInfo()));
+	connect(this, SIGNAL(yChanged()),this, SLOT(changeElementInfo()));
 }
 
 /**
@@ -52,16 +55,33 @@
 }
 
 /**
+ * @brief SimpleElement::changeElementInfo()
+ * Update label if it contains %c, %l, %f or %F variables
+ */
+void SimpleElement::changeElementInfo(){
+	QString temp_label = this->elementInformations()["label"].toString();
+	if (temp_label.contains("\%l")||temp_label.contains("\%c")||temp_label.contains("\%f")||temp_label.contains("\%F")) {
+		if (this->diagram()!=NULL)
+			this->updateLabel(this->elementInformations(),this->elementInformations());
+	}
+}
+
+/**
  * @brief SimpleElement::updateLabel
  * update label of this element
  */
 void SimpleElement::updateLabel(DiagramContext old_info, DiagramContext new_info) {
+	QString label = new_info["label"].toString();
+	Element *elmt = this;
+	label = assignVariables(label,elmt);
+
 	//Label of element
-	if (old_info["label"].toString() != new_info["label"].toString()) {
+	if (old_info["label"].toString() != label) {
 		if (new_info["label"].toString().isEmpty())
 			setTaggedText("label", "_", false);
-		else
-			setTaggedText("label", new_info["label"].toString(), true);
+		else {
+			setTaggedText("label", label, true);
+		}
 	}
 
 	if (ElementTextItem *eti = taggedText("label")) {

Modified: trunk/sources/qetgraphicsitem/simpleelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/simpleelement.h	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/qetgraphicsitem/simpleelement.h	2016-05-24 18:21:52 UTC (rev 4514)
@@ -41,6 +41,7 @@
 
 	public slots:
 		void updateLabel(DiagramContext old_info, DiagramContext new_info);
+		void changeElementInfo();
 
 	private:
 		CommentItem *m_comment_item;

Modified: trunk/sources/qetgraphicsitem/slaveelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/slaveelement.cpp	2016-05-24 13:29:39 UTC (rev 4513)
+++ trunk/sources/qetgraphicsitem/slaveelement.cpp	2016-05-24 18:21:52 UTC (rev 4514)
@@ -134,10 +134,8 @@
 		label = elmt -> elementInformations()["label"].toString();
 		XRefProperties xrp = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
 		Xreflabel = xrp.slaveLabel();
-		Xreflabel.replace("%f", QString::number(elmt->diagram()->folioIndex()+1));
-		Xreflabel.replace("%F", elmt->diagram() -> border_and_titleblock.folio());
-		Xreflabel.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number()));
-		Xreflabel.replace("%l", elmt->diagram() -> convertPosition(elmt -> scenePos()).letter());
+		Xreflabel = assignVariables(Xreflabel, elmt);
+		label = assignVariables(label, elmt);
 	}
 
 	// set the new label


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