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