From 2622b7f602815fdb938c8d7e1ff565cf3c7325b5 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 26 Aug 2024 14:53:21 +0200 Subject: [PATCH] QListView/QTableView: attempt to move each row even after a failure Change-Id: I039917c9fa82d356291e75abc7233b3b220a1931 Reviewed-by: Richard Moe Gustavsen (cherry picked from commit bac5b6188fb18b0c41625d42809dd318abfc6c39) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/itemviews/qlistview.cpp | 7 ++++--- src/widgets/itemviews/qtableview.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index a7f1931947..c9481e892f 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -918,9 +918,10 @@ void QListView::dropEvent(QDropEvent *event) // only generate a move when not same row or behind itself if (r != pIndex.row() && r != pIndex.row() + 1) { // try to move (preserves selection) - dataMoved |= model()->moveRow(QModelIndex(), pIndex.row(), QModelIndex(), r); - if (!dataMoved) // can't move - abort and let QAbstractItemView handle this - break; + const bool moved = model()->moveRow(QModelIndex(), pIndex.row(), QModelIndex(), r); + if (!moved) + continue; // maybe it'll work for other rows + dataMoved = true; // success } else { // move onto itself is blocked, don't delete anything dataMoved = true; diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 977cb4e301..f0ac4a78fe 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -3155,9 +3155,10 @@ void QTableView::dropEvent(QDropEvent *event) // only generate a move when not same row or behind itself if (r != pIndex.row() && r != pIndex.row() + 1) { // try to move (preserves selection) - dataMoved |= model()->moveRow(QModelIndex(), pIndex.row(), QModelIndex(), r); - if (!dataMoved) // can't move - abort and let QAbstractItemView handle this - break; + const bool moved = model()->moveRow(QModelIndex(), pIndex.row(), QModelIndex(), r); + if (!moved) + continue; // maybe it'll work for other rows + dataMoved = true; // success } else { // move onto itself is blocked, don't delete anything dataMoved = true;