summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-06-20 14:01:52 +0200
committerFriedemann Kleint <Friedemann.Kleint@digia.com>2014-06-25 16:31:03 +0200
commit4696e9dbaa4fc8bf3c7eeed9aceaba5da480acaf (patch)
tree547c667da3f0b9a74f49e74d51f1042f3e4503cb
parent8ded0a324d9ebdc8d45ecc278831e5993fabe1e0 (diff)
QAbstractProxyModel: Forward drop-related API.
Forward canDropMimeData() and dropMimeData() to the source model. [ChangeLog][QtCore][QAbstractProxyModel] QAbstractProxyModel now forwards the drop-related API. Task-number: QTBUG-39549 Change-Id: Ib81fcec862586e4ecfb99b9e0f4eb1a16eace762 Reviewed-by: Jørgen Lind <jorgen.lind@digia.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
-rw-r--r--src/corelib/itemmodels/qabstractproxymodel.cpp24
-rw-r--r--src/corelib/itemmodels/qabstractproxymodel.h4
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp32
3 files changed, 60 insertions, 0 deletions
diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp
index 2f1f4921f7..5250e2bf15 100644
--- a/src/corelib/itemmodels/qabstractproxymodel.cpp
+++ b/src/corelib/itemmodels/qabstractproxymodel.cpp
@@ -394,6 +394,30 @@ QMimeData* QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const
/*!
\reimp
+ \since 5.4
+ */
+bool QAbstractProxyModel::canDropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent) const
+{
+ Q_D(const QAbstractProxyModel);
+ const QModelIndex source = mapToSource(index(row, column, parent));
+ return d->model->canDropMimeData(data, action, source.row(), source.column(), source.parent());
+}
+
+/*!
+ \reimp
+ \since 5.4
+ */
+bool QAbstractProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent)
+{
+ Q_D(QAbstractProxyModel);
+ const QModelIndex source = mapToSource(index(row, column, parent));
+ return d->model->dropMimeData(data, action, source.row(), source.column(), source.parent());
+}
+
+/*!
+ \reimp
*/
QStringList QAbstractProxyModel::mimeTypes() const
{
diff --git a/src/corelib/itemmodels/qabstractproxymodel.h b/src/corelib/itemmodels/qabstractproxymodel.h
index 9b26d6cead..f1d3d0b07c 100644
--- a/src/corelib/itemmodels/qabstractproxymodel.h
+++ b/src/corelib/itemmodels/qabstractproxymodel.h
@@ -91,6 +91,10 @@ public:
QModelIndex sibling(int row, int column, const QModelIndex &idx) const;
QMimeData* mimeData(const QModelIndexList &indexes) const;
+ bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
+ bool dropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent) Q_DECL_OVERRIDE;
QStringList mimeTypes() const;
Qt::DropActions supportedDropActions() const;
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 72c7246ca9..471e5e6655 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -150,6 +150,8 @@ private slots:
void chainedProxyModelRoleNames();
void noMapAfterSourceDelete();
+ void forwardDropApi();
+
protected:
void buildHierarchy(const QStringList &data, QAbstractItemModel *model);
void checkHierarchy(const QStringList &data, const QAbstractItemModel *model);
@@ -3875,5 +3877,35 @@ void tst_QSortFilterProxyModel::noMapAfterSourceDelete()
QVERIFY(!persistent.isValid());
}
+// QTBUG-39549, test whether canDropMimeData(), dropMimeData() are proxied as well
+// by invoking them on a QSortFilterProxyModel proxying a QStandardItemModel that allows drops
+// on row #1, filtering for that row.
+class DropTestModel : public QStandardItemModel {
+public:
+ explicit DropTestModel(QObject *parent = 0) : QStandardItemModel(0, 1, parent)
+ {
+ appendRow(new QStandardItem(QStringLiteral("Row0")));
+ appendRow(new QStandardItem(QStringLiteral("Row1")));
+ }
+
+ bool canDropMimeData(const QMimeData *, Qt::DropAction,
+ int row, int /* column */, const QModelIndex & /* parent */) const Q_DECL_OVERRIDE
+ { return row == 1; }
+
+ bool dropMimeData(const QMimeData *, Qt::DropAction,
+ int row, int /* column */, const QModelIndex & /* parent */) Q_DECL_OVERRIDE
+ { return row == 1; }
+};
+
+void tst_QSortFilterProxyModel::forwardDropApi()
+{
+ QSortFilterProxyModel model;
+ model.setSourceModel(new DropTestModel(&model));
+ model.setFilterFixedString(QStringLiteral("Row1"));
+ QCOMPARE(model.rowCount(), 1);
+ QVERIFY(model.canDropMimeData(0, Qt::CopyAction, 0, 0, QModelIndex()));
+ QVERIFY(model.dropMimeData(0, Qt::CopyAction, 0, 0, QModelIndex()));
+}
+
QTEST_MAIN(tst_QSortFilterProxyModel)
#include "tst_qsortfilterproxymodel.moc"