[qet] [4071] terminal editor : use QPropertyUndoCommand instead of ChangePartCommand

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


Revision: 4071
Author:   blacksun
Date:     2015-07-24 14:08:03 +0200 (Fri, 24 Jul 2015)
Log Message:
-----------
terminal editor : use QPropertyUndoCommand instead of ChangePartCommand

Modified Paths:
--------------
    trunk/sources/editor/graphicspart/partterminal.cpp
    trunk/sources/editor/graphicspart/partterminal.h
    trunk/sources/editor/terminaleditor.cpp
    trunk/sources/editor/terminaleditor.h

Modified: trunk/sources/editor/graphicspart/partterminal.cpp
===================================================================
--- trunk/sources/editor/graphicspart/partterminal.cpp	2015-07-24 11:34:45 UTC (rev 4070)
+++ trunk/sources/editor/graphicspart/partterminal.cpp	2015-07-24 12:08:03 UTC (rev 4071)
@@ -140,10 +140,13 @@
 	Definit l'orientation de la borne
 	@param ori la nouvelle orientation de la borne
 */
-void PartTerminal::setOrientation(Qet::Orientation ori) {
+void PartTerminal::setOrientation(Qet::Orientation ori)
+{
+	if (m_orientation == ori) return;
 	prepareGeometryChange();
 	m_orientation = ori;
 	updateSecondPoint();
+	emit orientationChanged();
 }
 
 /**

Modified: trunk/sources/editor/graphicspart/partterminal.h
===================================================================
--- trunk/sources/editor/graphicspart/partterminal.h	2015-07-24 11:34:45 UTC (rev 4070)
+++ trunk/sources/editor/graphicspart/partterminal.h	2015-07-24 12:08:03 UTC (rev 4071)
@@ -36,6 +36,9 @@
 		virtual ~PartTerminal();
 	private:
 		PartTerminal(const PartTerminal &);
+
+	signals:
+		void orientationChanged();
 	
 		// attributes
 	private:

Modified: trunk/sources/editor/terminaleditor.cpp
===================================================================
--- trunk/sources/editor/terminaleditor.cpp	2015-07-24 11:34:45 UTC (rev 4070)
+++ trunk/sources/editor/terminaleditor.cpp	2015-07-24 12:08:03 UTC (rev 4071)
@@ -18,6 +18,7 @@
 #include "terminaleditor.h"
 #include "partterminal.h"
 #include "qeticons.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
 
 /**
 	Constructeur
@@ -27,7 +28,8 @@
 */
 TerminalEditor::TerminalEditor(QETElementEditor *editor, PartTerminal *term, QWidget *parent) :
 	ElementItemEditor(editor, parent),
-	part(term)
+	part(term),
+	m_locked(false)
 {
 	qle_x = new QDoubleSpinBox();
 	qle_y = new QDoubleSpinBox();
@@ -75,18 +77,26 @@
 	@param new_part Nouvelle primitive a editer
 	@return true si l'editeur a accepter d'editer la primitive, false sinon
 */
-bool TerminalEditor::setPart(CustomElementPart *new_part) {
-	if (!new_part) {
+bool TerminalEditor::setPart(CustomElementPart *new_part)
+{
+	if (!new_part)
+	{
+		if (part)
+			disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
 		part = 0;
 		return(true);
 	}
-	if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part)) {
+	if (PartTerminal *part_terminal = dynamic_cast<PartTerminal *>(new_part))
+	{
+		if(part == part_terminal) return true;
+		if (part)
+			disconnect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
 		part = part_terminal;
 		updateForm();
+		connect(part, &PartTerminal::orientationChanged, this, &TerminalEditor::updateForm);
 		return(true);
-	} else {
-		return(false);
 	}
+	return(false);
 }
 
 /**
@@ -96,28 +106,35 @@
 	return(part);
 }
 
-/**
-	Met a jour la borne a partir des donnees du formulaire
-*/
-void TerminalEditor::updateTerminal() {
-	if (!part) return;
-	part -> setPos(qle_x -> value(), qle_y -> value());
-	part -> setOrientation(
-		static_cast<Qet::Orientation>(
-			orientation -> itemData(
-				orientation -> currentIndex()
-			).toInt()
-		)
-	);
+/// Met a jour l'orientation de la borne et cree un objet d'annulation
+void TerminalEditor::updateTerminalO()
+{
+	if (m_locked) return;
+	m_locked = true;
+	QVariant var(orientation -> itemData(orientation -> currentIndex()));
+	if (var != part->property("orientation"))
+	{
+		QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "orientation", part->property("orientation"), var);
+		undo->setText(tr("Modifier l'orientation d'une borne"));
+		undoStack().push(undo);
+	}
+	m_locked = false;
 }
 
-/// WARNING!!!! on addChangePartCommand the prop accept only the simple string! (NOT /:;,?...)
-/// Met a jour l'abscisse de la position de la borne et cree un objet d'annulation
-void TerminalEditor::updateTerminalX() { addChangePartCommand(tr("abscisse"),    part, "x",           qle_x -> value()); }
-/// Met a jour l'ordonnee de la position de la borne et cree un objet d'annulation
-void TerminalEditor::updateTerminalY() { addChangePartCommand(tr("ordonnée"), part, "y",           qle_y -> value()); }
-/// Met a jour l'orientation de la borne et cree un objet d'annulation
-void TerminalEditor::updateTerminalO() { addChangePartCommand(tr("orientation"), part, "orientation", orientation -> itemData(orientation -> currentIndex())); }
+void TerminalEditor::updatePos()
+{
+	if (m_locked) return;
+	m_locked = true;
+	QPointF new_pos(qle_x->value(), qle_y->value());
+	if (new_pos != part->pos())
+	{
+		QPropertyUndoCommand *undo = new QPropertyUndoCommand(part, "pos", part->property("pos"), new_pos);
+		undo->setText(tr("Déplacer une borne"));
+		undo->enableAnimation();
+		undoStack().push(undo);
+	}
+	m_locked=false;
+}
 /// update Number and name, create cancel object
 
 /**
@@ -136,14 +153,18 @@
 	Active ou desactive les connexionx signaux/slots entre les widgets internes.
 	@param active true pour activer les connexions, false pour les desactiver
 */
-void TerminalEditor::activeConnections(bool active) {
-	if (active) {
-		connect(qle_x,       SIGNAL(editingFinished()), this, SLOT(updateTerminalX()));
-		connect(qle_y,       SIGNAL(editingFinished()), this, SLOT(updateTerminalY()));
+void TerminalEditor::activeConnections(bool active)
+{
+	if (active)
+	{
+		connect(qle_x,       SIGNAL(editingFinished()), this, SLOT(updatePos()));
+		connect(qle_y,       SIGNAL(editingFinished()), this, SLOT(updatePos()));
 		connect(orientation, SIGNAL(activated(int)),    this, SLOT(updateTerminalO()));
-	} else {
-		disconnect(qle_x,       SIGNAL(editingFinished()), this, SLOT(updateTerminalX()));
-		disconnect(qle_y,       SIGNAL(editingFinished()), this, SLOT(updateTerminalY()));
+	}
+	else
+	{
+		disconnect(qle_x,       SIGNAL(editingFinished()), this, SLOT(updatePos()));
+		disconnect(qle_y,       SIGNAL(editingFinished()), this, SLOT(updatePos()));
 		disconnect(orientation, SIGNAL(activated(int)),    this, SLOT(updateTerminalO()));
 	}
 }

Modified: trunk/sources/editor/terminaleditor.h
===================================================================
--- trunk/sources/editor/terminaleditor.h	2015-07-24 11:34:45 UTC (rev 4070)
+++ trunk/sources/editor/terminaleditor.h	2015-07-24 12:08:03 UTC (rev 4071)
@@ -17,9 +17,13 @@
 */
 #ifndef TERMINAL_EDITOR_H
 #define TERMINAL_EDITOR_H
-#include <QtWidgets>
+
 #include "elementitemeditor.h"
+
 class PartTerminal;
+class QDoubleSpinBox;
+class QComboBox;
+
 /**
 	This class provides a widget to edit terminals within the element editor.
 */
@@ -34,9 +38,10 @@
 	
 	// attributes
 	private:
-	PartTerminal *part;
-	QDoubleSpinBox *qle_x, *qle_y;
-	QComboBox *orientation;
+		PartTerminal *part;
+		QDoubleSpinBox *qle_x, *qle_y;
+		QComboBox *orientation;
+		bool m_locked;
 	
 	// methods
 	public:
@@ -44,11 +49,9 @@
 	virtual CustomElementPart *currentPart() const;
 	
 	public slots:
-	void updateTerminal();
-	void updateTerminalX();
-	void updateTerminalY();
-	void updateTerminalO();
-	void updateForm();
+		void updateTerminalO();
+		void updatePos();
+		void updateForm();
 	
 	private:
 	void activeConnections(bool);


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