QListView/QTableView: attempt to move each row even after a failure

Change-Id: I039917c9fa82d356291e75abc7233b3b220a1931
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit bac5b6188fb18b0c41625d42809dd318abfc6c39)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
bb10
David Faure 2024-08-26 14:53:21 +02:00 committed by Qt Cherry-pick Bot
parent eb2a072f91
commit 2622b7f602
2 changed files with 8 additions and 6 deletions

View File

@ -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;

View File

@ -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;