135 EditHistory* AbstractHistoryEntry::parent() const |
135 EditHistory* AbstractHistoryEntry::parent() const |
136 { |
136 { |
137 return m_parent; |
137 return m_parent; |
138 } |
138 } |
139 |
139 |
140 AddHistoryEntry::AddHistoryEntry(const QModelIndex& index, EditHistory* parent) : |
140 AddHistoryEntry::AddHistoryEntry(const Uuid& id, const int row, EditHistory* parent) : |
141 AbstractHistoryEntry {parent}, |
141 AbstractHistoryEntry {parent}, |
142 m_row {index.row()}, |
142 m_row {row}, |
143 m_code {Serializer::store(parent->document()->lookup(index))} {} |
143 m_code {Serializer::store(parent->document()->lookup(id))} {} |
144 |
144 |
145 void AddHistoryEntry::undo() |
145 void AddHistoryEntry::undo() |
146 { |
146 { |
147 LDObject* object = parent()->document()->getObject(m_row); |
147 LDObject* object = parent()->document()->getObject(m_row); |
148 parent()->document()->remove(object); |
148 parent()->document()->remove(object); |
162 { |
162 { |
163 AddHistoryEntry::undo(); |
163 AddHistoryEntry::undo(); |
164 } |
164 } |
165 |
165 |
166 EditHistoryEntry::EditHistoryEntry( |
166 EditHistoryEntry::EditHistoryEntry( |
167 const QModelIndex& index, |
167 const int row, |
168 const Serializer::Archive& oldState, |
168 const Serializer::Archive& oldState, |
169 const Serializer::Archive& newState, |
169 const Serializer::Archive& newState, |
170 EditHistory* parent |
170 EditHistory* parent |
171 ) : |
171 ) : |
172 AbstractHistoryEntry {parent}, |
172 AbstractHistoryEntry {parent}, |
173 row {index.row()}, |
173 row {row}, |
174 oldState {oldState}, |
174 oldState {oldState}, |
175 newState {newState} {} |
175 newState {newState} {} |
176 |
176 |
177 void EditHistoryEntry::undo() |
177 void EditHistoryEntry::undo() |
178 { |
178 { |
181 |
181 |
182 void EditHistoryEntry::redo() |
182 void EditHistoryEntry::redo() |
183 { |
183 { |
184 parent()->document()->setObjectAt(row, newState); |
184 parent()->document()->setObjectAt(row, newState); |
185 } |
185 } |
186 |
|
187 MoveHistoryEntry::MoveHistoryEntry(int top, int bottom, int destination, EditHistory* parent) : |
|
188 AbstractHistoryEntry {parent}, |
|
189 top {top}, |
|
190 bottom {bottom}, |
|
191 destination {destination} {} |
|
192 |
|
193 void MoveHistoryEntry::undo() |
|
194 { |
|
195 bool downwards = (destination < top); |
|
196 parent()->document()->moveRows( |
|
197 {}, |
|
198 downwards ? (destination) : (destination - (bottom - top) - 1), |
|
199 bottom - top + 1, |
|
200 {}, |
|
201 downwards ? (bottom + 1) : top |
|
202 ); |
|
203 } |
|
204 |
|
205 void MoveHistoryEntry::redo() |
|
206 { |
|
207 parent()->document()->moveRows( |
|
208 {}, |
|
209 top, |
|
210 bottom - top + 1, |
|
211 {}, |
|
212 destination |
|
213 ); |
|
214 } |
|