safer handling of command macros
parent
b5005f7812
commit
b2181fae20
@ -0,0 +1,26 @@
|
||||
|
||||
#include "commandmacro.hpp"
|
||||
|
||||
#include <QUndoStack>
|
||||
#include <QUndoCommand>
|
||||
|
||||
CSMWorld::CommandMacro::CommandMacro (QUndoStack& undoStack, const QString& description)
|
||||
: mUndoStack (undoStack), mDescription (description), mStarted (false)
|
||||
{}
|
||||
|
||||
CSMWorld::CommandMacro::~CommandMacro()
|
||||
{
|
||||
if (mStarted)
|
||||
mUndoStack.endMacro();
|
||||
}
|
||||
|
||||
void CSMWorld::CommandMacro::push (QUndoCommand *command)
|
||||
{
|
||||
if (!mStarted)
|
||||
{
|
||||
mUndoStack.beginMacro (mDescription.isEmpty() ? command->text() : mDescription);
|
||||
mStarted = true;
|
||||
}
|
||||
|
||||
mUndoStack.push (command);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#ifndef CSM_WOLRD_COMMANDMACRO_H
|
||||
#define CSM_WOLRD_COMMANDMACRO_H
|
||||
|
||||
class QUndoStack;
|
||||
class QUndoCommand;
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class CommandMacro
|
||||
{
|
||||
QUndoStack& mUndoStack;
|
||||
QString mDescription;
|
||||
bool mStarted;
|
||||
|
||||
/// not implemented
|
||||
CommandMacro (const CommandMacro&);
|
||||
|
||||
/// not implemented
|
||||
CommandMacro& operator= (const CommandMacro&);
|
||||
|
||||
public:
|
||||
|
||||
/// If \a description is empty, the description of the first command is used.
|
||||
CommandMacro (QUndoStack& undoStack, const QString& description = "");
|
||||
|
||||
~CommandMacro();
|
||||
|
||||
void push (QUndoCommand *command);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue