mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
58f2e5f77c
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>
51 lines
808 B
C++
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
|
|
|
|
|