QAbstractItemModel::supportedDragActions: fix regression

This method now returns -1 by default, due to commit 6255cb893d
which mistakenly replaced -1 with Qt::IgnoreAction (0x0).

As a result, dropping is forbidden in a number of applications
(I detected this in zanshin).

Change-Id: I4922451216e08d5d3fe36f8ba87364a361b691bf
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
bb10
David Faure 2017-05-28 10:49:21 +02:00 committed by Liang Qi
parent 32a94e54b5
commit f33cf18d88
4 changed files with 40 additions and 1 deletions

View File

@ -2044,7 +2044,7 @@ Qt::DropActions QAbstractItemModel::supportedDropActions() const
Qt::DropActions QAbstractItemModel::supportedDragActions() const
{
Q_D(const QAbstractItemModel);
if (d->supportedDragActions != Qt::IgnoreAction)
if (int(d->supportedDragActions) != -1)
return d->supportedDragActions;
return supportedDropActions();
}

View File

@ -101,6 +101,7 @@ private slots:
void testRoleNames();
void testDragActions();
void dragActionsFallsBackToDropActions();
void testFunctionPointerSignalConnection();
@ -2157,6 +2158,27 @@ void tst_QAbstractItemModel::testDragActions()
QVERIFY(actions & Qt::MoveAction);
}
class OverrideDropActions : public QStringListModel
{
Q_OBJECT
public:
OverrideDropActions(QObject *parent = 0)
: QStringListModel(parent)
{
}
Qt::DropActions supportedDropActions() const override
{
return Qt::MoveAction;
}
};
void tst_QAbstractItemModel::dragActionsFallsBackToDropActions()
{
QAbstractItemModel *model = new OverrideDropActions(this);
QCOMPARE(model->supportedDragActions(), Qt::MoveAction);
QCOMPARE(model->supportedDropActions(), Qt::MoveAction);
}
class SignalConnectionTester : public QObject
{
Q_OBJECT

View File

@ -80,6 +80,8 @@ private slots:
void setData_emits_both_roles_data();
void setData_emits_both_roles();
void supportedDragDropActions();
};
void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved_data()
@ -250,5 +252,12 @@ void tst_QStringListModel::setData_emits_both_roles()
expected);
}
void tst_QStringListModel::supportedDragDropActions()
{
QStringListModel model;
QCOMPARE(model.supportedDragActions(), Qt::CopyAction | Qt::MoveAction);
QCOMPARE(model.supportedDropActions(), Qt::CopyAction | Qt::MoveAction);
}
QTEST_MAIN(tst_QStringListModel)
#include "tst_qstringlistmodel.moc"

View File

@ -125,6 +125,7 @@ private slots:
void itemRoleNames();
void getMimeDataWithInvalidModelIndex();
void supportedDragDropActions();
private:
QAbstractItemModel *m_model;
@ -1666,5 +1667,12 @@ void tst_QStandardItemModel::getMimeDataWithInvalidModelIndex()
QVERIFY(!data);
}
void tst_QStandardItemModel::supportedDragDropActions()
{
QStandardItemModel model;
QCOMPARE(model.supportedDragActions(), Qt::CopyAction | Qt::MoveAction);
QCOMPARE(model.supportedDropActions(), Qt::CopyAction | Qt::MoveAction);
}
QTEST_MAIN(tst_QStandardItemModel)
#include "tst_qstandarditemmodel.moc"