summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2020-12-08 21:27:40 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-19 11:35:35 +0000
commit93e4f88204e604d9196c99c297b081e3f61b7a1c (patch)
treedbce2b6691458eadc4a9063667adb7f6e9548db4 /src/widgets/itemviews
parentc855608119cba04cb116af6e5f68759dd888e1a6 (diff)
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 Change-Id: I69de4b8d76d1b0f57338b402aee87580226cd6cb Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 12d8bb0709bf7982061cb0c3e608e4a581892e35) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp6
-rw-r--r--src/widgets/itemviews/qlistview.cpp6
2 files changed, 8 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index 19824911fa..2b8ee4f29c 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -3702,8 +3702,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();
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 7e472d37c2..ce7b98d780 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -2901,8 +2901,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;