[qet] [4591] Fix Element Label when opening older QET versions.

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


Revision: 4591
Author:   dfochi
Date:     2016-07-25 21:18:26 +0200 (Mon, 25 Jul 2016)
Log Message:
-----------
Fix Element Label when opening older QET versions. Fix old user created element label's handling on newer QET versions

Modified Paths:
--------------
    trunk/sources/qetgraphicsitem/customelement.cpp
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetgraphicsitem/element.h

Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp	2016-07-25 14:17:54 UTC (rev 4590)
+++ trunk/sources/qetgraphicsitem/customelement.cpp	2016-07-25 19:18:26 UTC (rev 4591)
@@ -726,6 +726,18 @@
 	eti -> setFollowParentRotations(e.attribute("rotate") == "true");
 	list_texts_ << eti;
 
+	if (e.attribute("tagg")=="label") {
+		DiagramContext &dc = this->rElementInformations();
+		dc.addValue("label", e.attribute("text"));
+			this->setElementInformations(dc);
+			this->setTaggedText("label", e.attribute("text"));
+		}
+		else if (e.attribute("tagg")=="function") {
+			DiagramContext &dc = this->rElementInformations();
+			dc.addValue("function", e.attribute("text"));
+			this->setElementInformations(dc);
+		}
+
 	// Se positionne aux coordonnees indiquees dans la description du texte
 	qp.setTransform(QTransform(), false);
 	qp.translate(pos_x, pos_y);
@@ -783,18 +795,6 @@
 	eti -> setFont(QETApp::diagramTextsFont(size));
 	eti -> setTagg(e.attribute("tagg", "other"));
 
-	if (e.attribute("tagg")=="label") {
-		DiagramContext &dc = this->rElementInformations();
-		dc.addValue("label", e.attribute("text"));
-		this->setElementInformations(dc);
-		this->setTaggedText("label", e.attribute("text"));
-	}
-	else if (e.attribute("tagg")=="function") {
-		DiagramContext &dc = this->rElementInformations();
-		dc.addValue("function", e.attribute("text"));
-		this->setElementInformations(dc);
-	}
-
 	// position the text field
 	eti -> setOriginalPos(QPointF(pos_x, pos_y));
 	eti -> setPos(pos_x, pos_y);

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2016-07-25 14:17:54 UTC (rev 4590)
+++ trunk/sources/qetgraphicsitem/element.cpp	2016-07-25 19:18:26 UTC (rev 4591)
@@ -308,6 +308,25 @@
 }
 
 /**
+	This class is used to retrieve label and function information from element
+	and add it to Diagram Context. Used to make older versions work correctly
+	@param Element Text item to check information
+*/
+void Element::etiToElementLabels(ElementTextItem *eti) {
+	if (eti->tagg() == "label" && eti->toPlainText()!= "_") {
+		DiagramContext &dc = this->rElementInformations();
+		dc.addValue("label", eti->toPlainText());
+		this->setElementInformations(dc);
+		this->setTaggedText("label", eti->toPlainText());
+	}
+	else if(eti->tagg() == "function" && eti->toPlainText() != "_") {
+		DiagramContext &dc = this->rElementInformations();
+		dc.addValue("function", eti->toPlainText());
+		this->setElementInformations(dc);
+	}
+}
+
+/**
 	Permet de savoir si un element XML (QDomElement) represente bien un element
 	@param e Le QDomElement a valide
 	@return true si l'element XML est un Element, false sinon
@@ -393,7 +412,10 @@
 	QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
 	foreach(QGraphicsItem *qgi, childItems()) {
 		if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
-			foreach(QDomElement input, inputs) eti -> fromXml(input);
+			foreach(QDomElement input, inputs) {
+				eti -> fromXml(input);
+				etiToElementLabels(eti);
+			}
 		}
 	}
 

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2016-07-25 14:17:54 UTC (rev 4590)
+++ trunk/sources/qetgraphicsitem/element.h	2016-07-25 19:18:26 UTC (rev 4591)
@@ -193,6 +193,7 @@
 		void drawSelection(QPainter *, const QStyleOptionGraphicsItem *);
 		void drawHighlight(QPainter *, const QStyleOptionGraphicsItem *);
 		void updatePixmap();
+		void etiToElementLabels(ElementTextItem*);
 
 	protected:
 		virtual void mouseMoveEvent    ( QGraphicsSceneMouseEvent *event );


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