undo: Clear undo stack on file close

The undo stack is only relevant to the dives that were loaded at the
time the command was executed. If a file is closed, by specifically
closing it or opening another file, then the undo commands will
reference dives that aren't available anymore. Clearing the undo stack
ensures that we don't crash or accidentally do some undefined
modifications to the currently open file.

Signed-off-by: Michael Andreen <michael@andreen.dev>
This commit is contained in:
Michael Andreen 2022-04-02 17:39:38 +02:00 committed by Dirk Hohndel
parent ada4632ff1
commit be2bdb8650
3 changed files with 3 additions and 1 deletions

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "command.h"
#include "command_base.h"
#include "core/globals.h"
#include "core/qthelper.h" // for updateWindowTitle()
@ -18,6 +19,7 @@ void init()
{
undoStack = make_global<QUndoStack>();
QObject::connect(undoStack, &QUndoStack::cleanChanged, &updateWindowTitle);
QObject::connect(&diveListNotifier, &DiveListNotifier::dataReset, &Command::clear);
changesCallback = &changesMade;
}