21 |
21 |
22 #include "common.h" |
22 #include "common.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 virtual History::Type getType() const override { return History::N; } |
30 |
30 |
31 class AbstractHistoryEntry; |
31 class AbstractHistoryEntry; |
32 |
32 |
33 // ============================================================================= |
33 // ============================================================================= |
34 class History |
34 class History |
35 { PROPERTY (long, pos, setPos) |
35 { PROPERTY (private, long, Position, NUM_OPS, NO_CB) |
36 PROPERTY (LDFile*, file, setFile) |
36 PROPERTY (public, LDFile*, File, NO_OPS, NO_CB) |
37 READ_PROPERTY (bool, opened, setOpened) |
37 PROPERTY (public, bool, Ignoring, BOOL_OPS, NO_CB) |
38 |
38 |
39 public: |
39 public: |
40 typedef QList<AbstractHistoryEntry*> Changeset; |
40 typedef QList<AbstractHistoryEntry*> Changeset; |
41 |
41 |
42 enum Type |
42 enum Type |
69 inline const Changeset& getChangeset (long pos) const |
68 inline const Changeset& getChangeset (long pos) const |
70 { return m_changesets[pos]; |
69 { return m_changesets[pos]; |
71 } |
70 } |
72 |
71 |
73 private: |
72 private: |
74 Changeset m_currentArchive; |
73 Changeset m_currentChangeset; |
75 QList<Changeset> m_changesets; |
74 QList<Changeset> m_changesets; |
76 }; |
75 }; |
77 |
76 |
78 // ============================================================================= |
77 // ============================================================================= |
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
78 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
80 // ============================================================================= |
79 // ============================================================================= |
81 class AbstractHistoryEntry |
80 class AbstractHistoryEntry |
82 { PROPERTY (History*, parent, setParent) |
81 { PROPERTY (public, History*, Parent, NO_OPS, NO_CB) |
83 |
82 |
84 public: |
83 public: |
|
84 virtual ~AbstractHistoryEntry() {} |
85 virtual void undo() const {} |
85 virtual void undo() const {} |
86 virtual void redo() const {} |
86 virtual void redo() const {} |
87 virtual ~AbstractHistoryEntry() {} |
|
88 virtual History::Type getType() const |
87 virtual History::Type getType() const |
89 { return (History::Type) 0; |
88 { return (History::Type) 0; |
90 } |
89 } |
91 }; |
90 }; |
92 |
91 |
93 // ============================================================================= |
92 // ============================================================================= |
94 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
95 // ============================================================================= |
94 // ============================================================================= |
96 class DelHistory : public AbstractHistoryEntry |
95 class DelHistory : public AbstractHistoryEntry |
97 { public: |
96 { PROPERTY (private, int, Index, NO_OPS, NO_CB) |
98 enum Type |
97 PROPERTY (private, str, Code, NO_OPS, NO_CB) |
99 { Cut, // was deleted with a cut operation |
|
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 |
98 |
107 public: |
99 public: |
108 IMPLEMENT_HISTORY_TYPE (Del) |
100 IMPLEMENT_HISTORY_TYPE (Del) |
109 |
101 |
110 DelHistory (int idx, LDObject* obj, Type type = Other) : |
102 DelHistory (int idx, LDObject* obj) : |
111 m_index (idx), |
103 m_Index (idx), |
112 m_code (obj->raw()), |
104 m_Code (obj->raw()) {} |
113 m_type (type) {} |
|
114 }; |
105 }; |
115 |
106 |
116 // ============================================================================= |
107 // ============================================================================= |
117 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
108 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
118 // ============================================================================= |
109 // ============================================================================= |
119 class EditHistory : public AbstractHistoryEntry |
110 class EditHistory : public AbstractHistoryEntry |
120 { PROPERTY (int, index, setIndex) |
111 { PROPERTY (private, int, Index, NO_OPS, NO_CB) |
121 PROPERTY (str, oldCode, setOldCode) |
112 PROPERTY (private, str, OldCode, NO_OPS, NO_CB) |
122 PROPERTY (str, newCode, setNewCode) |
113 PROPERTY (private, str, NewCode, NO_OPS, NO_CB) |
123 |
114 |
124 public: |
115 public: |
125 IMPLEMENT_HISTORY_TYPE (Edit) |
116 IMPLEMENT_HISTORY_TYPE (Edit) |
126 |
117 |
127 EditHistory (int idx, str oldCode, str newCode) : |
118 EditHistory (int idx, str oldCode, str newCode) : |
128 m_index (idx), |
119 m_Index (idx), |
129 m_oldCode (oldCode), |
120 m_OldCode (oldCode), |
130 m_newCode (newCode) {} |
121 m_NewCode (newCode) {} |
131 }; |
122 }; |
132 |
123 |
133 // ============================================================================= |
124 // ============================================================================= |
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
135 // ============================================================================= |
126 // ============================================================================= |
136 class AddHistory : public AbstractHistoryEntry |
127 class AddHistory : public AbstractHistoryEntry |
137 { public: |
128 { PROPERTY (private, int, Index, NO_OPS, NO_CB) |
138 enum Type |
129 PROPERTY (private, str, Code, NO_OPS, NO_CB) |
139 { Other, // was "just added" |
|
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 |
130 |
147 public: |
131 public: |
148 IMPLEMENT_HISTORY_TYPE (Add) |
132 IMPLEMENT_HISTORY_TYPE (Add) |
149 |
133 |
150 AddHistory (int idx, LDObject* obj, Type type = Other) : |
134 AddHistory (int idx, LDObject* obj) : |
151 m_index (idx), |
135 m_Index (idx), |
152 m_code (obj->raw()), |
136 m_Code (obj->raw()) {} |
153 m_type (type) {} |
|
154 }; |
137 }; |
155 |
138 |
156 // ============================================================================= |
139 // ============================================================================= |
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
140 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
158 // ============================================================================= |
141 // ============================================================================= |