diff options
author | David Faure <david.faure@kdab.com> | 2014-11-21 10:46:22 +0100 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2014-11-24 08:05:51 +0100 |
commit | b13aa15e1007a1b5ed61049bbd9ef8f95b6d12a5 (patch) | |
tree | e202817bf80517ce9efd178d6642acf12cac05ee /src/widgets/doc/snippets/qlistview-dnd/model.cpp | |
parent | 736ac191565196514e14f875c774771026f95d7e (diff) |
QAbstractItemView: call canDropMimeData, as one would expect.
The virtual method was added for 5.0 but never called.
The old code (only checking mimetypes) is now the default implementation
for canDropMimeData. Model subclasses can now refine this by having
index-specific logic instead, or in order to inspect the dropped data
(e.g. to accept files and refuse directories, which are all text/uri-list).
[ChangeLog][QtWidgets][QAbstractItemView] now calls canDropMimeData in
order to decide whether or not to accept the drop.
Task-number: QTBUG-30534
Change-Id: Ied3aa964b4025bae6a1a26df89a681bfe61c3faa
Reviewed-by: Stephen Kelly <steveire@gmail.com>
Diffstat (limited to 'src/widgets/doc/snippets/qlistview-dnd/model.cpp')
-rw-r--r-- | src/widgets/doc/snippets/qlistview-dnd/model.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/widgets/doc/snippets/qlistview-dnd/model.cpp b/src/widgets/doc/snippets/qlistview-dnd/model.cpp index 6ebeb2eb56..aa12cef3a2 100644 --- a/src/widgets/doc/snippets/qlistview-dnd/model.cpp +++ b/src/widgets/doc/snippets/qlistview-dnd/model.cpp @@ -65,18 +65,31 @@ DragDropListModel::DragDropListModel(const QStringList &strings, } //! [0] -bool DragDropListModel::dropMimeData(const QMimeData *data, +bool DragDropListModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { - if (action == Qt::IgnoreAction) - return true; + Q_UNUSED(action); + Q_UNUSED(row); + Q_UNUSED(parent); if (!data->hasFormat("application/vnd.text.list")) return false; if (column > 0) -//! [0] //! [1] return false; + + return true; +} +//! [0] +//! [1] +bool DragDropListModel::dropMimeData(const QMimeData *data, + Qt::DropAction action, int row, int column, const QModelIndex &parent) +{ + if (!canDropMimeData(data, action, row, column, parent)) + return false; + + if (action == Qt::IgnoreAction) + return true; //! [1] //! [2] |