14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
15 * You should have received a copy of the GNU General Public License |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #ifndef HISTORY_H |
19 #ifndef LDFORGE_HISTORY_H |
20 #define HISTORY_H |
20 #define LDFORGE_HISTORY_H |
21 |
21 |
22 #include "common.h" |
22 #include "main.h" |
23 #include "ldtypes.h" |
23 #include "ldtypes.h" |
24 |
24 |
25 #define IMPLEMENT_HISTORY_TYPE(N) \ |
25 #define IMPLEMENT_HISTORY_TYPE(N) \ |
26 virtual ~N##History(); \ |
26 virtual ~N##History() {} \ |
27 virtual void undo() const override; \ |
27 virtual void undo() const override; \ |
28 virtual void redo() const override; \ |
28 virtual void redo() const override; \ |
29 virtual History::Type getType() const override { return History::N; } |
29 \ |
|
30 virtual History::EHistoryType getType() const override \ |
|
31 { \ |
|
32 return History::E##N##History; \ |
|
33 } \ |
|
34 \ |
|
35 virtual QString getTypeName() const \ |
|
36 { \ |
|
37 return #N; \ |
|
38 } |
30 |
39 |
31 class AbstractHistoryEntry; |
40 class AbstractHistoryEntry; |
32 |
41 |
33 // ============================================================================= |
42 // ============================================================================= |
34 class History |
43 class History |
35 { PROPERTY (long, pos, setPos) |
44 { |
36 PROPERTY (LDFile*, file, setFile) |
45 PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) |
37 READ_PROPERTY (bool, opened, setOpened) |
46 PROPERTY (public, LDDocument*, Document, NO_OPS, STOCK_WRITE) |
|
47 PROPERTY (public, bool, Ignoring, BOOL_OPS, STOCK_WRITE) |
38 |
48 |
39 public: |
49 public: |
40 typedef QList<AbstractHistoryEntry*> Changeset; |
50 typedef QList<AbstractHistoryEntry*> Changeset; |
41 |
51 |
42 enum Type |
52 enum EHistoryType |
43 { Del, |
53 { |
44 Edit, |
54 EDelHistory, |
45 Add, |
55 EEditHistory, |
46 Move, |
56 EAddHistory, |
47 Swap, |
57 EMoveHistory, |
|
58 ESwapHistory, |
48 }; |
59 }; |
49 |
60 |
50 History(); |
61 History(); |
51 void undo(); |
62 void undo(); |
52 void redo(); |
63 void redo(); |
53 void clear(); |
64 void clear(); |
54 void updateActions() const; |
|
55 |
65 |
56 void open(); |
66 void addStep(); |
57 void close(); |
|
58 void add (AbstractHistoryEntry* entry); |
67 void add (AbstractHistoryEntry* entry); |
59 |
68 |
60 inline long size() const |
69 inline long getSize() const |
61 { return m_changesets.size(); |
70 { |
|
71 return m_changesets.size(); |
62 } |
72 } |
63 |
73 |
64 inline History& operator<< (AbstractHistoryEntry* entry) |
74 inline History& operator<< (AbstractHistoryEntry* entry) |
65 { add (entry); |
75 { |
|
76 add (entry); |
66 return *this; |
77 return *this; |
67 } |
78 } |
68 |
79 |
69 inline const Changeset& changeset (long pos) const |
80 inline const Changeset& getChangeset (long pos) const |
70 { return m_changesets[pos]; |
81 { |
|
82 return m_changesets[pos]; |
71 } |
83 } |
72 |
84 |
73 private: |
85 private: |
74 Changeset m_currentArchive; |
86 Changeset m_currentChangeset; |
75 QList<Changeset> m_changesets; |
87 QList<Changeset> m_changesets; |
76 }; |
88 }; |
77 |
89 |
78 // ============================================================================= |
90 // ============================================================================= |
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
80 // ============================================================================= |
92 // ============================================================================= |
81 class AbstractHistoryEntry |
93 class AbstractHistoryEntry |
82 { PROPERTY (History*, parent, setParent) |
94 { |
|
95 PROPERTY (public, History*, Parent, NO_OPS, STOCK_WRITE) |
83 |
96 |
84 public: |
97 public: |
85 virtual void undo() const {} |
|
86 virtual void redo() const {} |
|
87 virtual ~AbstractHistoryEntry() {} |
98 virtual ~AbstractHistoryEntry() {} |
88 virtual History::Type getType() const |
99 virtual void undo() const = 0; |
89 { return (History::Type) 0; |
100 virtual void redo() const = 0; |
90 } |
101 virtual History::EHistoryType getType() const = 0; |
|
102 virtual QString getTypeName() const = 0; |
91 }; |
103 }; |
92 |
104 |
93 // ============================================================================= |
105 // ============================================================================= |
94 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
95 // ============================================================================= |
107 // ============================================================================= |
96 class DelHistory : public AbstractHistoryEntry |
108 class DelHistory : public AbstractHistoryEntry |
97 { public: |
109 { |
98 enum Type |
110 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
99 { Cut, // was deleted with a cut operation |
111 PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) |
100 Other, // was deleted witout specific reason |
|
101 }; |
|
102 |
|
103 PROPERTY (int, index, setIndex) |
|
104 PROPERTY (str, code, setCode) |
|
105 PROPERTY (DelHistory::Type, type, setType) |
|
106 |
112 |
107 public: |
113 public: |
108 IMPLEMENT_HISTORY_TYPE (Del) |
114 IMPLEMENT_HISTORY_TYPE (Del) |
109 |
115 DelHistory (int idx, LDObject* obj); |
110 DelHistory (int idx, LDObject* obj, Type type = Other) : |
|
111 m_index (idx), |
|
112 m_code (obj->raw()), |
|
113 m_type (type) {} |
|
114 }; |
116 }; |
115 |
117 |
116 // ============================================================================= |
118 // ============================================================================= |
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
118 // ============================================================================= |
120 // ============================================================================= |
119 class EditHistory : public AbstractHistoryEntry |
121 class EditHistory : public AbstractHistoryEntry |
120 { PROPERTY (int, index, setIndex) |
122 { |
121 PROPERTY (str, oldCode, setOldCode) |
123 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
122 PROPERTY (str, newCode, setNewCode) |
124 PROPERTY (private, QString, OldCode, NO_OPS, STOCK_WRITE) |
|
125 PROPERTY (private, QString, NewCode, NO_OPS, STOCK_WRITE) |
123 |
126 |
124 public: |
127 public: |
125 IMPLEMENT_HISTORY_TYPE (Edit) |
128 IMPLEMENT_HISTORY_TYPE (Edit) |
126 |
129 |
127 EditHistory (int idx, str oldCode, str newCode) : |
130 EditHistory (int idx, QString oldCode, QString newCode) : |
128 m_index (idx), |
131 m_Index (idx), |
129 m_oldCode (oldCode), |
132 m_OldCode (oldCode), |
130 m_newCode (newCode) {} |
133 m_NewCode (newCode) {} |
131 }; |
134 }; |
132 |
135 |
133 // ============================================================================= |
136 // ============================================================================= |
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
135 // ============================================================================= |
138 // ============================================================================= |
136 class AddHistory : public AbstractHistoryEntry |
139 class AddHistory : public AbstractHistoryEntry |
137 { public: |
140 { |
138 enum Type |
141 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
139 { Other, // was "just added" |
142 PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) |
140 Paste, // was added through a paste operation |
|
141 }; |
|
142 |
|
143 PROPERTY (int, index, setIndex) |
|
144 PROPERTY (str, code, setCode) |
|
145 PROPERTY (AddHistory::Type, type, setType) |
|
146 |
143 |
147 public: |
144 public: |
148 IMPLEMENT_HISTORY_TYPE (Add) |
145 IMPLEMENT_HISTORY_TYPE (Add) |
149 |
146 |
150 AddHistory (int idx, LDObject* obj, Type type = Other) : |
147 AddHistory (int idx, LDObject* obj) : |
151 m_index (idx), |
148 m_Index (idx), |
152 m_code (obj->raw()), |
149 m_Code (obj->raw()) {} |
153 m_type (type) {} |
|
154 }; |
150 }; |
155 |
151 |
156 // ============================================================================= |
152 // ============================================================================= |
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
158 // ============================================================================= |
154 // ============================================================================= |
159 class MoveHistory : public AbstractHistoryEntry |
155 class MoveHistory : public AbstractHistoryEntry |
160 { public: |
156 { |
|
157 public: |
161 IMPLEMENT_HISTORY_TYPE (Move) |
158 IMPLEMENT_HISTORY_TYPE (Move) |
162 |
159 |
163 QList<int> indices; |
160 QList<int> indices; |
164 vertex dest; |
161 Vertex dest; |
165 |
162 |
166 MoveHistory (QList<int> indices, vertex dest) : |
163 MoveHistory (QList<int> indices, Vertex dest) : |
167 indices (indices), |
164 indices (indices), |
168 dest (dest) {} |
165 dest (dest) {} |
169 }; |
166 }; |
170 |
167 |
|
168 // ============================================================================= |
|
169 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
|
170 // ============================================================================= |
171 class SwapHistory : public AbstractHistoryEntry |
171 class SwapHistory : public AbstractHistoryEntry |
172 { public: |
172 { |
|
173 public: |
173 IMPLEMENT_HISTORY_TYPE (Swap) |
174 IMPLEMENT_HISTORY_TYPE (Swap) |
174 int a, b; |
|
175 |
175 |
176 SwapHistory (int a, int b) : |
176 SwapHistory (int a, int b) : |
177 a (a), |
177 a (a), |
178 b (b) {} |
178 b (b) {} |
|
179 |
|
180 private: |
|
181 int a, b; |
179 }; |
182 }; |
180 |
183 |
181 #endif // HISTORY_H |
184 #endif // LDFORGE_HISTORY_H |