From 4df52eee2b40244ba1a3d115a43ed51cfd742105 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 7 Feb 2019 17:35:51 +0100 Subject: Menu: account for the scale when getting the size before positioning Fixes: QTBUG-73687 Change-Id: Id2d6a6b5c6651337ab7ae26d07011160b79654bf Reviewed-by: Mitch Curtis --- tests/auto/controls/data/tst_popup.qml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml index 27043d1c..71d6f2d7 100644 --- a/tests/auto/controls/data/tst_popup.qml +++ b/tests/auto/controls/data/tst_popup.qml @@ -326,6 +326,7 @@ TestCase { var control = createTemporaryObject(popupControl, testCase, {visible: true, margins: 0}) verify(control) + control.scale = 1.0 control.width = control.implicitWidth = testCase.width + 10 control.height = control.implicitHeight = testCase.height + 10 @@ -1293,8 +1294,8 @@ TestCase { // Center the popup in the window via the overlay. control.anchors.centerIn = Qt.binding(function() { return control.parent; }) compare(centerInSpy.count, 1) - compare(control.x, (overlay.width - control.width) / 2) - compare(control.y, (overlay.height - control.height) / 2) + compare(control.x, (overlay.width - (control.width * control.scale)) / 2) + compare(control.y, (overlay.height - (control.width * control.scale)) / 2) // Ensure that it warns when trying to set it to an item that's not its parent. var anotherItem = createTemporaryObject(rect, applicationWindow.contentItem, { x: 100, y: 100, width: 50, height: 50 }) @@ -1317,14 +1318,14 @@ TestCase { compare(control.parent, anotherItem) compare(control.anchors.centerIn, anotherItem) compare(centerInSpy.count, 4) - compare(control.x, (anotherItem.width - control.width) / 2) - compare(control.y, (anotherItem.height - control.height) / 2) + compare(control.x, (anotherItem.width - (control.width * control.scale)) / 2) + compare(control.y, (anotherItem.height - (control.height * control.scale)) / 2) // Check that anchors.centerIn beats x and y coordinates as it does in QQuickItem. control.x = 33; control.y = 44; - compare(control.x, (anotherItem.width - control.width) / 2) - compare(control.y, (anotherItem.height - control.height) / 2) + compare(control.x, (anotherItem.width - (control.width * control.scale)) / 2) + compare(control.y, (anotherItem.height - (control.height * control.scale)) / 2) // Check that the popup's x and y coordinates are restored when it's no longer centered. control.anchors.centerIn = undefined @@ -1335,8 +1336,8 @@ TestCase { // Test centering in the overlay while having a different parent (anotherItem). control.anchors.centerIn = overlay compare(centerInSpy.count, 6) - compare(control.x, (overlay.width - control.width) / 2) - compare(control.y, (overlay.height - control.height) / 2) + compare(control.x, (overlay.width - (control.width * control.scale)) / 2) + compare(control.y, (overlay.height - (control.height * control.scale)) / 2) // TODO: do this properly by creating a component or something applicationWindow.visible = false -- cgit v1.2.3 From 418cb72b9346ddb258cb1384fd6b95af143c2059 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 17 Mar 2020 20:19:41 +0100 Subject: Account for the padding around a menu when checking if it is interactive If there is padding around the menu then it will mean the available height is smaller than the containing item and as such should be interactive. Fixes: QTBUG-82473 Change-Id: Ie3e7568ab66aa3da93e5448c1a27c9bd2a5e486a Reviewed-by: Mitch Curtis --- .../auto/qquickmenu/data/scrollableWithPadding.qml | 79 ++++++++++++++++++++++ tests/auto/qquickmenu/tst_qquickmenu.cpp | 1 + 2 files changed, 80 insertions(+) create mode 100644 tests/auto/qquickmenu/data/scrollableWithPadding.qml (limited to 'tests/auto') diff --git a/tests/auto/qquickmenu/data/scrollableWithPadding.qml b/tests/auto/qquickmenu/data/scrollableWithPadding.qml new file mode 100644 index 00000000..86405ccb --- /dev/null +++ b/tests/auto/qquickmenu/data/scrollableWithPadding.qml @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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.12 +import QtQuick.Controls 2.12 +import QtQuick.Window 2.11 + +Window { + title: "Test Window" + width: 300 + height: dummyItem.height * 10 + + property alias menu: menu + MenuItem { + id: dummyItem + objectName: "Dummy" + text: objectName + } + + Menu { + id: menu + topPadding: 10 + Repeater { + model: 10 + + delegate: MenuItem { + objectName: text + text: (index + 1) + } + } + } +} diff --git a/tests/auto/qquickmenu/tst_qquickmenu.cpp b/tests/auto/qquickmenu/tst_qquickmenu.cpp index 2fe47477..22aece0c 100644 --- a/tests/auto/qquickmenu/tst_qquickmenu.cpp +++ b/tests/auto/qquickmenu/tst_qquickmenu.cpp @@ -1588,6 +1588,7 @@ void tst_QQuickMenu::scrollable_data() QTest::addRow("Window") << QString::fromLatin1("windowScrollable.qml"); QTest::addRow("ApplicationWindow") << QString::fromLatin1("applicationWindowScrollable.qml"); + QTest::addRow("WithPadding") << QString::fromLatin1("scrollableWithPadding.qml"); } void tst_QQuickMenu::scrollable() -- cgit v1.2.3 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 From 25532ae18f25f2c415efc0f2ee9a67e16c39813b Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 30 Mar 2020 13:49:02 +0200 Subject: tst_qquickheaderview: wait for window to be active The tst_QQuickHeaderView::listModel test fails on Ubuntu. From inspecting the build log, VerticalHeaderView has an empty size. Since HeaderView will only load items that end up visible in the view, it will load just one item in this case, even if the model contains five. Hence the test will fail when searching for the other missing items. Why VerticalTableView has an empty size is not well understood (and cannot be reproduced on my mac). The size is bound to the size of the window, which indicates that the window is not shown or ready by the time the test runs. So this patch will change how we create the window for the test, and wait for it to be active, which is standard procedure for many other tests. Hopefully this will also fix the test failure on Ubuntu. Task-number: QTBUG-83172 Change-Id: I7d3a188dbeb161f11eee7b95c103928404161f11 Reviewed-by: Volker Hilsheimer --- tests/auto/qquickheaderview/tst_qquickheaderview.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qquickheaderview/tst_qquickheaderview.cpp b/tests/auto/qquickheaderview/tst_qquickheaderview.cpp index 64f769e8..611e39cb 100644 --- a/tests/auto/qquickheaderview/tst_qquickheaderview.cpp +++ b/tests/auto/qquickheaderview/tst_qquickheaderview.cpp @@ -359,6 +359,9 @@ void tst_QQuickHeaderView::listModel() QScopedPointer root(component.create()); QVERIFY2(root, qPrintable(component.errorString())); + if (!QTest::qWaitForWindowActive(qobject_cast(root.data()))) + QSKIP("Window failed to become active!"); + auto hhv = root->findChild("horizontalHeader"); QVERIFY(hhv); auto vhv = root->findChild("verticalHeader"); -- cgit v1.2.3