subsurface/desktop-widgets/command_base.cpp
Berthold Stoeger 58f2e5f77c Undo: use QUndoStack::isClean() to determine unsaved changes
Properly implement the unsaved-changes flag(s). Since we currently have
two kinds of changes, there are two flags:
1) dive_list_changed in divelist.c marks non-undoable changes. This flag
   is only cleared on save or load.
2) QUndoStack::isClean() is used to determine the state of undoable
   changes. Every time the user returns to the state where they saved,
   this flag is cleared.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12 18:19:07 +03:00

51 lines
808 B
C++

// SPDX-License-Identifier: GPL-2.0
#include "command_base.h"
#include "core/qthelper.h" // for updateWindowTitle()
namespace Command {
static QUndoStack undoStack;
// General commands
void init()
{
QObject::connect(&undoStack, &QUndoStack::cleanChanged, &updateWindowTitle);
}
void clear()
{
undoStack.clear();
}
void setClean()
{
undoStack.setClean();
}
bool isClean()
{
return undoStack.isClean();
}
QAction *undoAction(QObject *parent)
{
return undoStack.createUndoAction(parent, QCoreApplication::translate("Command", "&Undo"));
}
QAction *redoAction(QObject *parent)
{
return undoStack.createRedoAction(parent, QCoreApplication::translate("Command", "&Redo"));
}
void execute(Base *cmd)
{
if (cmd->workToBeDone())
undoStack.push(cmd);
else
delete cmd;
}
} // namespace Command