ItemViews: Don't remove items on internal move

When an itemview only allows internal moving of items it can happen that
the target accepts the drag'n'drop operation since it's out of the
control of Qt (e.g. Recycle Bin or an other application). Due to the
nature of a move, the original item is deleted. Therefore check if the
internal move target is the same as the source and don't delete it
otherwse.

Fixes: QTBUG-86020
Pick-to: 6.0
Change-Id: I69de4b8d76d1b0f57338b402aee87580226cd6cb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2020-12-08 21:27:40 +01:00
parent 6ee13db700
commit 12d8bb0709
2 changed files with 8 additions and 4 deletions

View File

@ -3701,8 +3701,10 @@ void QAbstractItemView::startDrag(Qt::DropActions supportedActions)
else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove)
defaultDropAction = Qt::CopyAction;
d->dropEventMoved = false;
if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction && !d->dropEventMoved)
d->clearOrRemove();
if (drag->exec(supportedActions, defaultDropAction) == Qt::MoveAction && !d->dropEventMoved) {
if (dragDropMode() != InternalMove || drag->target() == viewport())
d->clearOrRemove();
}
d->dropEventMoved = false;
// Reset the drop indicator
d->dropIndicatorRect = QRect();

View File

@ -2898,8 +2898,10 @@ bool QIconModeViewBase::filterStartDrag(Qt::DropActions supportedActions)
Qt::DropAction action = drag->exec(supportedActions, dd->defaultDropAction);
draggedItems.clear();
// delete item, unless it has already been moved internally (see filterDropEvent)
if (action == Qt::MoveAction && !dd->dropEventMoved)
dd->clearOrRemove();
if (action == Qt::MoveAction && !dd->dropEventMoved) {
if (dd->dragDropMode != QAbstractItemView::InternalMove || drag->target() == qq->viewport())
dd->clearOrRemove();
}
dd->dropEventMoved = false;
}
return true;