summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-01-24 17:29:20 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-30 16:24:57 +0100
commitbe1867b6c4743da937d269f04c2e108a18d3f400 (patch)
tree5971ed2bee8bdfe0e1ae10c433cb98650be01b95 /tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
parent3fe3d1dfdda9be266ba2400a85fd100c4e3d2cc2 (diff)
Add the QAbstractItemModel::canDropMimeData method.
Can be used by views to indicate whether a drop is allowed (eg adequete permissions in a filesystem model). Change-Id: Iefedb5399e44c8edc5f5df1403c8d5c0da618612 Reviewed-by: Peter Penz <peter.penz19@gmail.com> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp')
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index 5d7902a57a..2ca5df477b 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -72,6 +72,7 @@ private slots:
void match();
void dropMimeData_data();
void dropMimeData();
+ void canDropMimeData();
void changePersistentIndex();
void movePersistentIndex();
@@ -150,6 +151,9 @@ public:
const QModelIndex &destinationParent, int destinationChild);
void reset();
+ bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent) const;
+
int cCount, rCount;
mutable bool wrongIndex;
QVector<QVector<QString> > table;
@@ -315,6 +319,25 @@ void QtTestModel::reset()
QAbstractItemModel::reset();
}
+bool QtTestModel::canDropMimeData(const QMimeData *data, Qt::DropAction action,
+ int row, int column, const QModelIndex &parent) const
+{
+ Q_UNUSED(data);
+ Q_UNUSED(action);
+
+ // For testing purposes, we impose some arbitrary rules on what may be dropped.
+ if (!parent.isValid() && row < 0 && column < 0) {
+ // a drop in emtpy space in the view is allowed.
+ // For example, in a filesystem view, a file may be dropped into empty space
+ // if it represents a writable directory.
+ return true;
+ }
+
+ // We then arbitrarily decide to only allow drops on odd rows.
+ // A filesystem view/model might be able to drop onto (writable) directories.
+ return row % 2 == 0;
+}
+
/**
* The source Model *must* be initialized before the _data function, since the _data function uses QModelIndexes to reference the items in the tables.
* Therefore, we must initialize it globally.
@@ -755,6 +778,15 @@ void tst_QAbstractItemModel::dropMimeData()
}
}
+void tst_QAbstractItemModel::canDropMimeData()
+{
+ QtTestModel model(3, 3);
+
+ QVERIFY(model.canDropMimeData(0, Qt::CopyAction, -1, -1, QModelIndex()));
+ QVERIFY(model.canDropMimeData(0, Qt::CopyAction, 0, 0, QModelIndex()));
+ QVERIFY(!model.canDropMimeData(0, Qt::CopyAction, 1, 0, QModelIndex()));
+}
+
void tst_QAbstractItemModel::changePersistentIndex()
{
QtTestModel model(3, 3);