Add a class to handle all undo/redo events. Whenever a user action affects a dive, an undo command will be created. A list of these commands will be stored in the UndoBuffer, to allow for moving forwards/backwards in the list. Signed-off-by: Grace Karanja <gracie.karanja89@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
38 lines
648 B
C++
38 lines
648 B
C++
#ifndef UNDOBUFFER_H
|
|
#define UNDOBUFFER_H
|
|
|
|
#include <QObject>
|
|
#include "dive.h"
|
|
|
|
class UndoCommand {
|
|
private:
|
|
dive* stateBefore;
|
|
dive* stateAfter;
|
|
QString name;
|
|
|
|
public:
|
|
explicit UndoCommand(QString commandName, dive* affectedDive);
|
|
void setStateAfter(dive* affectedDive);
|
|
void undo();
|
|
void redo();
|
|
};
|
|
|
|
class UndoBuffer : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit UndoBuffer(QObject *parent = 0);
|
|
~UndoBuffer();
|
|
bool canUndo();
|
|
bool canRedo();
|
|
private:
|
|
int curIdx;
|
|
public slots:
|
|
void redo();
|
|
void undo();
|
|
void recordbefore(QString commandName, dive *affectedDive);
|
|
void recordAfter(dive *affectedDive);
|
|
};
|
|
|
|
#endif // UNDOBUFFER_H
|