]> Shamusworld >> Repos - architektonas/blob - src/base/rs_undoable.cpp
84f10b51fed5f211de7da77e9d5999cc2f90da63
[architektonas] / src / base / rs_undoable.cpp
1 /****************************************************************************
2 ** $Id: rs_undoable.cpp 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 #include "rs_undoable.h"
28
29 #include "rs_undocycle.h"
30
31 /**
32  * Default constructor.
33  */
34 RS_Undoable::RS_Undoable()
35 {
36         cycle = NULL;
37 }
38
39 /**
40  * Destructor. Makes sure that this undoable is removed from
41  * its undo cycle before it is deleted.
42  */
43 RS_Undoable::~RS_Undoable()
44 {
45         if (cycle != NULL)
46                 cycle->removeUndoable(this);
47 }
48
49 /**
50  * Runtime type identification for undoables.
51  * Note that this is voluntarily. The default implementation
52  * returns RS2::UndoableUnknown.
53  */
54 /*virtual*/ RS2::UndoableType RS_Undoable::undoRtti()
55 {
56         return RS2::UndoableUnknown;
57 }
58
59 /**
60  * Sets the undo cycle this entity is in. This is necessary to
61  * make sure the entity can remove itself from the cycle before
62  * being deleted.
63  */
64 void RS_Undoable::setUndoCycle(RS_UndoCycle * cycle)
65 {
66         this->cycle = cycle;
67 }
68
69 /**
70  * The undoable thing gets activated if it was undone and
71  * deactivated otherwise.
72  */
73 void RS_Undoable::changeUndoState()
74 {
75         toggleFlag(RS2::FlagUndone);
76         undoStateChanged(isUndone());
77 }
78
79 /**
80  * Undoes or redoes an undoable.
81  */
82 void RS_Undoable::setUndoState(bool undone)
83 {
84         if (undone)
85                 setFlag(RS2::FlagUndone);
86         else
87                 delFlag(RS2::FlagUndone);
88
89         undoStateChanged(isUndone());
90 }
91
92 /**
93  * Is this entity in the Undo memory and not active?
94  */
95 bool RS_Undoable::isUndone() const
96 {
97         return getFlag(RS2::FlagUndone);
98 }
99
100 /**
101  * Can be overwriten by the implementing class to be notified
102  * when the undo state changes (the undoable becomes visible / invisible).
103  */
104 /*virtual*/ void RS_Undoable::undoStateChanged(bool /*undone*/)
105 {
106 }