]> Shamusworld >> Repos - architektonas/blob - src/base/rs_undo.h
Fixed thumbnail rendering in LibraryWidget and DXF detection.
[architektonas] / src / base / rs_undo.h
1 #ifndef RS_UNDO_H
2 #define RS_UNDO_H
3
4 #include <QtCore>
5 #include "rs_undocycle.h"
6
7 /**
8  * Undo / redo functionality. The internal undo list consists of
9  * RS_UndoCycle entries.
10  *
11  * @see RS_UndoCycle
12  * @author Andrew Mustun
13  */
14 class RS_Undo
15 {
16 public:
17                 RS_Undo();
18                 virtual ~RS_Undo();
19
20                 void addUndoCycle(RS_UndoCycle * i);
21
22                 virtual void undo();
23                 virtual void redo();
24
25                 virtual RS_UndoCycle * getUndoCycle();
26                 virtual RS_UndoCycle * getRedoCycle();
27
28                 virtual int countUndoCycles();
29                 virtual int countRedoCycles();
30
31                 virtual void startUndoCycle();
32                 virtual void addUndoable(RS_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(RS_Undoable * u) = 0;
41
42                 friend std::ostream & operator<<(std::ostream & os, RS_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<RS_UndoCycle> undoList;
51                 QList<RS_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                 RS_UndoCycle * currentCycle;
65 };
66
67 #ifdef RS_TEST
68 /**
69  * Stub for testing the RS_Undo class.
70  */
71 class RS_UndoStub : public RS_Undo
72 {
73     virtual void removeUndoable(RS_Undoable * u)
74     {
75         delete u;
76         u = NULL;
77     }
78 };
79 #endif
80
81 #endif