mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Refactoring: move undo commands to top level
In the future we might want to use undo-commands for mobile as well (even if not implementing undo). Therefore, move the undo-command source from desktop-widgets to their own commands top-level folder. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
685b92b9c2
commit
5e29245e68
34 changed files with 45 additions and 31 deletions
56
commands/command_base.cpp
Normal file
56
commands/command_base.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#include "command_base.h"
|
||||
#include "core/qthelper.h" // for updateWindowTitle()
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
bool execute(Base *cmd)
|
||||
{
|
||||
if (cmd->workToBeDone()) {
|
||||
undoStack.push(cmd);
|
||||
emit diveListNotifier.commandExecuted();
|
||||
return true;
|
||||
} else {
|
||||
delete cmd;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Command
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue