From be9398c8d4ab0b7eba74b607d82dc43cd40443b8 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 2 Dec 2019 21:07:44 +0100 Subject: QListModel: fix moveRows() QListModel::moveRows() had an issue when the destination was before the source row. Change-Id: I4ce8b425451f2f53c7eb3b211e9590753dec618a Reviewed-by: Luca Beldi Reviewed-by: David Faure --- src/widgets/itemviews/qlistwidget.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/widgets/itemviews/qlistwidget.cpp') diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index f71e0f2822..c9379f9a8a 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -301,16 +301,23 @@ bool QListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co { if (sourceRow < 0 || sourceRow + count - 1 >= rowCount(sourceParent) - || destinationChild <= 0 + || destinationChild < 0 || destinationChild > rowCount(destinationParent) + || sourceRow == destinationChild || sourceRow == destinationChild - 1 - || count <= 0) { + || count <= 0 + || sourceParent.isValid() + || destinationParent.isValid()) { return false; } if (!beginMoveRows(QModelIndex(), sourceRow, sourceRow + count - 1, QModelIndex(), destinationChild)) return false; - destinationChild--; - const int fromRow = destinationChild < sourceRow ? (sourceRow + count - 1) : sourceRow; + + int fromRow = sourceRow; + if (destinationChild < sourceRow) + fromRow += count - 1; + else + destinationChild--; while (count--) items.move(fromRow, destinationChild); endMoveRows(); -- cgit v1.2.3