[qet] [4681] Element Terminale add label

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


Revision: 4681
Author:   scorpio810
Date:     2016-09-02 07:28:26 +0200 (Fri, 02 Sep 2016)
Log Message:
-----------
Element Terminale add label
Nomenclature Add terminal element

Modified Paths:
--------------
    trunk/sources/editor/graphicspart/partterminal.cpp
    trunk/sources/editor/graphicspart/partterminal.h
    trunk/sources/nomenclature.cpp
    trunk/sources/qetgraphicsitem/terminalelement.cpp
    trunk/sources/qetgraphicsitem/terminalelement.h
    trunk/sources/ui/elementpropertieswidget.cpp

Modified: trunk/sources/editor/graphicspart/partterminal.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partterminal.cpp	2016-09-01 19:41:49 UTC (rev 4680)
+++ trunk/sources/editor/graphicspart/partterminal.cpp	2016-09-02 05:28:26 UTC (rev 4681)
@@ -26,6 +26,7 @@
 */
 PartTerminal::PartTerminal(QETElementEditor *editor, QGraphicsItem *parent) :
 	CustomElementGraphicPart(editor, parent),
+	m_tagg("none"),
 	m_orientation(Qet::North)
 {
 	updateSecondPoint();
@@ -64,6 +65,7 @@
 	// ecrit la position de la borne
 	xml_element.setAttribute("x", QString("%1").arg(scenePos().x()));
 	xml_element.setAttribute("y", QString("%1").arg(scenePos().y()));
+	xml_element.setAttribute("tagg", m_tagg);
 	
 	// ecrit l'orientation de la borne
 	xml_element.setAttribute("orientation", Qet::orientationToString(m_orientation));

Modified: trunk/sources/editor/graphicspart/partterminal.h
===================================================================
--- trunk/sources/editor/graphicspart/partterminal.h	2016-09-01 19:41:49 UTC (rev 4680)
+++ trunk/sources/editor/graphicspart/partterminal.h	2016-09-02 05:28:26 UTC (rev 4681)
@@ -19,6 +19,9 @@
 #define PART_TERMINAL_H
 
 #include "customelementgraphicpart.h"
+#include "customelementpart.h"
+class TextFieldEditor;
+class QETElementEditor;
 
 /**
 	This class represents a terminal which may be used to compose the drawing of
@@ -30,6 +33,11 @@
 
 		Q_PROPERTY(Qet::Orientation orientation READ orientation WRITE setOrientation)
 
+	// tagg of text
+	Q_PROPERTY(QString tagg READ tagg WRITE setTagg)
+		QString tagg() const {return m_tagg;}
+		void setTagg(const QString &tagg) {m_tagg = tagg;}
+		
 	public:
 		// constructors, destructor
 		PartTerminal(QETElementEditor *editor, QGraphicsItem *parent = 0);
@@ -44,6 +52,7 @@
 	private:
 		Qet::Orientation m_orientation;
 		QPointF second_point;
+		QString m_tagg;
 	
 		// methods
 	public:

Modified: trunk/sources/nomenclature.cpp
===================================================================
--- trunk/sources/nomenclature.cpp	2016-09-01 19:41:49 UTC (rev 4680)
+++ trunk/sources/nomenclature.cpp	2016-09-02 05:28:26 UTC (rev 4681)
@@ -105,7 +105,7 @@
 		//Get only simple, master and unlinked slave element.
 		ElementProvider ep(d);
 		QList <Element *> list_elements;
-		list_elements << ep.find(Element::Simple | Element::Master);
+		list_elements << ep.find(Element::Simple | Element::Master | Element::Terminale);
 		list_elements << ep.freeElement(Element::Slave);
 
 		foreach (Element *elmt, list_elements) {

Modified: trunk/sources/qetgraphicsitem/terminalelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminalelement.cpp	2016-09-01 19:41:49 UTC (rev 4680)
+++ trunk/sources/qetgraphicsitem/terminalelement.cpp	2016-09-02 05:28:26 UTC (rev 4681)
@@ -16,6 +16,8 @@
 	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
 */
 #include "terminalelement.h"
+#include "commentitem.h"
+#include "elementtextitem.h"
 
 /**
  * @brief TerminalElement::TerminalElement
@@ -26,9 +28,76 @@
  * @param state int used to know if the creation of element have error
  */
 TerminalElement::TerminalElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
-	CustomElement(location, qgi, state)
+	CustomElement(location, qgi, state),
+	m_comment_item (nullptr),
+	m_location_item (nullptr)
 {
 	link_type_ = Terminale;
+	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()));
+	connect(this, SIGNAL(updateLabel()),this,SLOT(changeElementInfo()));
 }
 
