diff options
author | Liang Qi <liang.qi@qt.io> | 2020-04-22 18:04:39 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2020-04-22 18:04:39 +0200 |
commit | a42144610b1e268e82c0aa972e957fd24ac4cc6a (patch) | |
tree | b63d3344952f34d76e0991e3ac0ecbe629c77702 /tests | |
parent | 796f6e1e8e99ea1046ffe2a744cfd1dca1248258 (diff) | |
parent | 560bc348d86aba6cef5fdf88bc9d7304dd914bc8 (diff) |
Merge remote-tracking branch 'origin/5.14' into 5.15.0
Conflicts:
src/imports/labsmodels/qqmltablemodel.cpp
tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp
This follows edc8512580fa16892dc13034e93300cc6a2bba59.
Change-Id: I42d1a977d33043045558118948db9151d03950c7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmltablemodel/data/intAndDouble.qml | 86 | ||||
-rw-r--r-- | tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp | 73 |
2 files changed, 158 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmltablemodel/data/intAndDouble.qml b/tests/auto/qml/qqmltablemodel/data/intAndDouble.qml new file mode 100644 index 0000000000..261bc8a115 --- /dev/null +++ b/tests/auto/qml/qqmltablemodel/data/intAndDouble.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 QtQuick 2.12 +import Qt.labs.qmlmodels 1.0 + +Item { + id: root + width: 200 + height: 200 + + property alias testModel: testModel + property alias tableView: tableView + + function appendBanana() { + testModel.appendRow({ + fruit: "Banana", + price: 3.5 + }) + } + + function appendStrawberry() { + testModel.appendRow({ + fruit: "Strawberry", + price: "5" + }) + } + + function appendInvalid() { + testModel.appendRow({ + fruit: "Pear", + price: "Invalid" + }) + } + + TableModel { + id: testModel + objectName: "testModel" + + TableModelColumn { display: "fruit" } + TableModelColumn { display: "price" } + rows: [ + { + fruit: "Apple", + price: 1 + }, + { + fruit: "Orange", + price: 2 + } + ] + } + TableView { + id: tableView + anchors.fill: parent + model: testModel + delegate: Text { + text: model.display + } + } +} diff --git a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp index 5457597df3..3923824fa2 100644 --- a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp +++ b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2019 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -59,6 +59,7 @@ private slots: void dataAndEditing(); void omitTableModelColumnIndex(); void complexRow(); + void appendRowWithDouble(); }; void tst_QQmlTableModel::appendRemoveRow() @@ -975,6 +976,76 @@ void tst_QQmlTableModel::complexRow() QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); } +void tst_QQmlTableModel::appendRowWithDouble() +{ + QQuickView view(testFileUrl("intAndDouble.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>(); + QVERIFY(model); + QCOMPARE(model->rowCount(), 2); + QCOMPARE(model->columnCount(), 2); + + QSignalSpy columnCountSpy(model, SIGNAL(columnCountChanged())); + QVERIFY(columnCountSpy.isValid()); + + QSignalSpy rowCountSpy(model, SIGNAL(rowCountChanged())); + QVERIFY(rowCountSpy.isValid()); + + QQuickTableView *tableView = view.rootObject()->property("tableView").value<QQuickTableView*>(); + QVERIFY(tableView); + QCOMPARE(tableView->rows(), 2); + QCOMPARE(tableView->columns(), 2); + + QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendBanana")); + QCOMPARE(model->rowCount(), 3); + QCOMPARE(model->columnCount(), 2); + const QHash<int, QByteArray> roleNames = model->roleNames(); + const int roleKey = roleNames.key("display"); + QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleKey).toString(), + QLatin1String("1")); + QCOMPARE(model->data(model->index(2, 0, QModelIndex()), roleKey).toString(), + QLatin1String("Banana")); + QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleKey).toDouble(), 3.5); + QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleKey).toString(), + QLatin1String("3.5")); + QCOMPARE(columnCountSpy.count(), 0); + QCOMPARE(rowCountSpy.count(), 1); + QTRY_COMPARE(tableView->rows(), 3); + QCOMPARE(tableView->columns(), 2); + + rowCountSpy.clear(); + + QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendStrawberry")); + QCOMPARE(model->rowCount(), 4); + QCOMPARE(model->columnCount(), 2); + QCOMPARE(model->data(model->index(3, 0, QModelIndex()), roleKey).toString(), + QLatin1String("Strawberry")); + QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleKey).toDouble(), 5); + QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleKey).toString(), + QLatin1String("5")); + QCOMPARE(columnCountSpy.count(), 0); + QCOMPARE(rowCountSpy.count(), 1); + QTRY_COMPARE(tableView->rows(), 4); + QCOMPARE(tableView->columns(), 2); + + rowCountSpy.clear(); + QTest::ignoreMessage(QtWarningMsg, + QRegularExpression(".*appendRow\\(\\): failed converting value " + "QVariant\\(QString, \"Invalid\"\\) set at column 1 with " + "role \"QString\" to \"int\"")); + QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendInvalid")); + // Nothing should change + QCOMPARE(model->rowCount(), 4); + QCOMPARE(model->columnCount(), 2); + QCOMPARE(columnCountSpy.count(), 0); + QCOMPARE(rowCountSpy.count(), 0); + QCOMPARE(tableView->rows(), 4); + QCOMPARE(tableView->columns(), 2); +} + QTEST_MAIN(tst_QQmlTableModel) #include "tst_qqmltablemodel.moc" |