Make the supportedDragActions a virtual accessor.

Change-Id: I4001fcabc67e5b46465b3c9111c33247c52e5788
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Stephen Kelly 2012-01-06 08:02:19 +01:00 committed by Qt by Nokia
parent c95aea407b
commit 20abd88e71
3 changed files with 35 additions and 11 deletions

View File

@ -1831,25 +1831,29 @@ Qt::DropActions QAbstractItemModel::supportedDropActions() const
*/ */
Qt::DropActions QAbstractItemModel::supportedDragActions() const Qt::DropActions QAbstractItemModel::supportedDragActions() const
{ {
// ### Qt 5: make this virtual or these properties
Q_D(const QAbstractItemModel); Q_D(const QAbstractItemModel);
if (d->supportedDragActions != -1) if (d->supportedDragActions != -1)
return d->supportedDragActions; return d->supportedDragActions;
return supportedDropActions(); return supportedDropActions();
} }
/*!
\internal
*/
void QAbstractItemModel::doSetSupportedDragActions(Qt::DropActions actions)
{
Q_D(QAbstractItemModel);
d->supportedDragActions = actions;
}
/*! /*!
\since 4.2 \since 4.2
\obsolete
Sets the supported drag \a actions for the items in the model. Sets the supported drag \a actions for the items in the model.
\sa supportedDragActions(), {Using drag and drop with item views} \sa supportedDragActions(), {Using drag and drop with item views}
*/ */
void QAbstractItemModel::setSupportedDragActions(Qt::DropActions actions)
{
Q_D(QAbstractItemModel);
d->supportedDragActions = actions;
}
/*! /*!
\note The base class implementation of this function does nothing and \note The base class implementation of this function does nothing and

View File

@ -198,8 +198,13 @@ public:
int row, int column, const QModelIndex &parent); int row, int column, const QModelIndex &parent);
virtual Qt::DropActions supportedDropActions() const; virtual Qt::DropActions supportedDropActions() const;
Qt::DropActions supportedDragActions() const; virtual Qt::DropActions supportedDragActions() const;
void setSupportedDragActions(Qt::DropActions); #if QT_DEPRECATED_SINCE(5, 0)
void setSupportedDragActions(Qt::DropActions actions)
{
doSetSupportedDragActions(actions);
}
#endif
virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()); virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()); virtual bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
@ -311,6 +316,7 @@ protected:
private: private:
void doSetRoleNames(const QHash<int,QByteArray> &roleNames); void doSetRoleNames(const QHash<int,QByteArray> &roleNames);
void doSetSupportedDragActions(Qt::DropActions actions);
Q_DECLARE_PRIVATE(QAbstractItemModel) Q_DECLARE_PRIVATE(QAbstractItemModel)
Q_DISABLE_COPY(QAbstractItemModel) Q_DISABLE_COPY(QAbstractItemModel)

View File

@ -113,6 +113,7 @@ private slots:
void testChildrenLayoutsChanged(); void testChildrenLayoutsChanged();
void testRoleNames(); void testRoleNames();
void testDragActions();
private: private:
DynamicTreeModel *m_model; DynamicTreeModel *m_model;
@ -1978,11 +1979,11 @@ void tst_QAbstractItemModel::testChildrenLayoutsChanged()
} }
} }
class OverrideRoleNames : public QStringListModel class OverrideRoleNamesAndDragActions : public QStringListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
OverrideRoleNames(QObject *parent = 0) OverrideRoleNamesAndDragActions(QObject *parent = 0)
: QStringListModel(parent) : QStringListModel(parent)
{ {
@ -1994,15 +1995,28 @@ public:
roles.insert(Qt::UserRole + 2, "custom"); roles.insert(Qt::UserRole + 2, "custom");
return roles; return roles;
} }
Qt::DropActions supportedDragActions() const
{
return QStringListModel::supportedDragActions() | Qt::MoveAction;
}
}; };
void tst_QAbstractItemModel::testRoleNames() void tst_QAbstractItemModel::testRoleNames()
{ {
QAbstractItemModel *model = new OverrideRoleNames(this); QAbstractItemModel *model = new OverrideRoleNamesAndDragActions(this);
QHash<int, QByteArray> roles = model->roleNames(); QHash<int, QByteArray> roles = model->roleNames();
QVERIFY(roles.contains(Qt::UserRole + 2)); QVERIFY(roles.contains(Qt::UserRole + 2));
QVERIFY(roles.value(Qt::UserRole + 2) == "custom"); QVERIFY(roles.value(Qt::UserRole + 2) == "custom");
} }
void tst_QAbstractItemModel::testDragActions()
{
QAbstractItemModel *model = new OverrideRoleNamesAndDragActions(this);
const Qt::DropActions actions = model->supportedDragActions();
QVERIFY(actions & Qt::CopyAction); // Present by default
QVERIFY(actions & Qt::MoveAction);
}
QTEST_MAIN(tst_QAbstractItemModel) QTEST_MAIN(tst_QAbstractItemModel)
#include "tst_qabstractitemmodel.moc" #include "tst_qabstractitemmodel.moc"