From 1b8f3a06ecd1361e5c764cddf22fadbf79a28690 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 14 Feb 2022 21:47:12 +0100 Subject: [PATCH] undo: add flag that indicates whether a command has been placed In multiple places we have the problem that when an undo command is executed, the corresponding value-changed signals are emitted, which in turn updates the UI. This can have nasty UI effects, such as the cursor position in the notes field being reset. To avoid this, add a flag that indicates whether a newly placed command is currently executed. Signed-off-by: Berthold Stoeger --- commands/command.h | 1 + commands/command_base.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/commands/command.h b/commands/command.h index 19908ca7c..303915ea7 100644 --- a/commands/command.h +++ b/commands/command.h @@ -26,6 +26,7 @@ bool isClean(); // Any changes need to be saved? QAction *undoAction(QObject *parent); // Create an undo action. QAction *redoAction(QObject *parent); // Create an redo action. QString changesMade(); // return a string with the texts from all commands on the undo stack -> for commit message +bool placingCommand(); // Currently executing a new command -> might not have to update the field the user just edited. // 2) Dive-list related commands diff --git a/commands/command_base.cpp b/commands/command_base.cpp index 8ebbf9be5..1110699a9 100644 --- a/commands/command_base.cpp +++ b/commands/command_base.cpp @@ -91,10 +91,13 @@ QString changesMade() return changeTexts; } +static bool executingCommand = false; bool execute(Base *cmd) { if (cmd->workToBeDone()) { + executingCommand = true; undoStack.push(cmd); + executingCommand = false; emit diveListNotifier.commandExecuted(); return true; } else { @@ -103,6 +106,11 @@ bool execute(Base *cmd) } } +bool placingCommand() +{ + return executingCommand; +} + } // namespace Command