src/editHistory.cpp

changeset 1273
900f1dfae46b
parent 1272
bf0ac547b934
child 1318
568fcfc6da71
equal deleted inserted replaced
1272:bf0ac547b934 1273:900f1dfae46b
186 void EditHistoryEntry::redo() 186 void EditHistoryEntry::redo()
187 { 187 {
188 parent()->document()->setObjectAt(row, newState); 188 parent()->document()->setObjectAt(row, newState);
189 } 189 }
190 190
191 SwapHistoryEntry::SwapHistoryEntry (const QModelIndex& index_1, const QModelIndex& index_2, EditHistory* parent) : 191 MoveHistoryEntry::MoveHistoryEntry(int top, int bottom, int destination, EditHistory* parent) :
192 AbstractHistoryEntry {parent}, 192 AbstractHistoryEntry {parent},
193 row_1 (index_1.row()), 193 top {top},
194 row_2 (index_2.row()) {} 194 bottom {bottom},
195 195 destination {destination} {}
196 196
197 void SwapHistoryEntry::undo() 197 void MoveHistoryEntry::undo()
198 { 198 {
199 Model* model = parent()->document(); 199 bool downwards = (destination < top);
200 model->swapObjects(model->index(row_1), model->index(row_2)); 200 parent()->document()->moveRows(
201 } 201 {},
202 202 downwards ? (destination) : (destination - (bottom - top) - 1),
203 void SwapHistoryEntry::redo() 203 bottom - top + 1,
204 { 204 {},
205 undo(); 205 downwards ? (bottom + 1) : top
206 } 206 );
207 }
208
209 void MoveHistoryEntry::redo()
210 {
211 parent()->document()->moveRows(
212 {},
213 top,
214 bottom - top + 1,
215 {},
216 destination
217 );
218 }

mercurial