Gui: Fix undo/redo behaviour in transformation tool

If the user clicks on undo while the transformation dialog is
open the currently active transaction will be closed.
From now on any change of the placement won't be recorded any
more so that e.g. canceling the dialog or an undo after
accepting the dialog leads to unexpected behaviour.

To fix the issue two new virtual methods onUndo() and onRedo()
are added to TaskDialog and reimplemented in TaskTransformDialog.
These functions make sure to open a new transaction.

This fixes issue 19152
This commit is contained in:
wmayer
2025-01-23 23:49:13 +01:00
committed by Ladislav Michl
parent 30ccf2ab26
commit c42dfe1ef3
6 changed files with 51 additions and 16 deletions

View File

@@ -728,16 +728,31 @@ void TaskTransformDialog::open()
Gui::TaskView::TaskDialog::open();
Gui::Application::Instance->activeDocument()->openCommand(
QT_TRANSLATE_NOOP("Command", "Transform"));
openCommand();
}
void TaskTransformDialog::openCommand()
{
if (auto document = vp->getDocument()) {
if (!document->hasPendingCommand()) {
document->openCommand(QT_TRANSLATE_NOOP("Command", "Transform"));
}
}
}
void TaskTransformDialog::onUndo()
{
openCommand();
}
void TaskTransformDialog::onRedo()
{
openCommand();
}
bool TaskTransformDialog::accept()
{
if (auto documentObject = vp->getObject()) {
Gui::Document* document =
Gui::Application::Instance->getDocument(documentObject->getDocument());
assert(document);
if (auto document = vp->getDocument()) {
document->commitCommand();
document->resetEdit();
document->getDocument()->recompute();
@@ -748,10 +763,7 @@ bool TaskTransformDialog::accept()
bool TaskTransformDialog::reject()
{
if (auto documentObject = vp->getObject()) {
Gui::Document* document =
Gui::Application::Instance->getDocument(documentObject->getDocument());
assert(document);
if (auto document = vp->getDocument()) {
document->abortCommand();
document->resetEdit();
document->getDocument()->recompute();