-TerminalElement::~TerminalElement() {}
+TerminalElement::~TerminalElement() {
+if (m_comment_item) delete m_comment_item;
+}
+
+/**
+ * @brief TerminalElement::initLink
+ * @param project
+ */
+void TerminalElement::initLink(QETProject *project) {
+	CustomElement::initLink(project);
+	updateLabel(DiagramContext(), elementInformations());
+}
+
+/**
+ * @brief SimpleElement::changeElementInfo()
+ * Update label if it contains %c, %l, %f or %F variables
+ */
+void TerminalElement::changeElementInfo(){
+	QString temp_label = this->elementInformations()["label"].toString();
+	if (temp_label.contains("\%")) {
+		if (this->diagram()!=NULL)
+			this->updateLabel(this->elementInformations(),this->elementInformations());
+	}
+}
+
+/**
+ * @brief SimpleElement::updateLabel
+ * update label of this element
+ */
+void TerminalElement::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() != label) {
+		if (new_info["label"].toString().isEmpty())
+			setTaggedText("label", "_", false);
+		else {
+			setTaggedText("label", label, true);
+		}
+	}
+
+	if (ElementTextItem *eti = taggedText("label")) {
+		new_info["label"].toString().isEmpty() ? eti->setVisible(true) : eti -> setVisible(new_info.keyMustShow("label"));
+	}
+
+	//Comment and Location of element
+	QString comment   = new_info["comment"].toString();
+	bool    must_show = new_info.keyMustShow("comment");
+	QString location  = new_info["location"].toString();
+	bool must_show_location = new_info.keyMustShow("location");
+
+	if ((!(comment.isEmpty() || !must_show) && !m_comment_item)||(!(location.isEmpty() || !must_show_location) && !m_comment_item)) {
+		m_comment_item = new CommentItem(this);
+	}
+	else if (((comment.isEmpty() || !must_show) && m_comment_item) && ((location.isEmpty() || !must_show_location) && m_comment_item)) {
+		delete m_comment_item;
+		m_comment_item = nullptr;
+	}
+}
+

Modified: trunk/sources/qetgraphicsitem/terminalelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/terminalelement.h	2016-09-01 19:41:49 UTC (rev 4680)
+++ trunk/sources/qetgraphicsitem/terminalelement.h	2016-09-02 05:28:26 UTC (rev 4681)
@@ -20,12 +20,26 @@
 
 #include "customelement.h"
 
+class CommentItem;
+class QETProject;
+
 class TerminalElement : public CustomElement
 {
 		Q_OBJECT
 	public:
 		TerminalElement(const ElementsLocation &, QGraphicsItem * = 0, int * = 0);
 		~TerminalElement();
+		virtual void initLink(QETProject *project);
+		
+		signals:
+
+	public slots:
+		void updateLabel(DiagramContext old_info, DiagramContext new_info);
+		void changeElementInfo();
+
+	private:
+		CommentItem *m_comment_item;
+		CommentItem *m_location_item;
 };
 
 #endif // TERMINALELEMENT_H

Modified: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp	2016-09-01 19:41:49 UTC (rev 4680)
+++ trunk/sources/ui/elementpropertieswidget.cpp	2016-09-02 05:28:26 UTC (rev 4681)
@@ -198,6 +198,7 @@
 			m_list_editor << new LinkSingleElementWidget(m_element, this);
 			break;
 		case Element::Terminale:
+			m_list_editor << new ElementInfoWidget(m_element, this);
 			break;
 		default:
 			break;


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