]> Shamusworld >> Repos - architektonas/blob - src/base/rs_undocycle.cpp
65c8798c65038f1e0ff05a2f0b6fa7baf0dbee59
[architektonas] / src / base / rs_undocycle.cpp
1 // rs_undocycle.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  05/05/2010  Moved implementation from header to this file. :-)
13 //
14
15 #include "rs_undocycle.h"
16
17 #include "rs_entity.h"
18 #include "rs_undoable.h"
19
20 /**
21  * @param type Type of undo item.
22  */
23 RS_UndoCycle::RS_UndoCycle(/*RS2::UndoType type*/): undoableIterator(undoables)
24 {
25         //this->type = type;
26 // Good, we don't have to worry about this...
27 //      undoables.setAutoDelete(false);
28 }
29
30 /**
31  * Adds an Undoable to this Undo Cycle. Every Cycle can contain one or
32  * more Undoables.
33  */
34 void RS_UndoCycle::addUndoable(RS_Undoable * u)
35 {
36         undoables.append(u);
37 }
38
39 /**
40  * Removes an undoable from the list.
41  */
42 void RS_UndoCycle::removeUndoable(RS_Undoable * u)
43 {
44 //      undoables.remove(u);
45         int i = undoables.indexOf(u);
46         undoables.takeAt(i);
47 }
48
49 /**
50  * Iteration through undoable elements in this item.
51  */
52 RS_Undoable * RS_UndoCycle::getFirstUndoable()
53 {
54 //      return undoables.first();
55         undoableIterator.toFront();
56         return undoableIterator.next();
57 }
58
59 /**
60  * Iteration through undoable elements in this item.
61  */
62 RS_Undoable * RS_UndoCycle::getNextUndoable()
63 {
64 //      return undoables.next();
65         return undoableIterator.next();
66 }
67
68 /*friend*/ std::ostream & operator<<(std::ostream & os, RS_UndoCycle & i)
69 {
70         os << " Undo item: " << "\n";
71         //os << "   Type: ";
72         /*switch (i.type) {
73         case RS2::UndoAdd:
74                 os << "RS2::UndoAdd";
75                 break;
76         case RS2::UndoDel:
77                 os << "RS2::UndoDel";
78                 break;
79 }*/
80         os << "   Undoable ids: ";
81
82         for(RS_Undoable * u=i.getFirstUndoable(); u!=NULL; u=i.getNextUndoable())
83         {
84                 if (u->undoRtti() == RS2::UndoableEntity)
85                 {
86                         RS_Entity * e = (RS_Entity *)u;
87                         os << e->getId() << (u->isUndone() ? "*" : "") << " ";
88                 }
89                 else
90                 {
91                         os << "|";
92                 }
93         }
94
95         return os;
96 }