summaryrefslogtreecommitdiffstats
path: root/qt-ui/undobuffer.h
blob: 9fac147106833b9d106ccd80f1913e24f96fb18b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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) { stateAfter = affectedDive; }
	void undo();
	void redo();
};

class UndoBuffer : public QObject
{
	Q_OBJECT
public:
	explicit UndoBuffer(QObject *parent = 0);
	~UndoBuffer();
	bool canUndo();
	bool canRedo();
	UndoCommand *current() const { return list.at(curIdx - 1); }
private:
	QList<UndoCommand*> list;
	int curIdx;
public slots:
	void redo();
	void undo();
	void recordbefore(QString commandName, dive *affectedDive);
	void recordAfter(dive *affectedDive);
};

#endif // UNDOBUFFER_H