[qet] qet/qet: [4740] Use QUndoCommand with childs, as recommended by Qt documentation

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


Revision: 4740
Author:   blacksun
Date:     2016-10-13 20:00:31 +0200 (Thu, 13 Oct 2016)
Log Message:
-----------
Use QUndoCommand with childs, as recommended by Qt documentation

Modified Paths:
--------------
    trunk/sources/elementsmover.cpp

Modified: trunk/sources/elementsmover.cpp
===================================================================
--- trunk/sources/elementsmover.cpp	2016-10-13 01:41:43 UTC (rev 4739)
+++ trunk/sources/elementsmover.cpp	2016-10-13 18:00:31 UTC (rev 4740)
@@ -125,12 +125,15 @@
 {
 		// A movement must be inited
 	if (!movement_running_) return;
-	
-	QUndoCommand *undo_object = nullptr;
 
+		//empty command to be used has parent of commands below
+	QUndoCommand *undo_object = new QUndoCommand();
+
 		//Create undo move if there is a movement
-	if (!current_movement_.isNull())
-		undo_object = new MoveElementsCommand(diagram_, moved_content_, current_movement_);
+	if (!current_movement_.isNull()) {
+		QUndoCommand *quc = new MoveElementsCommand(diagram_, moved_content_, current_movement_, undo_object);
+		undo_object->setText(quc->text());
+	}
 
 		//There is only one element moved, and project authorize auto conductor,
 		//we try auto connection of conductor;
@@ -141,6 +144,8 @@
 	{
 		Element *elmt = moved_content_.elements.toList().first();
 
+		int acc = elmt->AlignedFreeTerminals().size();
+
 		while (!elmt -> AlignedFreeTerminals().isEmpty())
 		{
 			QPair <Terminal *, Terminal *> pair = elmt -> AlignedFreeTerminals().takeFirst();
@@ -147,12 +152,10 @@
 
 			Conductor *conductor = new Conductor(pair.first, pair.second);
 
-				//Create an undo object for each new auto conductor, with undo_object for parent if exist
-				//Else the first undo for this auto conductor become the undo_object
-			if (undo_object)
-				new AddItemCommand<Conductor *>(conductor, diagram_, QPointF(), undo_object);
-			else
-				undo_object = new AddItemCommand<Conductor *>(conductor, diagram_, QPointF());
+				//Create an undo object for each new auto conductor, with undo_object for parent
+			new AddItemCommand<Conductor *>(conductor, diagram_, QPointF(), undo_object);
+				if (undo_object->text().isEmpty())
+					undo_object->setText(QObject::tr("Ajouter %n conducteur(s)", "add a numbers of conductor one or more", acc));
 
 				//Get all conductors at the same potential of conductor
 			QSet <Conductor *> conductors_list = conductor->relatedPotentialConductors();
@@ -183,9 +186,11 @@
 		};
 	}
 
-		//Add undo_object if exist
-	if (undo_object)
+		//Add undo_object if have child
+	if (undo_object->childCount() >= 1)
 		diagram_ -> undoStack().push(undo_object);
+	else
+		delete undo_object;
 	
 		// There is no movement in progress now
 	movement_running_ = false;


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