31 |
31 |
32 class AbstractHistoryEntry; |
32 class AbstractHistoryEntry; |
33 |
33 |
34 // ============================================================================= |
34 // ============================================================================= |
35 class History |
35 class History |
36 { PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) |
36 { |
37 PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) |
37 PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) |
38 PROPERTY (public, bool, Ignoring, BOOL_OPS, STOCK_WRITE) |
38 PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) |
|
39 PROPERTY (public, bool, Ignoring, BOOL_OPS, STOCK_WRITE) |
39 |
40 |
40 public: |
41 public: |
41 typedef QList<AbstractHistoryEntry*> Changeset; |
42 typedef QList<AbstractHistoryEntry*> Changeset; |
42 |
43 |
43 enum Type |
44 enum Type |
44 { Del, |
45 { |
|
46 Del, |
45 Edit, |
47 Edit, |
46 Add, |
48 Add, |
47 Move, |
49 Move, |
48 Swap, |
50 Swap, |
49 }; |
51 }; |
55 |
57 |
56 void addStep(); |
58 void addStep(); |
57 void add (AbstractHistoryEntry* entry); |
59 void add (AbstractHistoryEntry* entry); |
58 |
60 |
59 inline long getSize() const |
61 inline long getSize() const |
60 { return m_changesets.size(); |
62 { |
|
63 return m_changesets.size(); |
61 } |
64 } |
62 |
65 |
63 inline History& operator<< (AbstractHistoryEntry* entry) |
66 inline History& operator<< (AbstractHistoryEntry* entry) |
64 { add (entry); |
67 { |
|
68 add (entry); |
65 return *this; |
69 return *this; |
66 } |
70 } |
67 |
71 |
68 inline const Changeset& getChangeset (long pos) const |
72 inline const Changeset& getChangeset (long pos) const |
69 { return m_changesets[pos]; |
73 { |
|
74 return m_changesets[pos]; |
70 } |
75 } |
71 |
76 |
72 private: |
77 private: |
73 Changeset m_currentChangeset; |
78 Changeset m_currentChangeset; |
74 QList<Changeset> m_changesets; |
79 QList<Changeset> m_changesets; |
76 |
81 |
77 // ============================================================================= |
82 // ============================================================================= |
78 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
79 // ============================================================================= |
84 // ============================================================================= |
80 class AbstractHistoryEntry |
85 class AbstractHistoryEntry |
81 { PROPERTY (public, History*, Parent, NO_OPS, STOCK_WRITE) |
86 { |
|
87 PROPERTY (public, History*, Parent, NO_OPS, STOCK_WRITE) |
82 |
88 |
83 public: |
89 public: |
84 virtual ~AbstractHistoryEntry() {} |
90 virtual ~AbstractHistoryEntry() {} |
85 virtual void undo() const {} |
91 virtual void undo() const {} |
86 virtual void redo() const {} |
92 virtual void redo() const {} |
87 |
93 |
88 virtual History::Type getType() const |
94 virtual History::Type getType() const |
89 { return (History::Type) 0; |
95 { |
|
96 return (History::Type) 0; |
90 } |
97 } |
91 |
98 |
92 virtual const char* getTypeName() const |
99 virtual const char* getTypeName() const |
93 { return ""; |
100 { |
|
101 return ""; |
94 } |
102 } |
95 }; |
103 }; |
96 |
104 |
97 // ============================================================================= |
105 // ============================================================================= |
98 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
99 // ============================================================================= |
107 // ============================================================================= |
100 class DelHistory : public AbstractHistoryEntry |
108 class DelHistory : public AbstractHistoryEntry |
101 { PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
109 { |
|
110 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
102 PROPERTY (private, str, Code, NO_OPS, STOCK_WRITE) |
111 PROPERTY (private, str, Code, NO_OPS, STOCK_WRITE) |
103 |
112 |
104 public: |
113 public: |
105 IMPLEMENT_HISTORY_TYPE (Del) |
114 IMPLEMENT_HISTORY_TYPE (Del) |
106 DelHistory (int idx, LDObject* obj); |
115 DelHistory (int idx, LDObject* obj); |
108 |
117 |
109 // ============================================================================= |
118 // ============================================================================= |
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
111 // ============================================================================= |
120 // ============================================================================= |
112 class EditHistory : public AbstractHistoryEntry |
121 class EditHistory : public AbstractHistoryEntry |
113 { PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
122 { |
|
123 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
114 PROPERTY (private, str, OldCode, NO_OPS, STOCK_WRITE) |
124 PROPERTY (private, str, OldCode, NO_OPS, STOCK_WRITE) |
115 PROPERTY (private, str, NewCode, NO_OPS, STOCK_WRITE) |
125 PROPERTY (private, str, NewCode, NO_OPS, STOCK_WRITE) |
116 |
126 |
117 public: |
127 public: |
118 IMPLEMENT_HISTORY_TYPE (Edit) |
128 IMPLEMENT_HISTORY_TYPE (Edit) |
125 |
135 |
126 // ============================================================================= |
136 // ============================================================================= |
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
128 // ============================================================================= |
138 // ============================================================================= |
129 class AddHistory : public AbstractHistoryEntry |
139 class AddHistory : public AbstractHistoryEntry |
130 { PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
140 { |
|
141 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
131 PROPERTY (private, str, Code, NO_OPS, STOCK_WRITE) |
142 PROPERTY (private, str, Code, NO_OPS, STOCK_WRITE) |
132 |
143 |
133 public: |
144 public: |
134 IMPLEMENT_HISTORY_TYPE (Add) |
145 IMPLEMENT_HISTORY_TYPE (Add) |
135 |
146 |
140 |
151 |
141 // ============================================================================= |
152 // ============================================================================= |
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
143 // ============================================================================= |
154 // ============================================================================= |
144 class MoveHistory : public AbstractHistoryEntry |
155 class MoveHistory : public AbstractHistoryEntry |
145 { public: |
156 { |
|
157 public: |
146 IMPLEMENT_HISTORY_TYPE (Move) |
158 IMPLEMENT_HISTORY_TYPE (Move) |
147 |
159 |
148 QList<int> indices; |
160 QList<int> indices; |
149 vertex dest; |
161 vertex dest; |
150 |
162 |
155 |
167 |
156 // ============================================================================= |
168 // ============================================================================= |
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
158 // ============================================================================= |
170 // ============================================================================= |
159 class SwapHistory : public AbstractHistoryEntry |
171 class SwapHistory : public AbstractHistoryEntry |
160 { public: |
172 { |
|
173 public: |
161 IMPLEMENT_HISTORY_TYPE (Swap) |
174 IMPLEMENT_HISTORY_TYPE (Swap) |
162 |
175 |
163 SwapHistory (int a, int b) : |
176 SwapHistory (int a, int b) : |
164 a (a), |
177 a (a), |
165 b (b) {} |
178 b (b) {} |