Make the supportedDragActions a virtual accessor.
authorStephen Kelly <stephen.kelly@kdab.com>
Fri, 6 Jan 2012 07:02:19 +0000 (08:02 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 10 Jan 2012 15:11:43 +0000 (16:11 +0100)
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>
src/corelib/itemmodels/qabstractitemmodel.cpp
src/corelib/itemmodels/qabstractitemmodel.h
tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp

index 7e6c8ba..dec1fe4 100644 (file)
@@ -1831,7 +1831,6 @@ 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;
@@ -1839,17 +1838,22 @@ Qt::DropActions QAbstractItemModel::supportedDragActions() const
 }
 
 /*!
+    \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
index 8c9615f..dce8585 100644 (file)
@@ -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)
index fd7b0d7..5d7eb1d 100644 (file)
@@ -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"