]> Shamusworld >> Repos - architektonas/blob - src/base/rs_undoable.cpp
a371e604dfafcbb06a55b5777ef5e00648a2b8ab
[architektonas] / src / base / rs_undoable.cpp
1 // rs_undoable.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  06/02/2010  Added this text. :-)
13 //
14
15 #include "rs_undoable.h"
16
17 #include "rs_undocycle.h"
18
19 /**
20  * Default constructor.
21  */
22 RS_Undoable::RS_Undoable()
23 {
24         cycle = NULL;
25 }
26
27 /**
28  * Destructor. Makes sure that this undoable is removed from
29  * its undo cycle before it is deleted.
30  */
31 RS_Undoable::~RS_Undoable()
32 {
33         if (cycle != NULL)
34                 cycle->removeUndoable(this);
35 }
36
37 /**
38  * Runtime type identification for undoables.
39  * Note that this is voluntarily. The default implementation
40  * returns RS2::UndoableUnknown.
41  */
42 /*virtual*/ RS2::UndoableType RS_Undoable::undoRtti()
43 {
44         return RS2::UndoableUnknown;
45 }
46
47 /**
48  * Sets the undo cycle this entity is in. This is necessary to
49  * make sure the entity can remove itself from the cycle before
50  * being deleted.
51  */
52 void RS_Undoable::setUndoCycle(RS_UndoCycle * cycle)
53 {
54         this->cycle = cycle;
55 }
56
57 /**
58  * The undoable thing gets activated if it was undone and
59  * deactivated otherwise.
60  */
61 void RS_Undoable::changeUndoState()
62 {
63         toggleFlag(RS2::FlagUndone);
64         undoStateChanged(isUndone());
65 }
66
67 /**
68  * Undoes or redoes an undoable.
69  */
70 void RS_Undoable::setUndoState(bool undone)
71 {
72         if (undone)
73                 setFlag(RS2::FlagUndone);
74         else
75                 delFlag(RS2::FlagUndone);
76
77         undoStateChanged(isUndone());
78 }
79
80 /**
81  * Is this entity in the Undo memory and not active?
82  */
83 bool RS_Undoable::isUndone() const
84 {
85         return getFlag(RS2::FlagUndone);
86 }
87
88 /**
89  * Can be overwriten by the implementing class to be notified
90  * when the undo state changes (the undoable becomes visible / invisible).
91  */
92 /*virtual*/ void RS_Undoable::undoStateChanged(bool /*undone*/)
93 {
94 }