From b13aa15e1007a1b5ed61049bbd9ef8f95b6d12a5 Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 21 Nov 2014 10:46:22 +0100 Subject: 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 --- src/corelib/itemmodels/qabstractitemmodel.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/corelib/itemmodels') diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index b15d255e66..a9cfa3e7ca 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -1842,7 +1842,9 @@ QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const /*! Returns \c{true} if a model can accept a drop of the \a data. This - default implementation always returns \c{true}. + default implementation only checks if \a data has at least one format + in the list of mimeTypes() and if \a action is among the + model's supportedDropActions(). Reimplement this function in your custom model, if you want to test whether the \a data can be dropped at \a row, \a column, @@ -1855,12 +1857,19 @@ bool QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction a int row, int column, const QModelIndex &parent) const { - Q_UNUSED(data) - Q_UNUSED(action) Q_UNUSED(row) Q_UNUSED(column) Q_UNUSED(parent) - return true; + + if (!(action & supportedDropActions())) + return false; + + const QStringList modelTypes = mimeTypes(); + for (int i = 0; i < modelTypes.count(); ++i) { + if (data->hasFormat(modelTypes.at(i))) + return true; + } + return false; } /*! -- cgit v1.2.3