From fe3b3c707e2bc41f2e98d315ba72f50d4929e064 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 3 Mar 2020 10:48:27 +0100 Subject: HeaderView: Add support for list based models Change-Id: I411136bd2b9a277d84a7c68c55bb1c317b6cc9d2 Reviewed-by: Mitch Curtis --- tests/auto/qquickheaderview/data/ListModel.qml | 107 +++++++++++++++++++++ .../auto/qquickheaderview/tst_qquickheaderview.cpp | 34 +++++++ 2 files changed, 141 insertions(+) create mode 100644 tests/auto/qquickheaderview/data/ListModel.qml (limited to 'tests/auto') diff --git a/tests/auto/qquickheaderview/data/ListModel.qml b/tests/auto/qquickheaderview/data/ListModel.qml new file mode 100644 index 00000000..59021458 --- /dev/null +++ b/tests/auto/qquickheaderview/data/ListModel.qml @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** 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:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtQuick.Controls 2.15 +import TestTableModel 0.1 + +Window { + objectName: "window" + width: 400 + height: 400 + visible: true + + Component { + id: cellDelegate + Rectangle { + implicitHeight: 25 + implicitWidth: 50 + color: "red" + Text { + text: row + "," + column + } + } + } + + HorizontalHeaderView { + id: hhv + objectName: "horizontalHeader" + model: ["AAA", "BBB", "CCC", "DDD", "EEE"] + syncView: tv + anchors.top: parent.top + x: vhv.width + } + + VerticalHeaderView { + id: vhv + objectName: "verticalHeader" + model: ["111", "222", "333", "444", "555"] + syncView: tv + anchors.left: parent.left + y: hhv.height + } + + TableView { + id: tv + objectName: "tableView" + model: TestTableModel { + id: tm + objectName: "tableModel" + rowCount: 5 + columnCount: 5 + } + delegate: cellDelegate + anchors.top: hhv.bottom + anchors.left: vhv.right + anchors.right: parent.right + anchors.bottom: parent.bottom + } +} diff --git a/tests/auto/qquickheaderview/tst_qquickheaderview.cpp b/tests/auto/qquickheaderview/tst_qquickheaderview.cpp index 5ce5439d..64f769e8 100644 --- a/tests/auto/qquickheaderview/tst_qquickheaderview.cpp +++ b/tests/auto/qquickheaderview/tst_qquickheaderview.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -218,6 +219,7 @@ private slots: void testHeaderDataProxyModel(); void testOrientation(); void testModel(); + void listModel(); private: QQmlEngine *engine; @@ -349,6 +351,38 @@ void tst_QQuickHeaderView::testModel() QCOMPARE(modelChangedSpy.count(), 2); } +void tst_QQuickHeaderView::listModel() +{ + QQmlComponent component(engine); + component.loadUrl(testFileUrl("ListModel.qml")); + + QScopedPointer root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + + auto hhv = root->findChild("horizontalHeader"); + QVERIFY(hhv); + auto vhv = root->findChild("verticalHeader"); + QVERIFY(vhv); + + auto hhvCell1 = hhv->childAt(0, 0)->childAt(0, 0)->findChild(); + QVERIFY(hhvCell1); + QCOMPARE(hhvCell1->property("text"), "AAA"); + + auto hhvCell2 = hhv->childAt(hhvCell1->width() + 5, 0)-> + childAt(hhvCell1->width() + 5, 0)->findChild(); + QVERIFY(hhvCell2); + QCOMPARE(hhvCell2->property("text"), "BBB"); + + auto vhvCell1 = vhv->childAt(0, 0)->childAt(0, 0)->findChild(); + QVERIFY(vhvCell1); + QCOMPARE(vhvCell1->property("text"), "111"); + + auto vhvCell2 = vhv->childAt(0, vhvCell1->height() + 5)-> + childAt(0, vhvCell1->height() + 5)->findChild(); + QVERIFY(vhvCell2); + QCOMPARE(vhvCell2->property("text"), "222"); +} + QTEST_MAIN(tst_QQuickHeaderView) #include "tst_qquickheaderview.moc" -- cgit v1.2.3