]> Shamusworld >> Repos - architektonas/blob - src/base/undo.h
Bugfixes related to removing Snapper class.
[architektonas] / src / base / undo.h
1 #ifndef __UNDO_H__
2 #define __UNDO_H__
3
4 #include <QtCore>
5 #include "undocycle.h"
6
7 /**
8  * Undo / redo functionality. The internal undo list consists of
9  * UndoCycle entries.
10  *
11  * @see UndoCycle
12  * @author Andrew Mustun
13  */
14 class Undo
15 {
16 public:
17                 Undo();
18                 virtual ~Undo();
19
20                 void addUndoCycle(UndoCycle * i);
21
22                 virtual void undo();
23                 virtual void redo();
24
25                 virtual UndoCycle * getUndoCycle();
26                 virtual UndoCycle * getRedoCycle();
27
28                 virtual int countUndoCycles();
29                 virtual int countRedoCycles();
30
31                 virtual void startUndoCycle();
32                 virtual void addUndoable(Undoable * u);
33                 virtual void endUndoCycle();
34
35                 /**
36                 * Must be overwritten by the implementing class and delete
37                 * the given Undoable (unrecoverable). This method is called
38                 * for Undoables that are no longer in the undo buffer.
39                 */
40                 virtual void removeUndoable(Undoable * u) = 0;
41
42                 friend std::ostream & operator<<(std::ostream & os, Undo & a);
43
44 #ifdef RS_TEST
45                 static bool test(void);
46 #endif
47
48         protected:
49                 //! List of undo list items. every item is something that can be undone.
50 //              Q3PtrList<UndoCycle> undoList;
51                 QList<UndoCycle *> undoList;
52
53                 /**
54                 * Index that points to the current position in the undo list.
55                 * The item it points on will be undone the next time undo is called.
56                 * The item after will be redone (if there is an item) when redo
57                 * is called.
58                 */
59                 int undoPointer;
60
61                 /**
62                 * Current undo cycle.
63                 */
64                 UndoCycle * currentCycle;
65 };
66
67 #ifdef RS_TEST
68 /**
69  * Stub for testing the Undo class.
70  */
71 class UndoStub : public Undo
72 {
73     virtual void removeUndoable(Undoable * u)
74     {
75         delete u;
76         u = NULL;
77     }
78 };
79 #endif
80
81 #endif