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()
|
2020-02-03 18:33:06 +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();
|
|
|
|
}
|
|
|
|
|
2020-01-11 23:22:50 +00:00
|
|
|
// this can be used to get access to the signals emitted by the QUndoStack
|
|
|
|
QUndoStack *getUndoStack()
|
|
|
|
{
|
|
|
|
return &undoStack;
|
|
|
|
}
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2020-03-05 16:56:17 +00:00
|
|
|
// return a string that can be used for the commit message and should list the changes that
|
|
|
|
// were made to the dive list
|
|
|
|
QString changesMade()
|
|
|
|
{
|
|
|
|
QString changeTexts;
|
|
|
|
for (int i = 0; i < undoStack.index(); i++)
|
|
|
|
changeTexts += undoStack.text(i) + "\n";
|
|
|
|
return changeTexts;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|