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:
parent
c95aea407b
commit
20abd88e71
@ -1831,25 +1831,29 @@ Qt::DropActions QAbstractItemModel::supportedDropActions() const
|
||||
*/
|
||||
Qt::DropActions QAbstractItemModel::supportedDragActions() const
|
||||
{
|
||||
// ### Qt 5: make this virtual or these properties
|
||||
Q_D(const QAbstractItemModel);
|
||||
if (d->supportedDragActions != -1)
|
||||
return d->supportedDragActions;
|
||||
return supportedDropActions();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
void QAbstractItemModel::doSetSupportedDragActions(Qt::DropActions actions)
|
||||
{
|
||||
Q_D(QAbstractItemModel);
|
||||
d->supportedDragActions = actions;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 4.2
|
||||
\obsolete
|
||||
|
||||
Sets the supported drag \a actions for the items in the model.
|
||||
|
||||
\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
|
||||
|
@ -198,8 +198,13 @@ public:
|
||||
int row, int column, const QModelIndex &parent);
|
||||
virtual Qt::DropActions supportedDropActions() const;
|
||||
|
||||
Qt::DropActions supportedDragActions() const;
|
||||
void setSupportedDragActions(Qt::DropActions);
|
||||
virtual Qt::DropActions supportedDragActions() const;
|
||||
#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 insertColumns(int column, int count, const QModelIndex &parent = QModelIndex());
|
||||
@ -311,6 +316,7 @@ protected:
|
||||
|
||||
private:
|
||||
void doSetRoleNames(const QHash<int,QByteArray> &roleNames);
|
||||
void doSetSupportedDragActions(Qt::DropActions actions);
|
||||
|
||||
Q_DECLARE_PRIVATE(QAbstractItemModel)
|
||||
Q_DISABLE_COPY(QAbstractItemModel)
|
||||
|
@ -113,6 +113,7 @@ private slots:
|
||||
void testChildrenLayoutsChanged();
|
||||
|
||||
void testRoleNames();
|
||||
void testDragActions();
|
||||
|
||||
private:
|
||||
DynamicTreeModel *m_model;
|
||||
@ -1978,11 +1979,11 @@ void tst_QAbstractItemModel::testChildrenLayoutsChanged()
|
||||
}
|
||||
}
|
||||
|
||||
class OverrideRoleNames : public QStringListModel
|
||||
class OverrideRoleNamesAndDragActions : public QStringListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
OverrideRoleNames(QObject *parent = 0)
|
||||
OverrideRoleNamesAndDragActions(QObject *parent = 0)
|
||||
: QStringListModel(parent)
|
||||
{
|
||||
|
||||
@ -1994,15 +1995,28 @@ public:
|
||||
roles.insert(Qt::UserRole + 2, "custom");
|
||||
return roles;
|
||||
}
|
||||
|
||||
Qt::DropActions supportedDragActions() const
|
||||
{
|
||||
return QStringListModel::supportedDragActions() | Qt::MoveAction;
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QAbstractItemModel::testRoleNames()
|
||||
{
|
||||
QAbstractItemModel *model = new OverrideRoleNames(this);
|
||||
QAbstractItemModel *model = new OverrideRoleNamesAndDragActions(this);
|
||||
QHash<int, QByteArray> roles = model->roleNames();
|
||||
QVERIFY(roles.contains(Qt::UserRole + 2));
|
||||
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)
|
||||
#include "tst_qabstractitemmodel.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user