diff options
Diffstat (limited to 'tests/auto/qml/qqmltablemodel/data')
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/TestModel.qml | 21 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/builtInRoles.qml | 47 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/common.qml | 95 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/complex.qml (renamed from tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml) | 59 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/dataAndSetData.qml | 19 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/empty.qml | 36 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/omitTableModelColumnIndex.qml (renamed from tests/auto/qml/qqmltablemodel/data/explicitDisplayRole.qml) | 20 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/setDataThroughDelegate.qml | 25 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/setRowsMultipleTimes.qml | 48 |
9 files changed, 173 insertions, 197 deletions
diff --git a/tests/auto/qml/qqmltablemodel/data/TestModel.qml b/tests/auto/qml/qqmltablemodel/data/TestModel.qml index 7aeb5d03f4..00e1fa65a7 100644 --- a/tests/auto/qml/qqmltablemodel/data/TestModel.qml +++ b/tests/auto/qml/qqmltablemodel/data/TestModel.qml @@ -33,15 +33,18 @@ import "TestUtils.js" as TestUtils TableModel { id: testModel objectName: "testModel" - roleDataProvider: TestUtils.testModelRoleDataProvider + + TableModelColumn { display: "name" } + TableModelColumn { display: "age" } + rows: [ - [ - { name: "John" }, - { age: 22 } - ], - [ - { name: "Oliver" }, - { age: 33 } - ] + { + name: "John", + age: 22 + }, + { + name: "Oliver", + age: 33 + } ] } diff --git a/tests/auto/qml/qqmltablemodel/data/builtInRoles.qml b/tests/auto/qml/qqmltablemodel/data/builtInRoles.qml deleted file mode 100644 index d9882e4dea..0000000000 --- a/tests/auto/qml/qqmltablemodel/data/builtInRoles.qml +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -import Qt.labs.qmlmodels 1.0 - -import "TestUtils.js" as TestUtils - -TableModel { - id: testModel - objectName: "testModel" - roleDataProvider: TestUtils.testModelRoleDataProvider - rows: [ - [ - { name: "John", someOtherRole1: "foo" }, // column 0 - { age: 22, someOtherRole2: "foo" } // column 1 - ], - [ - { name: "Oliver", someOtherRole1: "foo" }, // column 0 - { age: 33, someOtherRole2: "foo" } // column 1 - ] - ] -} diff --git a/tests/auto/qml/qqmltablemodel/data/common.qml b/tests/auto/qml/qqmltablemodel/data/common.qml index aec796bd4f..2f8b0c072b 100644 --- a/tests/auto/qml/qqmltablemodel/data/common.qml +++ b/tests/auto/qml/qqmltablemodel/data/common.qml @@ -26,7 +26,7 @@ ** ****************************************************************************/ -import QtQuick 2.12 +import QtQuick 2.13 import Qt.labs.qmlmodels 1.0 Item { @@ -38,80 +38,101 @@ Item { property alias tableView: tableView function appendRow(personName, personAge) { - testModel.appendRow([ - { name: personName }, - { age: personAge } - ]) + testModel.appendRow({ + name: personName, + age: personAge + }) + } + + function appendRowExtraData() { + testModel.appendRow({ + name: "Foo", + age: 99, + nonExistentRole: 123 + }) } function appendRowInvalid1() { - testModel.appendRow([ - { name: "Foo" }, - { age: 99 }, - { nonExistentRole: 123 } - ]) + testModel.appendRow(123) } function appendRowInvalid2() { - testModel.appendRow(123) + testModel.appendRow({ + name: "Foo", + age: [] + }) } function appendRowInvalid3() { testModel.appendRow([ - { name: "Foo" }, - { age: [] } + { name: "Bar" }, + { age: "111" } ]) } function insertRow(personName, personAge, rowIndex) { - testModel.insertRow(rowIndex, [ - { name: personName }, - { age: personAge }] - ) + testModel.insertRow(rowIndex, { + name: personName, + age: personAge + }) + } + + function insertRowExtraData() { + testModel.insertRow(0, { + name: "Foo", + age: 99, + nonExistentRole: 123 + }) } function insertRowInvalid1() { - testModel.insertRow(0, [ - { name: "Foo" }, - { age: 99 }, - { nonExistentRole: 123 } - ]) + testModel.insertRow(0, 123) } function insertRowInvalid2() { - testModel.insertRow(0, 123) + testModel.insertRow(0, { + name: "Foo", + age: [] + }) } function insertRowInvalid3() { testModel.insertRow(0, [ - { name: "Foo" }, - { age: [] } + { name: "Bar" }, + { age: "111" } ]) } function setRow(rowIndex, personName, personAge) { - testModel.setRow(rowIndex, [ - { name: personName }, - { age: personAge }] - ) + testModel.setRow(rowIndex, { + name: personName, + age: personAge + }) + } + + function setRowExtraData() { + testModel.setRow(0, { + name: "Foo", + age: 99, + nonExistentRole: 123 + }) } function setRowInvalid1() { - testModel.setRow(0, [ - { name: "Foo" }, - { age: 99 }, - { nonExistentRole: 123 } - ]) + testModel.setRow(0, 123) } function setRowInvalid2() { - testModel.setRow(0, 123) + testModel.setRow(0, { + name: "Foo", + age: [] + }) } function setRowInvalid3() { testModel.setRow(0, [ - { name: "Foo" }, - { age: [] } + { name: "Bar" }, + { age: "111" } ]) } diff --git a/tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml b/tests/auto/qml/qqmltablemodel/data/complex.qml index 2706ea54fd..dbf53bac7e 100644 --- a/tests/auto/qml/qqmltablemodel/data/roleDataProvider.qml +++ b/tests/auto/qml/qqmltablemodel/data/complex.qml @@ -26,40 +26,43 @@ ** ****************************************************************************/ -import QtQuick 2.12 +import QtQuick 2.13 import Qt.labs.qmlmodels 1.0 -Item { - id: root - width: 200 - height: 200 +TableView { + width: 100 + height: 100 + delegate: Item { + implicitWidth: 50 + implicitHeight: 50 - property alias testModel: testModel - - TableModel { + Text { + text: model.display + anchors.centerIn: parent + } + } + model: TableModel { id: testModel objectName: "testModel" - rows: [ - [ { name: "Rex" }, { age: 3 } ], - [ { name: "Buster" }, { age: 5 } ] - ] - roleDataProvider: function(index, role, cellData) { - if (role === "display") { - // Age will now be in dog years - if (cellData.hasOwnProperty("age")) - return (cellData.age * 7); - else if (index.column === 0) - return (cellData.name); - } - return cellData; + + TableModelColumn { + display: function(modelIndex) { return testModel.rows[modelIndex.row][0].name } + setDisplay: function(modelIndex, cellData) { testModel.rows[modelIndex.row][0].name = cellData } } - } - TableView { - anchors.fill: parent - model: testModel - delegate: Text { - id: textItem - text: model.display + TableModelColumn { + display: function(modelIndex) { return testModel.rows[modelIndex.row][1].age } + setDisplay: function(modelIndex, cellData) { testModel.rows[modelIndex.row][1].age = cellData } } + + rows: [ + [ + { name: "John" }, + { age: 22 } + ], + [ + { name: "Oliver" }, + { age: 33 } + ] + ] } } diff --git a/tests/auto/qml/qqmltablemodel/data/dataAndSetData.qml b/tests/auto/qml/qqmltablemodel/data/dataAndSetData.qml index d61c50ba2c..d3f726bfa1 100644 --- a/tests/auto/qml/qqmltablemodel/data/dataAndSetData.qml +++ b/tests/auto/qml/qqmltablemodel/data/dataAndSetData.qml @@ -31,36 +31,25 @@ import Qt.labs.qmlmodels 1.0 TableView { width: 200; height: 200 - model: TableModel { + model: TestModel { id: testModel - objectName: "testModel" - rows: [ - [ - { name: "John", someOtherRole1: "foo" }, // column 0 - { age: 22, someOtherRole2: "foo" } // column 1 - ], - [ - { name: "Oliver", someOtherRole1: "foo" }, // column 0 - { age: 33, someOtherRole2: "foo" } // column 1 - ] - ] // This is silly: in real life, store the birthdate instead of the age, // and let the delegate calculate the age, so it won't need updating function happyBirthday(dude) { var row = -1; for (var r = 0; row < 0 && r < testModel.rowCount; ++r) - if (testModel.data(testModel.index(r, 0), "name") === dude) + if (testModel.data(testModel.index(r, 0), "display") === dude) row = r; var index = testModel.index(row, 1) - testModel.setData(index, "age", testModel.data(index, "age") + 1) + testModel.setData(index, "display", testModel.data(index, "display") + 1) } } delegate: Text { id: textItem text: model.display TapHandler { - onTapped: testModel.happyBirthday(testModel.data(testModel.index(row, 0), "name")) + onTapped: testModel.happyBirthday(testModel.data(testModel.index(row, 0), "display")) } } } diff --git a/tests/auto/qml/qqmltablemodel/data/empty.qml b/tests/auto/qml/qqmltablemodel/data/empty.qml index 6e66b99145..f5afbd1d27 100644 --- a/tests/auto/qml/qqmltablemodel/data/empty.qml +++ b/tests/auto/qml/qqmltablemodel/data/empty.qml @@ -29,8 +29,6 @@ import QtQuick 2.12 import Qt.labs.qmlmodels 1.0 -import "TestUtils.js" as TestUtils - Item { id: root width: 200 @@ -41,21 +39,37 @@ Item { function setRows() { testModel.rows = [ - [ - { name: "John" }, - { age: 22 } - ], - [ - { name: "Oliver" }, - { age: 33 } - ] + { + name: "John", + age: 22 + }, + { + name: "Oliver", + age: 33 + } ] } + function appendJohn() { + testModel.appendRow({ + name: "John", + age: 22 + }) + } + + function appendOliver() { + testModel.appendRow({ + name: "Oliver", + age: 33 + }) + } + TableModel { id: testModel objectName: "testModel" - roleDataProvider: TestUtils.testModelRoleDataProvider + + TableModelColumn { display: "name" } + TableModelColumn { display: "age" } } TableView { id: tableView diff --git a/tests/auto/qml/qqmltablemodel/data/explicitDisplayRole.qml b/tests/auto/qml/qqmltablemodel/data/omitTableModelColumnIndex.qml index 510a62e74b..86bcb08fa2 100644 --- a/tests/auto/qml/qqmltablemodel/data/explicitDisplayRole.qml +++ b/tests/auto/qml/qqmltablemodel/data/omitTableModelColumnIndex.qml @@ -28,14 +28,20 @@ import Qt.labs.qmlmodels 1.0 -import "TestUtils.js" as TestUtils - TableModel { - id: testModel + objectName: "testModel" + + TableModelColumn { display: "name" } + TableModelColumn { display: "age" } + rows: [ - [ - { name: "John", display: "foo" }, - { age: 22, display: "bar" } - ] + { + name: "John", + age: 22 + }, + { + name: "Oliver", + age: 33 + } ] } diff --git a/tests/auto/qml/qqmltablemodel/data/setDataThroughDelegate.qml b/tests/auto/qml/qqmltablemodel/data/setDataThroughDelegate.qml index 5f849c3350..ebfe4ed930 100644 --- a/tests/auto/qml/qqmltablemodel/data/setDataThroughDelegate.qml +++ b/tests/auto/qml/qqmltablemodel/data/setDataThroughDelegate.qml @@ -41,11 +41,11 @@ Item { signal shouldModifyInvalidType() function modify() { - shouldModify(); + shouldModify() } function modifyInvalidRole() { - shouldModifyInvalidRole(); + shouldModifyInvalidRole() } function modifyInvalidType() { @@ -54,37 +54,24 @@ Item { TableView { anchors.fill: parent - model: TableModel { + model: TestModel { id: testModel - objectName: "testModel" - rows: [ - [ - { name: "John" }, - { age: 22 } - ], - [ - { name: "Oliver" }, - { age: 33 } - ] - ] } delegate: Text { id: textItem - // TODO: this is currently random when no roleDataProvider handles it - // we should allow roleDataProvider to be used to handle specific roles only text: model.display Connections { target: root enabled: column === 1 - onShouldModify: model.age = 18 + onShouldModify: model.display = 18 } Connections { target: root enabled: column === 0 - // Invalid: should be "name". + // Invalid: should be "display". onShouldModifyInvalidRole: model.age = 100 } @@ -92,7 +79,7 @@ Item { target: root enabled: column === 1 // Invalid: should be string. - onShouldModifyInvalidType: model.age = "Whoops" + onShouldModifyInvalidType: model.display = "Whoops" } } } diff --git a/tests/auto/qml/qqmltablemodel/data/setRowsMultipleTimes.qml b/tests/auto/qml/qqmltablemodel/data/setRowsMultipleTimes.qml index 6aaf79f2d4..01ec40270c 100644 --- a/tests/auto/qml/qqmltablemodel/data/setRowsMultipleTimes.qml +++ b/tests/auto/qml/qqmltablemodel/data/setRowsMultipleTimes.qml @@ -39,35 +39,35 @@ Item { function setRowsValid() { testModel.rows = [ - [ - { name: "Max" }, - { age: 20 } - ], - [ - { name: "Imum" }, - { age: 41 } - ], - [ - { name: "Power" }, - { age: 89 } - ] + { + name: "Max", + age: 20 + }, + { + name: "Imum", + age: 41 + }, + { + name: "Power", + age: 89 + } ] } function setRowsInvalid() { testModel.rows = [ - [ - { nope: "Nope" }, - { age: 20 } - ], - [ - { nope: "Nah" }, - { age: 41 } - ], - [ - { nope: "No" }, - { age: 89 } - ] + { + nope: "Nope", + age: 20 + }, + { + nope: "Nah", + age: 41 + }, + { + nope: "No", + age: 89 + } ] } |