mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
Use QUndoCommand with childs, as recommended by Qt documentation
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4740 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -126,11 +126,14 @@ void ElementsMover::endMovement()
|
|||||||
// A movement must be inited
|
// A movement must be inited
|
||||||
if (!movement_running_) return;
|
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
|
//Create undo move if there is a movement
|
||||||
if (!current_movement_.isNull())
|
if (!current_movement_.isNull()) {
|
||||||
undo_object = new MoveElementsCommand(diagram_, moved_content_, current_movement_);
|
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,
|
//There is only one element moved, and project authorize auto conductor,
|
||||||
//we try auto connection of conductor;
|
//we try auto connection of conductor;
|
||||||
@@ -141,18 +144,18 @@ void ElementsMover::endMovement()
|
|||||||
{
|
{
|
||||||
Element *elmt = moved_content_.elements.toList().first();
|
Element *elmt = moved_content_.elements.toList().first();
|
||||||
|
|
||||||
|
int acc = elmt->AlignedFreeTerminals().size();
|
||||||
|
|
||||||
while (!elmt -> AlignedFreeTerminals().isEmpty())
|
while (!elmt -> AlignedFreeTerminals().isEmpty())
|
||||||
{
|
{
|
||||||
QPair <Terminal *, Terminal *> pair = elmt -> AlignedFreeTerminals().takeFirst();
|
QPair <Terminal *, Terminal *> pair = elmt -> AlignedFreeTerminals().takeFirst();
|
||||||
|
|
||||||
Conductor *conductor = new Conductor(pair.first, pair.second);
|
Conductor *conductor = new Conductor(pair.first, pair.second);
|
||||||
|
|
||||||
//Create an undo object for each new auto conductor, with undo_object for parent if exist
|
//Create an undo object for each new auto conductor, with undo_object for parent
|
||||||
//Else the first undo for this auto conductor become the undo_object
|
new AddItemCommand<Conductor *>(conductor, diagram_, QPointF(), undo_object);
|
||||||
if (undo_object)
|
if (undo_object->text().isEmpty())
|
||||||
new AddItemCommand<Conductor *>(conductor, diagram_, QPointF(), undo_object);
|
undo_object->setText(QObject::tr("Ajouter %n conducteur(s)", "add a numbers of conductor one or more", acc));
|
||||||
else
|
|
||||||
undo_object = new AddItemCommand<Conductor *>(conductor, diagram_, QPointF());
|
|
||||||
|
|
||||||
//Get all conductors at the same potential of conductor
|
//Get all conductors at the same potential of conductor
|
||||||
QSet <Conductor *> conductors_list = conductor->relatedPotentialConductors();
|
QSet <Conductor *> conductors_list = conductor->relatedPotentialConductors();
|
||||||
@@ -183,9 +186,11 @@ void ElementsMover::endMovement()
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add undo_object if exist
|
//Add undo_object if have child
|
||||||
if (undo_object)
|
if (undo_object->childCount() >= 1)
|
||||||
diagram_ -> undoStack().push(undo_object);
|
diagram_ -> undoStack().push(undo_object);
|
||||||
|
else
|
||||||
|
delete undo_object;
|
||||||
|
|
||||||
// There is no movement in progress now
|
// There is no movement in progress now
|
||||||
movement_running_ = false;
|
movement_running_ = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user