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