2018-07-23 21:41:23 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include "command_base.h"
|
2019-03-30 17:39:27 +00:00
|
|
|
#include "core/qthelper.h" // for updateWindowTitle()
|
2019-05-24 19:38:56 +00:00
|
|
|
#include "core/subsurface-qt/DiveListNotifier.h"
|
2018-07-23 21:41:23 +00:00
|
|
|
|
|
|
|
namespace Command {
|
|
|
|
|
|
|
|
static QUndoStack undoStack;
|
|
|
|
|
|
|
|
// General commands
|
2019-03-30 17:39:27 +00:00
|
|
|
void init()
|
|
|
|
{
|
|
|
|
QObject::connect(&undoStack, &QUndoStack::cleanChanged, &updateWindowTitle);
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:41:23 +00:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
undoStack.clear();
|
|
|
|
}
|
|
|
|
|
2019-03-30 17:39:27 +00:00
|
|
|
void setClean()
|
|
|
|
{
|
|
|
|
undoStack.setClean();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isClean()
|
|
|
|
{
|
|
|
|
return undoStack.isClean();
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:41:23 +00:00
|
|
|
QAction *undoAction(QObject *parent)
|
|
|
|
{
|
|
|
|
return undoStack.createUndoAction(parent, QCoreApplication::translate("Command", "&Undo"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *redoAction(QObject *parent)
|
|
|
|
{
|
|
|
|
return undoStack.createRedoAction(parent, QCoreApplication::translate("Command", "&Redo"));
|
|
|
|
}
|
|
|
|
|
2019-05-24 19:17:22 +00:00
|
|
|
bool execute(Base *cmd)
|
2018-07-23 21:41:23 +00:00
|
|
|
{
|
2019-05-24 19:17:22 +00:00
|
|
|
if (cmd->workToBeDone()) {
|
2018-07-23 21:41:23 +00:00
|
|
|
undoStack.push(cmd);
|
2019-05-24 19:38:56 +00:00
|
|
|
emit diveListNotifier.commandExecuted();
|
2019-05-24 19:17:22 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2018-07-23 21:41:23 +00:00
|
|
|
delete cmd;
|
2019-05-24 19:17:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-23 21:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Command
|
|
|
|
|
|
|
|
|