diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-01-15 19:46:56 +0100 |
---|---|---|
committer | Caroline Chao <caroline.chao@theqtcompany.com> | 2015-02-12 11:10:04 +0000 |
commit | 005931905af62fb354c012594f9420d0acabbee3 (patch) | |
tree | 400f3a3c34bf6c47f579199655575b0d2517aa98 /tests/auto/qml/qqmlitemmodels/data | |
parent | c5796292adf7cb7f2ce6f95fb83a9da89ecaa730 (diff) |
Add Q_GADGET wrappers for QModelIndex & Co.
The complete list of types is,
* QModelIndex
* QModelIndexList
* QPersistentModelIndex
* QItemSelection
* QItemSelectionRange
These wrapper types follow the QQmlValueType conventions and
allow us to expose the wrapped types without introducing
meta-type changes. They also allow to customize the string
type representation.
We also extend QQmlValueTypeFactory to return the meta-object
for those types.
Finally, we add two-way meta-type conversion between QModelIndex
and QPersistentModelIndex to get the same interoperability as
in C++ when passing an object of one type to a function requir-
ing an object of the other type.
Change-Id: Iaa7089ea576c901f12715ffa21e4d94603d53755
Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com>
Diffstat (limited to 'tests/auto/qml/qqmlitemmodels/data')
6 files changed, 140 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlitemmodels/data/itemselection.qml b/tests/auto/qml/qqmlitemmodels/data/itemselection.qml new file mode 100644 index 0000000000..57cb6436e9 --- /dev/null +++ b/tests/auto/qml/qqmlitemmodels/data/itemselection.qml @@ -0,0 +1,36 @@ +import Test 1.0 + +ItemModelsTest { + property var itemSelection + property int count + property bool contains: false + + function range(top, bottom, left, right, parent) { + if (parent === undefined) + parent = invalidModelIndex() + var topLeft = model.index(top, left, parent) + var bottomRight = model.index(bottom, right, parent) + return createItemSelectionRange(topLeft, bottomRight) + } + + onModelChanged: { + itemSelection = createItemSelection() + itemSelection.prepend(range(0, 0, 0, 5)) + itemSelection.append(range(0, 5, 0, 0)) + for (var i = 0; i < 3; i++) + itemSelection.insert(i, 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*/) + + count = itemSelection.length + contains = itemSelection.contains(model.index(0, 0)) + + itemSelection.removeAt(3) + itemSelection.removeFirst() + itemSelection.removeLast() + } +} diff --git a/tests/auto/qml/qqmlitemmodels/data/itemselectionrange.qml b/tests/auto/qml/qqmlitemmodels/data/itemselectionrange.qml new file mode 100644 index 0000000000..72f732abaf --- /dev/null +++ b/tests/auto/qml/qqmlitemmodels/data/itemselectionrange.qml @@ -0,0 +1,32 @@ +import Test 1.0 + +ItemModelsTest { + property var itemSelectionRange: createItemSelectionRange(invalidModelIndex(), invalidModelIndex()) + property int top: itemSelectionRange.top + property int left: itemSelectionRange.left + property int bottom: itemSelectionRange.bottom + property int right: itemSelectionRange.right + property int width: itemSelectionRange.width + property int height: itemSelectionRange.height + property bool isValid: itemSelectionRange.valid + property bool isEmpty: itemSelectionRange.empty + property var isrModel: itemSelectionRange.model + property bool contains1: false + property bool contains2: false + property bool intersects: false + property var intersected + + onModelChanged: { + if (model) { + var parentIndex = model.index(0, 0) + var index1 = model.index(3, 0, parentIndex) + var index2 = model.index(5, 6, parentIndex) + itemSelectionRange = createItemSelectionRange(index1, index2) + + contains1 = itemSelectionRange.contains(index1) + contains2 = itemSelectionRange.contains(4, 3, parentIndex) + intersects = itemSelectionRange.intersects(createItemSelectionRange(parentIndex, parentIndex)) + intersected = itemSelectionRange.intersected(createItemSelectionRange(parentIndex, parentIndex)) + } + } +} diff --git a/tests/auto/qml/qqmlitemmodels/data/modelindex.qml b/tests/auto/qml/qqmlitemmodels/data/modelindex.qml new file mode 100644 index 0000000000..0d6e3624cb --- /dev/null +++ b/tests/auto/qml/qqmlitemmodels/data/modelindex.qml @@ -0,0 +1,19 @@ +import Test 1.0 + +ItemModelsTest { + property bool isValid: modelIndex.valid + property int row: modelIndex.row + property int column: modelIndex.column + property var parent: modelIndex.parent + property var model: modelIndex.model + property var internalId: modelIndex.internalId + + onSignalWithModelIndex: { + isValid = index.valid + row = index.row + column = index.column + parent = index.parent + model = index.model + internalId = index.internalId + } +} diff --git a/tests/auto/qml/qqmlitemmodels/data/modelindexconversion.qml b/tests/auto/qml/qqmlitemmodels/data/modelindexconversion.qml new file mode 100644 index 0000000000..91ee05eaa9 --- /dev/null +++ b/tests/auto/qml/qqmlitemmodels/data/modelindexconversion.qml @@ -0,0 +1,9 @@ +import Test 1.0 + +ItemModelsTest { + + onModelChanged: { + modelIndex = createPersistentModelIndex(model.index(0, 0)) + persistentModelIndex = model.index(1, 1) + } +} diff --git a/tests/auto/qml/qqmlitemmodels/data/modelindexlist.qml b/tests/auto/qml/qqmlitemmodels/data/modelindexlist.qml new file mode 100644 index 0000000000..44393392d3 --- /dev/null +++ b/tests/auto/qml/qqmlitemmodels/data/modelindexlist.qml @@ -0,0 +1,21 @@ +import Test 1.0 + +ItemModelsTest { + property var modelIndexList + property int count + + onModelChanged: { + modelIndexList = createModelIndexList() + modelIndexList.prepend(model.index(0, 0)) + modelIndexList.append(model.index(1, 1)) + for (var i = 0; i < 3; i++) + modelIndexList.insert(i, model.index(2 + i, 2 + i)) + + count = modelIndexList.length + modelIndex = modelIndexList.at(0) + + modelIndexList.removeAt(3) + modelIndexList.removeFirst() + modelIndexList.removeLast() + } +} diff --git a/tests/auto/qml/qqmlitemmodels/data/persistentmodelindex.qml b/tests/auto/qml/qqmlitemmodels/data/persistentmodelindex.qml new file mode 100644 index 0000000000..13037065a6 --- /dev/null +++ b/tests/auto/qml/qqmlitemmodels/data/persistentmodelindex.qml @@ -0,0 +1,23 @@ +import Test 1.0 + +ItemModelsTest { + property bool isValid: persistentModelIndex.valid + property int row: persistentModelIndex.row + property int column: persistentModelIndex.column + property var parent: persistentModelIndex.parent + property var model: persistentModelIndex.model + property var internalId: persistentModelIndex.internalId + + property var pmi + + onSignalWithPersistentModelIndex: { + isValid = index.valid + row = index.row + column = index.column + parent = index.parent + model = index.model + internalId = index.internalId + + pmi = createPersistentModelIndex(model.index(0, 0)) + } +} |