[qet] [4073] style editor : use QPropertyUndoCommand instead of ChangePartCommand.

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


Revision: 4073
Author:   blacksun
Date:     2015-07-24 15:41:51 +0200 (Fri, 24 Jul 2015)
Log Message:
-----------
style editor :  use QPropertyUndoCommand instead of ChangePartCommand.
Remove ChangePartCommand class.

Modified Paths:
--------------
    trunk/sources/editor/editorcommands.cpp
    trunk/sources/editor/editorcommands.h
    trunk/sources/editor/elementitemeditor.cpp
    trunk/sources/editor/elementitemeditor.h
    trunk/sources/editor/styleeditor.cpp
    trunk/sources/editor/styleeditor.h

Modified: trunk/sources/editor/editorcommands.cpp
===================================================================
--- trunk/sources/editor/editorcommands.cpp	2015-07-24 12:56:27 UTC (rev 4072)
+++ trunk/sources/editor/editorcommands.cpp	2015-07-24 13:41:51 UTC (rev 4073)
@@ -304,64 +304,6 @@
 
 /**
 	Constructeur
-	@param name   nom de la propriete modifiee
-	@param part   partie modifiee
-	@param prop   propriete modifiee
-	@param old_v  ancienne valeur
-	@param new_v  nouvelle valeur
-	@param parent qUndoCommand parent
-*/
-ChangePartCommand::ChangePartCommand(
-	const QString &name,
-	CustomElementPart *part,
-	const char *prop,
-	const QVariant &old_v,
-	const QVariant &new_v,
-	QUndoCommand *parent
-) :
-	ElementEditionCommand(QString(QObject::tr("modification %1", "undo caption")).arg(name), 0, 0, parent),
-	cep(part),
-	property(prop),
-	m_old_value(old_v),
-	m_new_value(new_v)
-{
-}
-
-ChangePartCommand::ChangePartCommand(const QString &part_name, CustomElementPart *part, const char *property_name, const QVariant &old_value, QUndoCommand *parent) :
-	ElementEditionCommand(QString(QObject::tr("modification %1", "undo caption")).arg(part_name), 0, 0, parent),
-	cep(part),
-	property(property_name),
-	m_old_value(old_value)
-{}
-
-/// Destructeur
-ChangePartCommand::~ChangePartCommand() {
-}
-
-void ChangePartCommand::setNewValue(const QVariant &new_value) {
-	m_new_value = new_value;
-}
-
-/**
- * @brief ChangePartCommand::undo
- */
-void ChangePartCommand::undo()
-{
-	cep -> setProperty(property, m_old_value);
-	ElementEditionCommand::undo();
-}
-
-/**
- * @brief ChangePartCommand::redo
- */
-void ChangePartCommand::redo()
-{
-	cep -> setProperty(property, m_new_value);
-	ElementEditionCommand::redo();
-}
-
-/**
-	Constructeur
 	@param element_scene Element edite
 	@param before Listes des noms avant changement
 	@param after Listes des noms apres changement

Modified: trunk/sources/editor/editorcommands.h
===================================================================
--- trunk/sources/editor/editorcommands.h	2015-07-24 12:56:27 UTC (rev 4072)
+++ trunk/sources/editor/editorcommands.h	2015-07-24 13:41:51 UTC (rev 4073)
@@ -170,36 +170,6 @@
 };
 
 /**
-	This command changes a property of a primitive when editing an electrical
-	element.
-*/
-class ChangePartCommand : public ElementEditionCommand
-{
-		// constructors, destructor
-	public:
-		ChangePartCommand(const QString &, CustomElementPart *, const char *, const QVariant &, const QVariant &, QUndoCommand * = 0);
-		ChangePartCommand(const QString &part_name, CustomElementPart *part, const char *property_name, const QVariant &old_value, QUndoCommand *parent = 0);
-		virtual ~ChangePartCommand();
-
-		void setNewValue(const QVariant &new_value);
-
-	private:
-		ChangePartCommand(const ChangePartCommand &);
-	
-		// methods
-	public:
-		virtual void undo();
-		virtual void redo();
-	
-		// attributes
-	private:
-		CustomElementPart *cep;
-		const char *property;
-		QVariant m_old_value;
-		QVariant m_new_value;
-};
-
-/**
 	This command changes the translated names of an electrical element.
 */
 class ChangeNamesCommand : public ElementEditionCommand {

Modified: trunk/sources/editor/elementitemeditor.cpp
===================================================================
--- trunk/sources/editor/elementitemeditor.cpp	2015-07-24 12:56:27 UTC (rev 4072)
+++ trunk/sources/editor/elementitemeditor.cpp	2015-07-24 13:41:51 UTC (rev 4073)
@@ -45,68 +45,6 @@
 	return(elementScene() -> undoStack());
 }
 
