[qet] qet/qet: [4804] Element : edit an element text item (with tagg) directly on the folio, also update the information of the element.

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


Revision: 4804
Author:   blacksun
Date:     2016-12-08 17:54:41 +0100 (Thu, 08 Dec 2016)
Log Message:
-----------
Element : edit an element text item (with tagg) directly on the folio, also update the information of the element.
For exemple, edit the element text item tagged "label", update the value with key "label" of element information. 

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

Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp	2016-12-08 15:06:46 UTC (rev 4803)
+++ trunk/sources/diagram.cpp	2016-12-08 16:54:41 UTC (rev 4804)
@@ -1011,14 +1011,6 @@
 
 	switch (item->type())
 	{
-		case Element::Type:
-		{
-			Element *elmt = static_cast<Element*>(item);
-			foreach(ElementTextItem *eti, elmt->texts())
-				connect (eti, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
-		}
-			break;
-
 		case Conductor::Type:
 		{
 			Conductor *conductor = static_cast<Conductor *>(item);
@@ -1048,15 +1040,6 @@
 
 	switch (item->type())
 	{
-		case Element::Type:
-		{
-			Element *elmt = static_cast<Element *>(item);
-			elmt->unlinkAllElements();
-			foreach(ElementTextItem *text, elmt->texts())
-				disconnect(text, &ElementTextItem::diagramTextChanged, this, &Diagram::diagramTextChanged);
-		}
-			break;
-
 		case Conductor::Type:
 		{
 			Conductor *conductor = static_cast<Conductor *>(item);

Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp	2016-12-08 15:06:46 UTC (rev 4803)
+++ trunk/sources/qetgraphicsitem/customelement.cpp	2016-12-08 16:54:41 UTC (rev 4804)
@@ -266,59 +266,6 @@
 }
 
 /**
-	Retrieves the element label stored in file ./elements/ * /qet_labels.xml
-	The labels are applied to all elements inside a folder. If an element
-	has a specific label, it will be applied. See qet_labels.xml for more
-	instructions.
-*/
-void CustomElement::parseLabels()
-{
-	QString formula = location().project()->elementAutoNumCurrentFormula();
-	DiagramContext &dc = rElementInformations();
-
-		//element is being added
-	if (taggedText("label") && (location().projectId()!=-1) && (taggedText("label")->toPlainText()=="_"))
-	{
-		if (getPrefix().isEmpty())
-		{
-			if (!formula.isEmpty() && (this->linkType() != Element::Slave))
-			{
-				dc.addValue("label", formula);
-				this->setTaggedText("label",formula);
-			}
-		}
-		else
-		{
-				//if there is a formula to assign, assign it
-			if (!formula.isEmpty() && (this->linkType() != Element::Slave))
-			{
-				dc.addValue("label", formula);
-				this->setTaggedText("label",formula);
-			}
-			else
-			{ //assign only prefix
-				dc.addValue("label", "%prefix");
-				this->setTaggedText("label", getPrefix());
-			}
-		}
-	}
-
-		//apply formula to specific label - This condition specify elements which have different labels e.g KM
-		//that are already specified in the element label (inside .elmt file). This method is not called if elements
-		//are being loaded at first time or being pasted
-	else if ((this->taggedText("label")!= NULL) && (location().projectId()!=-1) &&
-			 (!location().project()->elementAutoNumCurrentFormula().isEmpty()) &&
-			 (this->linkType()!=Element::Slave) && !this->diagram()->item_paste)
-	{
-		QString prefix = this->taggedText("label")->toPlainText();
-		this->setPrefix(prefix);
-		dc.addValue("label", formula);
-		this->setTaggedText("label",formula);
-		this->setElementInformations(dc);
-	}
-}
-
-/**
 	Analyse et prend en compte un element XML decrivant une partie du dessin
 	de l'element perso. Si l'analyse reussit, la partie est ajoutee au dessin.
 	Cette partie peut etre une borne, une ligne, une ellipse, un cercle, un arc
@@ -767,6 +714,8 @@
 
 	list_texts_ << eti;
 
+	connect(eti, &ElementTextItem::diagramTextChanged, this, &Element::textItemChanged);
+
 	return(eti);
 }
 

Modified: trunk/sources/qetgraphicsitem/customelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.h	2016-12-08 15:06:46 UTC (rev 4803)
+++ trunk/sources/qetgraphicsitem/customelement.h	2016-12-08 16:54:41 UTC (rev 4804)
@@ -72,7 +72,6 @@
 	virtual QList<QVector<qreal> *> arcs() const;
 	virtual int terminalsCount() const;
 	virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
-	virtual void parseLabels();
 	QString typeId() const;
 	ElementsLocation location() const;
 	QString name() const;

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2016-12-08 15:06:46 UTC (rev 4803)
+++ trunk/sources/qetgraphicsitem/element.cpp	2016-12-08 16:54:41 UTC (rev 4804)
@@ -28,6 +28,7 @@
 #include "elementpropertieswidget.h"
 #include "numerotationcontextcommands.h"
 #include "diagramcontext.h"
+#include "changeelementinformationcommand.h"
 
 class ElementXmlRetroCompatibility
 {
@@ -436,12 +437,15 @@
 			table_id_adr.insert(id_trouve, priv_id_adr.value(id_trouve));
 		}
 	}
-	
-	// importe les valeurs des champs de texte
+
+		//import text filed value
 	QList<QDomElement> inputs = QET::findInDomElement(e, "inputs", "input");
-	foreach(QGraphicsItem *qgi, childItems()) {
-		if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi)) {
-			foreach(QDomElement input, inputs) {
+	foreach(QGraphicsItem *qgi, childItems())
+	{
+		if (ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(qgi))
+		{
+			foreach(QDomElement input, inputs)
+			{
 				eti -> fromXml(input);
 				etiToElementLabels(eti);
 			}
@@ -779,6 +783,40 @@
 }
 
 /**
+ * @brief Element::textItemChanged
+ * Use to keep up to date the element information when text item changed.
+ * @param dti
+ * @param old_str
+ * @param new_str
+ */
+void Element::textItemChanged(DiagramTextItem *dti, QString old_str, QString new_str)
+{
+	Q_UNUSED(new_str)
+
+	if (!diagram())
+		return;
+
+	ElementTextItem *eti = qgraphicsitem_cast<ElementTextItem *>(dti);
+	if (!eti)
+		return;
+
+	QString tagg = eti->tagg();
+	if (m_element_informations.contains(tagg))
+	{
+		DiagramContext dc = m_element_informations;
+		dc.addValue(tagg, eti->toPlainText(), dc.keyMustShow(tagg));
+		if (tagg == "label")
+			dc.addValue("formula", eti->toPlainText(), dc.keyMustShow("formula"));
+
+		diagram()->undoStack().push(new ChangeElementInformationCommand(this, m_element_informations, dc));
+	}
+	else
+	{
+		diagram()->undoStack().push(new ChangeDiagramTextCommand(eti, old_str, eti->toPlainText()));
+	}
+}
+
+/**
  * @brief Element::getPrefix
  * get Element Prefix
  */

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2016-12-08 15:06:46 UTC (rev 4803)
+++ trunk/sources/qetgraphicsitem/element.h	2016-12-08 16:54:41 UTC (rev 4804)
@@ -28,6 +28,7 @@
 class Terminal;
 class Conductor;
 class NumerotationContext;
+class DiagramTextItem;
 
 /**
 	This is the base class for electrical elements.
@@ -46,8 +47,7 @@
 		// attributes
 	public:
 			/**
-			 * Enable the use of qgraphicsitem_cast to safely cast
-			 * a QGraphicsItem into an Element.
+			 * Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into an Element.
 			 * @return the QGraphicsItem type
 			 */
 		enum { Type = UserType + 1000 };
@@ -72,30 +72,30 @@
 
 		// methods
 	public:
-		/// @return the list of terminals for this element
-	virtual QList<Terminal *> terminals() const = 0;
-		/// @return the list of conductors attached to this element
-	virtual QList<Conductor *> conductors() const = 0;
-		/// @return the list of text items attached to this element
-	virtual QList<ElementTextItem *> texts() const = 0;
-		/// @return the text field tagged with @tagg or NULL if text field isn't found
-	virtual ElementTextItem* taggedText(const QString &tagg) const = 0;
-		/// @return the list of lines items in this element
-	virtual QList<QLineF *> lines() const = 0;
-		/// @return the list of rectangles items in this element
-	virtual QList<QRectF *> rectangles() const = 0;
-		/// @return the list of bounding rectangles for circles items in this element
-	virtual QList<QRectF *> circles() const = 0;
-		/// @return the list of polygons in this element
-	virtual QList<QVector<QPointF> *> polygons() const = 0;	
-		/// @return the list of arcs in this element
-	virtual QList<QVector<qreal> *> arcs() const = 0;
-		/// @return the current number of terminals of this element
-	virtual int terminalsCount() const = 0;
-		/// @return the minimum number of terminals for this element
-	virtual int minTerminalsCount() const = 0;
-		/// @return the maximum number of terminals for this element
-	virtual int maxTerminalsCount() const = 0;
+			/// @return the list of terminals for this element
+		virtual QList<Terminal *> terminals() const = 0;
+			/// @return the list of conductors attached to this element
+		virtual QList<Conductor *> conductors() const = 0;
+			/// @return the list of text items attached to this element
+		virtual QList<ElementTextItem *> texts() const = 0;
+			/// @return the text field tagged with @tagg or NULL if text field isn't found
+		virtual ElementTextItem* taggedText(const QString &tagg) const = 0;
+			/// @return the list of lines items in this element
+		virtual QList<QLineF *> lines() const = 0;
+			/// @return the list of rectangles items in this element
+		virtual QList<QRectF *> rectangles() const = 0;
+			/// @return the list of bounding rectangles for circles items in this element
+		virtual QList<QRectF *> circles() const = 0;
+			/// @return the list of polygons in this element
+		virtual QList<QVector<QPointF> *> polygons() const = 0;
+			/// @return the list of arcs in this element
+		virtual QList<QVector<qreal> *> arcs() const = 0;
+			/// @return the current number of terminals of this element
+		virtual int terminalsCount() const = 0;
+			/// @return the minimum number of terminals for this element
+		virtual int minTerminalsCount() const = 0;
+			/// @return the maximum number of terminals for this element
+		virtual int maxTerminalsCount() const = 0;
 
 		QList <QPair <Terminal *, Terminal *> > AlignedFreeTerminals () const;
 
@@ -130,6 +130,7 @@
 
 		//METHODS related to information
 	public:
+		void textItemChanged(DiagramTextItem *dti, QString old_str, QString new_str);
 		DiagramContext  elementInformations    ()const              {return m_element_informations;}
 		DiagramContext& rElementInformations   ()                   {return m_element_informations;}
 		virtual void    setElementInformations (DiagramContext dc);


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