20 #define LDFORGE_HISTORY_H |
20 #define LDFORGE_HISTORY_H |
21 |
21 |
22 #include "main.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 const char* getTypeName() const { return #N; } |
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 } |
31 |
39 |
32 class AbstractHistoryEntry; |
40 class AbstractHistoryEntry; |
33 |
41 |
34 // ============================================================================= |
42 // ============================================================================= |
35 class History |
43 class History |
36 { |
44 { |
37 PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) |
45 PROPERTY (private, int, Position, NUM_OPS, STOCK_WRITE) |
38 PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) |
46 PROPERTY (public, LDDocument*, Document, NO_OPS, STOCK_WRITE) |
39 PROPERTY (public, bool, Ignoring, BOOL_OPS, STOCK_WRITE) |
47 PROPERTY (public, bool, Ignoring, BOOL_OPS, STOCK_WRITE) |
40 |
48 |
41 public: |
49 public: |
42 typedef QList<AbstractHistoryEntry*> Changeset; |
50 typedef QList<AbstractHistoryEntry*> Changeset; |
43 |
51 |
44 enum Type |
52 enum EHistoryType |
45 { |
53 { |
46 Del, |
54 EDelHistory, |
47 Edit, |
55 EEditHistory, |
48 Add, |
56 EAddHistory, |
49 Move, |
57 EMoveHistory, |
50 Swap, |
58 ESwapHistory, |
51 }; |
59 }; |
52 |
60 |
53 History(); |
61 History(); |
54 void undo(); |
62 void undo(); |
55 void redo(); |
63 void redo(); |
86 { |
94 { |
87 PROPERTY (public, History*, Parent, NO_OPS, STOCK_WRITE) |
95 PROPERTY (public, History*, Parent, NO_OPS, STOCK_WRITE) |
88 |
96 |
89 public: |
97 public: |
90 virtual ~AbstractHistoryEntry() {} |
98 virtual ~AbstractHistoryEntry() {} |
91 virtual void undo() const {} |
99 virtual void undo() const = 0; |
92 virtual void redo() const {} |
100 virtual void redo() const = 0; |
93 |
101 virtual History::EHistoryType getType() const = 0; |
94 virtual History::Type getType() const |
102 virtual QString getTypeName() const = 0; |
95 { |
|
96 return (History::Type) 0; |
|
97 } |
|
98 |
|
99 virtual const char* getTypeName() const |
|
100 { |
|
101 return ""; |
|
102 } |
|
103 }; |
103 }; |
104 |
104 |
105 // ============================================================================= |
105 // ============================================================================= |
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
107 // ============================================================================= |
107 // ============================================================================= |
108 class DelHistory : public AbstractHistoryEntry |
108 class DelHistory : public AbstractHistoryEntry |
109 { |
109 { |
110 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
110 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
111 PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) |
111 PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) |
112 |
112 |
113 public: |
113 public: |
114 IMPLEMENT_HISTORY_TYPE (Del) |
114 IMPLEMENT_HISTORY_TYPE (Del) |
115 DelHistory (int idx, LDObject* obj); |
115 DelHistory (int idx, LDObject* obj); |
118 // ============================================================================= |
118 // ============================================================================= |
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
120 // ============================================================================= |
120 // ============================================================================= |
121 class EditHistory : public AbstractHistoryEntry |
121 class EditHistory : public AbstractHistoryEntry |
122 { |
122 { |
123 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
123 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
124 PROPERTY (private, QString, OldCode, NO_OPS, STOCK_WRITE) |
124 PROPERTY (private, QString, OldCode, NO_OPS, STOCK_WRITE) |
125 PROPERTY (private, QString, NewCode, NO_OPS, STOCK_WRITE) |
125 PROPERTY (private, QString, NewCode, NO_OPS, STOCK_WRITE) |
126 |
126 |
127 public: |
127 public: |
128 IMPLEMENT_HISTORY_TYPE (Edit) |
128 IMPLEMENT_HISTORY_TYPE (Edit) |
129 |
129 |
130 EditHistory (int idx, QString oldCode, QString newCode) : |
130 EditHistory (int idx, QString oldCode, QString newCode) : |
136 // ============================================================================= |
136 // ============================================================================= |
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
138 // ============================================================================= |
138 // ============================================================================= |
139 class AddHistory : public AbstractHistoryEntry |
139 class AddHistory : public AbstractHistoryEntry |
140 { |
140 { |
141 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
141 PROPERTY (private, int, Index, NO_OPS, STOCK_WRITE) |
142 PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) |
142 PROPERTY (private, QString, Code, NO_OPS, STOCK_WRITE) |
143 |
143 |
144 public: |
144 public: |
145 IMPLEMENT_HISTORY_TYPE (Add) |
145 IMPLEMENT_HISTORY_TYPE (Add) |
146 |
146 |