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()
|
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"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void execute(Base *cmd)
|
|
|
|
{
|
|
|
|
if (cmd->workToBeDone())
|
|
|
|
undoStack.push(cmd);
|
|
|
|
else
|
|
|
|
delete cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Command
|
|
|
|
|
|
|
|
|