[qet] [2946] slave element: when linked to master, label is replaced by the label of master, and show the position of the master

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


Revision: 2946
Author:   blacksun
Date:     2014-03-21 15:40:33 +0100 (Fri, 21 Mar 2014)
Log Message:
-----------
slave element: when linked to master, label is replaced by the label of master, and show the position of the master

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

Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp	2014-03-21 10:39:05 UTC (rev 2945)
+++ trunk/sources/qetgraphicsitem/customelement.cpp	2014-03-21 14:40:33 UTC (rev 2946)
@@ -711,18 +711,19 @@
 	
 	ElementTextItem *eti = new ElementTextItem(e.attribute("text"), this);
 	eti -> setFont(QETApp::diagramTextsFont(size));
+	eti -> setTagg(e.attribute("tagg", "other"));
 	
-	// position du champ de texte
+	// position the text field
 	eti -> setOriginalPos(QPointF(pos_x, pos_y));
 	eti -> setPos(pos_x, pos_y);
 	
-	// rotation du champ de texte
+	// rotation of the text field
 	qreal original_rotation_angle = 0.0;
 	QET::attributeIsAReal(e, "rotation", &original_rotation_angle);
 	eti -> setOriginalRotationAngle(original_rotation_angle);
 	eti -> setRotationAngle(original_rotation_angle);
 	
-	// comportement du champ lorsque son element parent est pivote
+	// behavior when the parent element is rotated
 	eti -> setFollowParentRotations(e.attribute("rotate") == "true");
 	
 	list_texts_ << eti;
@@ -900,3 +901,22 @@
 	// mise en place (ou non) de l'antialiasing
 	setQPainterAntiAliasing(qp, e.attribute("antialias") == "true");
 }
+
+/**
+ * @brief CustomElement::setTaggedText
+ * Set text @newstr to the text tagged with @tagg.
+ * If tagg is found return the text item, else return 0.
+ * @param tagg required tagg
+ * @param newstr new label
+ * @param noeditable set editable or not (by default, set editable)
+ */
+ElementTextItem* CustomElement::setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable) {
+	foreach (ElementTextItem *eti, list_texts_) {
+		if (eti -> tagg() == tagg) {
+			eti -> setPlainText(newstr);
+			eti -> setNoEditable(noeditable);
+			return eti;
+		}
+	}
+	return 0;
+}

Modified: trunk/sources/qetgraphicsitem/customelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.h	2014-03-21 10:39:05 UTC (rev 2945)
+++ trunk/sources/qetgraphicsitem/customelement.h	2014-03-21 14:40:33 UTC (rev 2946)
@@ -90,6 +90,7 @@
 	virtual void setQPainterAntiAliasing(QPainter &, bool);
 	virtual bool validOrientationAttribute(const QDomElement &);
 	virtual void setPainterStyle(QDomElement &, QPainter &);
