]> Shamusworld >> Repos - architektonas/blob - src/base/rs_undo.h
Initial import
[architektonas] / src / base / rs_undo.h
1 /****************************************************************************
2 ** $Id: rs_undo.h 1648 2003-06-11 06:56:01Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #ifndef RS_UNDO_H
28 #define RS_UNDO_H
29
30 #include <QtCore>
31 #include "rs_undocycle.h"
32
33 /**
34  * Undo / redo functionality. The internal undo list consists of
35  * RS_UndoCycle entries.
36  *
37  * @see RS_UndoCycle
38  * @author Andrew Mustun
39  */
40 class RS_Undo
41 {
42 public:
43                 RS_Undo();
44                 virtual ~RS_Undo();
45
46                 void addUndoCycle(RS_UndoCycle * i);
47
48                 virtual void undo();
49                 virtual void redo();
50
51                 virtual RS_UndoCycle * getUndoCycle();
52                 virtual RS_UndoCycle * getRedoCycle();
53
54                 virtual int countUndoCycles();
55                 virtual int countRedoCycles();
56
57                 virtual void startUndoCycle();
58                 virtual void addUndoable(RS_Undoable * u);
59                 virtual void endUndoCycle();
60
61                 /**
62                 * Must be overwritten by the implementing class and delete
63                 * the given Undoable (unrecoverable). This method is called
64                 * for Undoables that are no longer in the undo buffer.
65                 */
66                 virtual void removeUndoable(RS_Undoable * u) = 0;
67
68                 friend std::ostream & operator<<(std::ostream & os, RS_Undo & a);
69
70 #ifdef RS_TEST
71                 static bool test(void);
72 #endif
73
74         protected:
75                 //! List of undo list items. every item is something that can be undone.
76 //              Q3PtrList<RS_UndoCycle> undoList;
77                 QList<RS_UndoCycle *> undoList;
78
79                 /**
80                 * Index that points to the current position in the undo list.
81                 * The item it points on will be undone the next time undo is called.
82                 * The item after will be redone (if there is an item) when redo
83                 * is called.
84                 */
85                 int undoPointer;
86
87                 /**
88                 * Current undo cycle.
89                 */
90                 RS_UndoCycle * currentCycle;
91 };
92
93 #ifdef RS_TEST
94 /**
95  * Stub for testing the RS_Undo class.
96  */
97 class RS_UndoStub : public RS_Undo
98 {
99     virtual void removeUndoable(RS_Undoable * u)
100     {
101         delete u;
102         u = NULL;
103     }
104 };
105 #endif
106
107 #endif