src/editHistory.cpp

changeset 1273
900f1dfae46b
parent 1272
bf0ac547b934
child 1318
568fcfc6da71
--- a/src/editHistory.cpp	Mon Mar 05 23:59:47 2018 +0200
+++ b/src/editHistory.cpp	Tue Mar 06 23:29:40 2018 +0200
@@ -188,19 +188,31 @@
 	parent()->document()->setObjectAt(row, newState);
 }
 
-SwapHistoryEntry::SwapHistoryEntry (const QModelIndex& index_1, const QModelIndex& index_2, EditHistory* parent) :
+MoveHistoryEntry::MoveHistoryEntry(int top, int bottom, int destination, EditHistory* parent) :
 	AbstractHistoryEntry {parent},
-	row_1 (index_1.row()),
-	row_2 (index_2.row()) {}
+	top {top},
+	bottom {bottom},
+	destination {destination} {}
 
-
-void SwapHistoryEntry::undo()
+void MoveHistoryEntry::undo()
 {
-	Model* model = parent()->document();
-	model->swapObjects(model->index(row_1), model->index(row_2));
+	bool downwards = (destination < top);
+	parent()->document()->moveRows(
+		{},
+		downwards ? (destination) : (destination - (bottom - top) - 1),
+		bottom - top + 1,
+		{},
+		downwards ? (bottom + 1) : top
+	);
 }
 
-void SwapHistoryEntry::redo()
+void MoveHistoryEntry::redo()
 {
-	undo();
+	parent()->document()->moveRows(
+		{},
+		top,
+		bottom - top + 1,
+		{},
+		destination
+	);
 }

mercurial