diff options
Diffstat (limited to 'tests/auto/qml/qqmlitemmodels')
-rw-r--r-- | tests/auto/qml/qqmlitemmodels/data/itemselection.qml | 23 | ||||
-rw-r--r-- | tests/auto/qml/qqmlitemmodels/testtypes.h | 16 | ||||
-rw-r--r-- | tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp | 14 |
3 files changed, 33 insertions, 20 deletions
diff --git a/tests/auto/qml/qqmlitemmodels/data/itemselection.qml b/tests/auto/qml/qqmlitemmodels/data/itemselection.qml index 57cb6436e9..c2da71627a 100644 --- a/tests/auto/qml/qqmlitemmodels/data/itemselection.qml +++ b/tests/auto/qml/qqmlitemmodels/data/itemselection.qml @@ -1,9 +1,10 @@ import Test 1.0 ItemModelsTest { - property var itemSelection property int count property bool contains: false + property var itemSelectionBinding: itemSelection + property var itemSelectionRead function range(top, bottom, left, right, parent) { if (parent === undefined) @@ -14,23 +15,15 @@ ItemModelsTest { } onModelChanged: { - itemSelection = createItemSelection() - itemSelection.prepend(range(0, 0, 0, 5)) - itemSelection.append(range(0, 5, 0, 0)) + itemSelection = [] + itemSelection.push(range(0, 0, 0, 5)) + itemSelection.push(range(0, 5, 0, 0)) for (var i = 0; i < 3; i++) - itemSelection.insert(i, range(i, i + 1, i + 2, i + 3)) + itemSelection.splice(i, 0, range(i, i + 1, i + 2, i + 3)) - var itemSelection2 = createItemSelection() - for (i = 3; i < 6; i++) - itemSelection2.select(model.index(i, i + 1), model.index(i + 2, i + 3)) - - itemSelection.merge(itemSelection2, 2 /*ItemSelectionModel.Select*/) + itemSelectionRead = itemSelection count = itemSelection.length - contains = itemSelection.contains(model.index(0, 0)) - - itemSelection.removeAt(3) - itemSelection.removeFirst() - itemSelection.removeLast() + contains = itemSelection.some(function (range, idx) { return range.contains(model.index(0, 0)) }) } } diff --git a/tests/auto/qml/qqmlitemmodels/testtypes.h b/tests/auto/qml/qqmlitemmodels/testtypes.h index d61064fcad..69da24ec6e 100644 --- a/tests/auto/qml/qqmlitemmodels/testtypes.h +++ b/tests/auto/qml/qqmlitemmodels/testtypes.h @@ -46,6 +46,7 @@ class ItemModelsTest : public QObject Q_PROPERTY(QModelIndex modelIndex READ modelIndex WRITE setModelIndex NOTIFY changed) Q_PROPERTY(QPersistentModelIndex persistentModelIndex READ persistentModelIndex WRITE setPersistentModelIndex NOTIFY changed) Q_PROPERTY(QModelIndexList modelIndexList READ modelIndexList WRITE setModelIndexList NOTIFY changed) + Q_PROPERTY(QItemSelection itemSelection READ itemSelection WRITE setItemSelection NOTIFY changed) public: ItemModelsTest(QObject *parent = 0) @@ -84,6 +85,11 @@ public: return list; } + QItemSelection itemSelection() const + { + return m_itemSelection; + } + void emitChanged() { emit changed(); @@ -161,6 +167,15 @@ public slots: emit changed(); } + void setItemSelection(QItemSelection arg) + { + if (m_itemSelection == arg) + return; + + m_itemSelection = arg; + emit changed(); + } + signals: void changed(); @@ -174,6 +189,7 @@ private: QPersistentModelIndex m_persistentModelIndex; QAbstractItemModel *m_model; QModelIndexList m_modelIndexList; + QItemSelection m_itemSelection; }; #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp b/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp index cd00593ee6..637b9e4b90 100644 --- a/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp +++ b/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp @@ -184,14 +184,18 @@ void tst_qqmlitemmodels::itemSelection() TestModel model(10, 10); object->setModel(&model); - QCOMPARE(object->property("count").toInt(), 8); + QCOMPARE(object->property("count").toInt(), 5); QCOMPARE(object->property("contains").toBool(), true); - QVariant milVariant = object->property("itemSelection"); - QCOMPARE(milVariant.userType(), qMetaTypeId<QItemSelection>()); + const char *propNames[] = { "itemSelectionRead", "itemSelectionBinding", 0 }; + for (const char **name = propNames; *name; name++) { + QVariant isVariant = object->property(*name); + QCOMPARE(isVariant.userType(), qMetaTypeId<QItemSelection>()); - const QItemSelection &mil = milVariant.value<QItemSelection>(); - QCOMPARE(mil.count(), 5); + const QItemSelection &sel = isVariant.value<QItemSelection>(); + QCOMPARE(sel.count(), object->itemSelection().count()); + QCOMPARE(sel, object->itemSelection()); + } } void tst_qqmlitemmodels::modelIndexList() |