-/**
-	Ajoute une ChangePartCommand a l'UndoStack. L'ancienne valeur sera
-	automatiquement recuperee. A noter que cette methode ne fait rien si
-	l'ancienne valeur et la nouvelle sont egales ou encore si part vaut 0
-	@param desc   nom de la propriete modifiee
-	@param part   partie modifiee
-	@param prop   propriete modifiee
-	@param new_v  nouvelle valeur
-*/
-void ElementItemEditor::addChangePartCommand(const QString &desc, CustomElementPart *part, const char *prop, const QVariant &new_v) {
-	// ne fait rien si part vaut 0
-	if (!part) return;
-	
-	// recupere l'ancienne valeur
-	QVariant old_v = part -> property(prop);
-	
-	// ne fait rien si l'ancienne valeur et la nouvelle sont egales 
-	if (old_v == new_v) return;
-	
-	undoStack().push(
-		new ChangePartCommand(
-			desc + " " + element_type_name,
-			part,
-			prop,
-			old_v,
-			new_v
-		)
-	);
-}
-
-/**
- * @brief ElementItemEditor::addChangePartCommand
- * Add a ChangePartCommand with child for each part of part_list to the undo stack
- * @param undo_text : text of undo command to display
- * @param part_list : list of parts to modify
- * @param property : QProperty (of CustomElementPart) to modify
- * @param new_value : the new value of the QProperty
- */
-void ElementItemEditor::addChangePartCommand(const QString &undo_text, QList<CustomElementPart *> part_list, const char *property, const QVariant &new_value)
-{
-	if (part_list.isEmpty()) return;
-
-		//Get only the parts concerned  by modification
-	QList <CustomElementPart *> updated_part;
-	foreach (CustomElementPart *cep, part_list)
-		if (cep->property(property) != new_value)
-			updated_part << cep;
-
-		//There is not part to modify
-	if(updated_part.isEmpty()) return;
-
-		//Set the first part has parent undo
-	CustomElementPart *p_cep = updated_part.takeFirst();
-	QUndoCommand *parent_undo = new ChangePartCommand (undo_text, p_cep, property, p_cep->property(property), new_value);
-
-		//And other parts are just child of parent
-	foreach (CustomElementPart *cep, updated_part)
-		new ChangePartCommand (undo_text, cep, property, cep->property(property), new_value, parent_undo);
-
-	undoStack().push(parent_undo);
-}
-
 /// @return Le nom du type d'element edite
 QString ElementItemEditor::elementTypeName() const {
 	return(element_type_name);

Modified: trunk/sources/editor/elementitemeditor.h
===================================================================
--- trunk/sources/editor/elementitemeditor.h	2015-07-24 12:56:27 UTC (rev 4072)
+++ trunk/sources/editor/elementitemeditor.h	2015-07-24 13:41:51 UTC (rev 4073)
@@ -46,9 +46,6 @@
 		virtual ElementScene *elementScene() const;
 		virtual QUndoStack &undoStack() const;
 
-		virtual void addChangePartCommand(const QString &, CustomElementPart *, const char *, const QVariant &);
-		virtual void addChangePartCommand(const QString &, QList<CustomElementPart *>, const char *, const QVariant &);
-
 		virtual QString elementTypeName() const;
 		virtual void setElementTypeName(const QString &);
 		virtual void detach();

Modified: trunk/sources/editor/styleeditor.cpp
===================================================================
--- trunk/sources/editor/styleeditor.cpp	2015-07-24 12:56:27 UTC (rev 4072)
+++ trunk/sources/editor/styleeditor.cpp	2015-07-24 13:41:51 UTC (rev 4073)
@@ -17,6 +17,7 @@
 */
 #include "styleeditor.h"
 #include "customelementgraphicpart.h"
+#include "QPropertyUndoCommand/qpropertyundocommand.h"
 
 /**
 	Constructeur
@@ -119,62 +120,30 @@
 /// Destructeur
 StyleEditor::~StyleEditor() {
 }
-/**
- * @brief StyleEditor::updatePart
- * Update the part from the content of the form
- */
-void StyleEditor::updatePart() {
-	if (!part) return;
-	part->setProperty("antialias",	 antialiasing  -> isChecked());
-	part->setProperty("color",		 outline_color -> itemData(outline_color -> currentIndex()));
-	part->setProperty("line_style",  line_style	   -> itemData(line_style	 -> currentIndex()));
-	part->setProperty("line_weight", size_weight   -> itemData(size_weight	 -> currentIndex()));
-	part->setProperty("filling",	 filling_color -> itemData(filling_color -> currentIndex()));
-}
 
 /// Update antialiasing with undo command
-void StyleEditor::updatePartAntialiasing()
-{
-	if (part)
-		addChangePartCommand(tr("style antialiasing"), part, "antialias",   antialiasing -> isChecked());
-	else if (!m_part_list.isEmpty())
-		addChangePartCommand(tr("style antialiasing"), m_cep_list, "antialias",   antialiasing -> isChecked());
+void StyleEditor::updatePartAntialiasing() {
+	makeUndo(tr("style antialiasing"), "antialias", antialiasing -> isChecked());
 }
 
 /// Update color with undo command
-void StyleEditor::updatePartColor()
-{
-	if (part)
-		addChangePartCommand(tr("style couleur"), part, "color", outline_color->itemData(outline_color -> currentIndex()));
-	else if (!m_part_list.isEmpty())
-		addChangePartCommand(tr("style couleur"), m_cep_list, "color", outline_color->itemData(outline_color -> currentIndex()));
+void StyleEditor::updatePartColor() {
+	makeUndo(tr("style couleur"),"color", outline_color->itemData(outline_color -> currentIndex()));
 }
 
 /// Update style with undo command
-void StyleEditor::updatePartLineStyle()
-{
-	if (part)
-		addChangePartCommand(tr("style ligne"), part, "line_style", line_style->itemData(line_style -> currentIndex()));
-	else if (!m_part_list.isEmpty())
-		addChangePartCommand(tr("style ligne"), m_cep_list, "line_style", line_style->itemData(line_style -> currentIndex()));
+void StyleEditor::updatePartLineStyle() {
+	makeUndo(tr("style ligne"), "line_style", line_style->itemData(line_style -> currentIndex()));
 }
 
 /// Update weight with undo command
-void StyleEditor::updatePartLineWeight()
-{
-	if (part)
-		addChangePartCommand(tr("style epaisseur"), part, "line_weight", size_weight->itemData(size_weight -> currentIndex()));
-	else if (!m_part_list.isEmpty())
-		addChangePartCommand(tr("style epaisseur"), m_cep_list, "line_weight", size_weight->itemData(size_weight -> currentIndex()));
+void StyleEditor::updatePartLineWeight() {
+	makeUndo(tr("style epaisseur"), "line_weight", size_weight->itemData(size_weight -> currentIndex()));
 }
 
 /// Update color filling with undo command
-void StyleEditor::updatePartFilling()
-{
-	if(part)
-		addChangePartCommand(tr("style remplissage"), part, "filling", filling_color->itemData(filling_color -> currentIndex()));
-	else if (!m_part_list.isEmpty())
-		addChangePartCommand(tr("style remplissage"), m_cep_list, "filling", filling_color->itemData(filling_color -> currentIndex()));
+void StyleEditor::updatePartFilling() {
+	makeUndo(tr("style remplissage"), "filling", filling_color->itemData(filling_color -> currentIndex()));
 }
 
 /**
@@ -320,3 +289,29 @@
 		disconnect(antialiasing, SIGNAL(stateChanged(int)),  this, SLOT(updatePartAntialiasing()));
 	}
 }
+
+void StyleEditor::makeUndo(const QString &undo_text, const char *property_name, const QVariant &new_value)
+{
+	QPropertyUndoCommand *undo = nullptr;
+	if (part && (new_value != part->property(property_name)))
+	{
+		undo = new QPropertyUndoCommand(part, property_name, part->property(property_name), new_value);
+		undo->setText(undo_text);
+		undoStack().push(undo);
+		return;
+	}
+	else if (!m_part_list.isEmpty())
+	{
+		foreach (CustomElementGraphicPart *cegp, m_part_list)
+		{
+			if (!undo)
+			{
+				undo = new QPropertyUndoCommand(cegp, property_name, cegp->property(property_name), new_value);
+				undo->setText(undo_text);
+			}
+			else
+				new QPropertyUndoCommand(cegp, property_name, cegp->property(property_name), new_value, undo);
+		}
+		undoStack().push(undo);
+	}
+}

Modified: trunk/sources/editor/styleeditor.h
===================================================================
--- trunk/sources/editor/styleeditor.h	2015-07-24 12:56:27 UTC (rev 4072)
+++ trunk/sources/editor/styleeditor.h	2015-07-24 13:41:51 UTC (rev 4073)
@@ -17,9 +17,14 @@
 */
 #ifndef STYLE_EDITOR_H
 #define STYLE_EDITOR_H
-#include <QtWidgets>
+
 #include "elementitemeditor.h"
+
 class CustomElementGraphicPart;
+class QVBoxLayout;
+class QCheckBox;
+class QComboBox;
+
 /**
 	This class provides a widget to edit styles (color, pen style and thickness,
 	filling, antialiasing) common to most primitives within the element editor.
@@ -55,7 +60,6 @@
 		static bool isStyleEditable (QList <CustomElementPart *> cep_list);
 	
 	public slots:
-		void updatePart();
 		void updateForm();
 		void updatePartAntialiasing();
 		void updatePartColor();
@@ -65,5 +69,6 @@
 	
 	private:
 		void activeConnections(bool);
+		void makeUndo(const QString &undo_text, const char *property_name, const QVariant &new_value);
 };
 #endif


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