mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Create a C string (which the caller needs to free) with the executed commands in this session. The detour via the callback allows us to not make the corelib depend on the commands, which is nice for tests, export-html, and smtk2ssrf. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
76 lines
1.4 KiB
C++
76 lines
1.4 KiB
C++
// 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;
|
|
|
|
// forward declaration
|
|
QString changesMade();
|
|
|
|
// General commands
|
|
void init()
|
|
{
|
|
QObject::connect(&undoStack, &QUndoStack::cleanChanged, &updateWindowTitle);
|
|
changesCallback = &changesMade;
|
|
}
|
|
|
|
void clear()
|
|
{
|
|
undoStack.clear();
|
|
}
|
|
|
|
void setClean()
|
|
{
|
|
undoStack.setClean();
|
|
}
|
|
|
|
bool isClean()
|
|
{
|
|
return undoStack.isClean();
|
|
}
|
|
|
|
// this can be used to get access to the signals emitted by the QUndoStack
|
|
QUndoStack *getUndoStack()
|
|
{
|
|
return &undoStack;
|
|
}
|
|
|
|
QAction *undoAction(QObject *parent)
|
|
{
|
|
return undoStack.createUndoAction(parent, QCoreApplication::translate("Command", "&Undo"));
|
|
}
|
|
|
|
QAction *redoAction(QObject *parent)
|
|
{
|
|
return undoStack.createRedoAction(parent, QCoreApplication::translate("Command", "&Redo"));
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
|
|
bool execute(Base *cmd)
|
|
{
|
|
if (cmd->workToBeDone()) {
|
|
undoStack.push(cmd);
|
|
emit diveListNotifier.commandExecuted();
|
|
return true;
|
|
} else {
|
|
delete cmd;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
} // namespace Command
|
|
|
|
|