42 { |
42 { |
43 PROPERTY (private, int, position, setPosition, STOCK_WRITE) |
43 PROPERTY (private, int, position, setPosition, STOCK_WRITE) |
44 PROPERTY (public, LDDocumentWeakPtr, document, setDocument, STOCK_WRITE) |
44 PROPERTY (public, LDDocumentWeakPtr, document, setDocument, STOCK_WRITE) |
45 PROPERTY (public, bool, isIgnoring, setIgnoring, STOCK_WRITE) |
45 PROPERTY (public, bool, isIgnoring, setIgnoring, STOCK_WRITE) |
46 |
46 |
47 public: |
47 public: |
48 typedef QList<AbstractHistoryEntry*> Changeset; |
48 typedef QList<AbstractHistoryEntry*> Changeset; |
49 |
49 |
50 enum EHistoryType |
50 enum EHistoryType |
51 { |
51 { |
52 EDelHistory, |
52 EDelHistory, |
53 EEditHistory, |
53 EEditHistory, |
54 EAddHistory, |
54 EAddHistory, |
55 EMoveHistory, |
55 EMoveHistory, |
56 ESwapHistory, |
56 ESwapHistory, |
57 }; |
57 }; |
58 |
58 |
59 History(); |
59 History(); |
60 void undo(); |
60 void undo(); |
61 void redo(); |
61 void redo(); |
62 void clear(); |
62 void clear(); |
63 |
63 |
64 void addStep(); |
64 void addStep(); |
65 void add (AbstractHistoryEntry* entry); |
65 void add (AbstractHistoryEntry* entry); |
66 |
66 |
67 inline long getSize() const |
67 inline long getSize() const |
68 { |
68 { |
69 return m_changesets.size(); |
69 return m_changesets.size(); |
70 } |
70 } |
71 |
71 |
72 inline History& operator<< (AbstractHistoryEntry* entry) |
72 inline History& operator<< (AbstractHistoryEntry* entry) |
73 { |
73 { |
74 add (entry); |
74 add (entry); |
75 return *this; |
75 return *this; |
76 } |
76 } |
77 |
77 |
78 inline const Changeset& getChangeset (long pos) const |
78 inline const Changeset& getChangeset (long pos) const |
79 { |
79 { |
80 return m_changesets[pos]; |
80 return m_changesets[pos]; |
81 } |
81 } |
82 |
82 |
83 private: |
83 private: |
84 Changeset m_currentChangeset; |
84 Changeset m_currentChangeset; |
85 QList<Changeset> m_changesets; |
85 QList<Changeset> m_changesets; |
86 }; |
86 }; |
87 |
87 |
88 // ============================================================================= |
88 // ============================================================================= |
89 // |
89 // |
90 class AbstractHistoryEntry |
90 class AbstractHistoryEntry |
91 { |
91 { |
92 PROPERTY (public, History*, parent, setParent, STOCK_WRITE) |
92 PROPERTY (public, History*, parent, setParent, STOCK_WRITE) |
93 |
93 |
94 public: |
94 public: |
95 virtual ~AbstractHistoryEntry() {} |
95 virtual ~AbstractHistoryEntry() {} |
96 virtual void undo() const = 0; |
96 virtual void undo() const = 0; |
97 virtual void redo() const = 0; |
97 virtual void redo() const = 0; |
98 virtual History::EHistoryType getType() const = 0; |
98 virtual History::EHistoryType getType() const = 0; |
99 virtual QString getTypeName() const = 0; |
99 virtual QString getTypeName() const = 0; |
100 }; |
100 }; |
101 |
101 |
102 // ============================================================================= |
102 // ============================================================================= |
103 // |
103 // |
104 class DelHistory : public AbstractHistoryEntry |
104 class DelHistory : public AbstractHistoryEntry |
105 { |
105 { |
106 PROPERTY (private, int, index, setIndex, STOCK_WRITE) |
106 PROPERTY (private, int, index, setIndex, STOCK_WRITE) |
107 PROPERTY (private, QString, code, setCode, STOCK_WRITE) |
107 PROPERTY (private, QString, code, setCode, STOCK_WRITE) |
108 |
108 |
109 public: |
109 public: |
110 IMPLEMENT_HISTORY_TYPE (Del) |
110 IMPLEMENT_HISTORY_TYPE (Del) |
111 DelHistory (int idx, LDObjectPtr obj); |
111 DelHistory (int idx, LDObjectPtr obj); |
112 }; |
112 }; |
113 |
113 |
114 // ============================================================================= |
114 // ============================================================================= |
115 // |
115 // |
116 class EditHistory : public AbstractHistoryEntry |
116 class EditHistory : public AbstractHistoryEntry |
117 { |
117 { |
118 PROPERTY (private, int, index, setIndex, STOCK_WRITE) |
118 PROPERTY (private, int, index, setIndex, STOCK_WRITE) |
119 PROPERTY (private, QString, oldCode, setOldCode, STOCK_WRITE) |
119 PROPERTY (private, QString, oldCode, setOldCode, STOCK_WRITE) |
120 PROPERTY (private, QString, newCode, setNewCode, STOCK_WRITE) |
120 PROPERTY (private, QString, newCode, setNewCode, STOCK_WRITE) |
121 |
121 |
122 public: |
122 public: |
123 IMPLEMENT_HISTORY_TYPE (Edit) |
123 IMPLEMENT_HISTORY_TYPE (Edit) |
124 |
124 |
125 EditHistory (int idx, QString oldCode, QString newCode) : |
125 EditHistory (int idx, QString oldCode, QString newCode) : |
126 m_index (idx), |
126 m_index (idx), |
127 m_oldCode (oldCode), |
127 m_oldCode (oldCode), |
128 m_newCode (newCode) {} |
128 m_newCode (newCode) {} |
129 }; |
129 }; |
130 |
130 |
131 // ============================================================================= |
131 // ============================================================================= |
132 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
132 // |
133 // ============================================================================= |
|
134 class AddHistory : public AbstractHistoryEntry |
133 class AddHistory : public AbstractHistoryEntry |
135 { |
134 { |
136 PROPERTY (private, int, index, setIndex, STOCK_WRITE) |
135 PROPERTY (private, int, index, setIndex, STOCK_WRITE) |
137 PROPERTY (private, QString, code, setCode, STOCK_WRITE) |
136 PROPERTY (private, QString, code, setCode, STOCK_WRITE) |
138 |
137 |
139 public: |
138 public: |
140 IMPLEMENT_HISTORY_TYPE (Add) |
139 IMPLEMENT_HISTORY_TYPE (Add) |
141 |
140 |
142 AddHistory (int idx, LDObjectPtr obj) : |
141 AddHistory (int idx, LDObjectPtr obj) : |
143 m_index (idx), |
142 m_index (idx), |
144 m_code (obj->asText()) {} |
143 m_code (obj->asText()) {} |
145 }; |
144 }; |
146 |
145 |
147 // ============================================================================= |
146 // ============================================================================= |
148 // |
147 // |
149 class MoveHistory : public AbstractHistoryEntry |
148 class MoveHistory : public AbstractHistoryEntry |
150 { |
149 { |
151 public: |
150 public: |
152 IMPLEMENT_HISTORY_TYPE (Move) |
151 IMPLEMENT_HISTORY_TYPE (Move) |
153 |
152 |
154 QList<int> indices; |
153 QList<int> indices; |
155 Vertex dest; |
154 Vertex dest; |
156 |
155 |
157 MoveHistory (QList<int> indices, Vertex dest) : |
156 MoveHistory (QList<int> indices, Vertex dest) : |
158 indices (indices), |
157 indices (indices), |
159 dest (dest) {} |
158 dest (dest) {} |
160 }; |
159 }; |
161 |
160 |
162 // ============================================================================= |
161 // ============================================================================= |
163 // |
162 // |
164 class SwapHistory : public AbstractHistoryEntry |
163 class SwapHistory : public AbstractHistoryEntry |
165 { |
164 { |
166 public: |
165 public: |
167 IMPLEMENT_HISTORY_TYPE (Swap) |
166 IMPLEMENT_HISTORY_TYPE (Swap) |
168 |
167 |
169 SwapHistory (int a, int b) : |
168 SwapHistory (int a, int b) : |
170 a (a), |
169 a (a), |
171 b (b) {} |
170 b (b) {} |
172 |
171 |
173 private: |
172 private: |
174 int a, b; |
173 int a, b; |
175 }; |
174 }; |