+	ElementTextItem* setTaggedText(const QString &tagg, const QString &newstr, const bool noeditable=false);
 };
 
 /**

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2014-03-21 10:39:05 UTC (rev 2945)
+++ trunk/sources/qetgraphicsitem/element.cpp	2014-03-21 14:40:33 UTC (rev 2946)
@@ -504,6 +504,17 @@
 }
 
 /**
+ * @brief Element::setElementInformations
+ * Set new information for this element.
+ * This method emit @elementInfoChange
+ * @param dc
+ */
+void Element::setElementInformations(DiagramContext dc) {
+	element_informations_ = dc;
+	emit elementInfoChange(element_informations_);
+}
+
+/**
  * @brief comparPos
  * Compare position of the two elements. Compare 3 points:
  * 1 folio - 2 row - 3 line

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2014-03-21 10:39:05 UTC (rev 2945)
+++ trunk/sources/qetgraphicsitem/element.h	2014-03-21 14:40:33 UTC (rev 2946)
@@ -115,10 +115,13 @@
 	QUuid uuid_;
 	kind link_type_;
 
+		signals:
+	void elementInfoChange(DiagramContext);
+
 		//METHODS related to information
 		public:
 	DiagramContext elementInformations()const {return element_informations_;}
-	void setElementInformations(DiagramContext dc) {element_informations_ = dc;}
+	void setElementInformations(DiagramContext dc);//{element_informations_ = dc; emit elementInfoChange(dc);}
 	DiagramContext kindInformations() const {return kind_informations_;}	//@kind_information_ is used to store more information
 																			//about the herited class like contactelement for know
 																			// kind of contact (simple tempo) or number of contact show by the element.

Modified: trunk/sources/qetgraphicsitem/elementtextitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/elementtextitem.h	2014-03-21 10:39:05 UTC (rev 2945)
+++ trunk/sources/qetgraphicsitem/elementtextitem.h	2014-03-21 14:40:33 UTC (rev 2946)
@@ -44,6 +44,7 @@
 	QPointF original_position;
 	qreal original_rotation_angle_;
 	bool first_move_;
+	QString tagg_;
 	
 	// methods
 	public:
@@ -63,6 +64,8 @@
 	void setOriginalRotationAngle(const qreal &);
 	qreal originalRotationAngle() const;
 	virtual void setFont(const QFont &);
+	void setTagg(const QString &str) {tagg_ = str;}
+	QString tagg() const {return tagg_;}
 	
 	public slots:
 	void adjustItemPosition(int = 0);

Modified: trunk/sources/qetgraphicsitem/slaveelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/slaveelement.cpp	2014-03-21 10:39:05 UTC (rev 2945)
+++ trunk/sources/qetgraphicsitem/slaveelement.cpp	2014-03-21 14:40:33 UTC (rev 2946)
@@ -16,6 +16,9 @@
 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "slaveelement.h"
+#include "diagramposition.h"
+#include "qetapp.h"
+#include "elementtextitem.h"
 
 /**
  * @brief SlaveElement::SlaveElement
@@ -28,6 +31,7 @@
 SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
 	CustomElement(location, qgi, s, state)
 {
+	Xref_item = NULL;
 	link_type_ = Slave;
 }
 
@@ -50,6 +54,9 @@
 	if (elmt->linkType() == Master && !connected_elements.contains(elmt)) {
 		if(!isFree()) unlinkAllElements();
 		connected_elements << elmt;
+		updateLabel();
+		connect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel()));
+		connect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
 		elmt->linkToElement(this);
 	}
 }
@@ -76,6 +83,47 @@
 	//Ensure elmt is linked to this element
 	if (connected_elements.contains(elmt)) {
 		connected_elements.removeOne(elmt);
+		disconnect(elmt, SIGNAL(positionChange(QPointF)), this, SLOT(updateLabel()));
+		disconnect(elmt, SIGNAL(elementInfoChange(DiagramContext)), this, SLOT(updateLabel()));
+		delete Xref_item; Xref_item = NULL;
+		updateLabel();
 		elmt->unlinkElement(this);
 	}
 }
+
+/**
+ * @brief SlaveElement::updateLabel
+ * update the label (tagged with label) of this element.
+ * If this element is connected to a master,
+ * the label show the string tagged by "label" of the master
+ * and add a qgraphicstextitem for show the position of the master
+ */
+void SlaveElement::updateLabel() {
+	QString label("_");
+	QString Xreflabel;
+	bool no_editable = false;
+
+	//must be linked to set the label of master
+	if (linkedElements().count()) {
+		no_editable = true;
+		Element *elmt = linkedElements().first();
+		label = elmt -> elementInformations()["label"].toString();
+
+		Xreflabel = "(";
+		Xreflabel += QString::number(elmt->diagram()->folioIndex()+1);
+		Xreflabel += "-";
+		Xreflabel += elmt->diagram() -> convertPosition(elmt -> scenePos()).toString();
+		Xreflabel += ")";
+	}
+
+	// set the new label
+	ElementTextItem *eti = setTaggedText("label", label, no_editable);
+	if (eti && !isFree()) {
+		if (Xref_item) Xref_item -> setPlainText(Xreflabel);
+		else {
+			Xref_item = new QGraphicsTextItem(Xreflabel, eti);
+			Xref_item -> setFont(QETApp::diagramTextsFont(5));
+			Xref_item -> setPos(eti ->  boundingRect().bottomLeft());
+		}
+	}
+}

Modified: trunk/sources/qetgraphicsitem/slaveelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/slaveelement.h	2014-03-21 10:39:05 UTC (rev 2945)
+++ trunk/sources/qetgraphicsitem/slaveelement.h	2014-03-21 14:40:33 UTC (rev 2946)
@@ -32,8 +32,12 @@
 
 	signals:
 
-	public slots:
+	private slots:
+	void updateLabel();
 
+	private:
+	QGraphicsTextItem *Xref_item;
+
 };
 
 #endif // SLAVEELEMENT_H


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