From cb7d397e3dbc769f8332a03858b28eddc7519279 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 30 Nov 2015 13:57:14 +0100 Subject: [PATCH] Simplify QAbstractItemViewPrivate::canDrop() Scope some variables better and drag a constant expression out of the loop, at the expense of executing it unconditionally. That should not be a problem, as all operands of the expression are calls to const member functions. Change-Id: Ibcf54b2e2faf9a818df7d12c0790c1f173c8a8ca Reviewed-by: Friedemann Kleint --- src/widgets/itemviews/qabstractitemview_p.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/widgets/itemviews/qabstractitemview_p.h b/src/widgets/itemviews/qabstractitemview_p.h index bb88b25652..861a0f9ff1 100644 --- a/src/widgets/itemviews/qabstractitemview_p.h +++ b/src/widgets/itemviews/qabstractitemview_p.h @@ -165,21 +165,20 @@ public: virtual QAbstractItemView::DropIndicatorPosition position(const QPoint &pos, const QRect &rect, const QModelIndex &idx) const; inline bool canDrop(QDropEvent *event) { - QModelIndex index; - int col = -1; - int row = -1; const QMimeData *mime = event->mimeData(); // Drag enter event shall always be accepted, if mime type and action match. // Whether the data can actually be dropped will be checked in drag move. - if (event->type() == QEvent::DragEnter) { + if (event->type() == QEvent::DragEnter && (event->dropAction() & model->supportedDropActions())) { const QStringList modelTypes = model->mimeTypes(); for (int i = 0; i < modelTypes.count(); ++i) - if (mime->hasFormat(modelTypes.at(i)) - && (event->dropAction() & model->supportedDropActions())) + if (mime->hasFormat(modelTypes.at(i))) return true; } + QModelIndex index; + int col = -1; + int row = -1; if (dropOn(event, &row, &col, &index)) { return model->canDropMimeData(mime, dragDropMode == QAbstractItemView::InternalMove ? Qt::MoveAction : event->dropAction(),