2015-02-09 08:17:38 +00:00
|
|
|
#ifndef UNDOBUFFER_H
|
|
|
|
#define UNDOBUFFER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include "dive.h"
|
|
|
|
|
2015-02-09 08:30:27 +00:00
|
|
|
class UndoCommand {
|
|
|
|
private:
|
|
|
|
dive* stateBefore;
|
|
|
|
dive* stateAfter;
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit UndoCommand(QString commandName, dive* affectedDive);
|
2015-02-09 08:44:10 +00:00
|
|
|
void setStateAfter(dive* affectedDive) { stateAfter = affectedDive; }
|
2015-02-09 08:30:27 +00:00
|
|
|
void undo();
|
|
|
|
void redo();
|
|
|
|
};
|
|
|
|
|
2015-02-09 08:17:38 +00:00
|
|
|
class UndoBuffer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit UndoBuffer(QObject *parent = 0);
|
|
|
|
~UndoBuffer();
|
|
|
|
bool canUndo();
|
|
|
|
bool canRedo();
|
2015-02-09 08:44:10 +00:00
|
|
|
UndoCommand *current() const { return list.at(curIdx - 1); }
|
2015-02-09 08:17:38 +00:00
|
|
|
private:
|
2015-02-09 08:44:10 +00:00
|
|
|
QList<UndoCommand*> list;
|
2015-02-09 08:17:38 +00:00
|
|
|
int curIdx;
|
|
|
|
public slots:
|
|
|
|
void redo();
|
|
|
|
void undo();
|
|
|
|
void recordbefore(QString commandName, dive *affectedDive);
|
|
|
|
void recordAfter(dive *affectedDive);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // UNDOBUFFER_H
|