From de867d237094b3ba7953aea68a739d13da056a76 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 5 Jun 2020 11:50:25 +0200 Subject: Platform: remove deprecated iconName, iconSource API [ChangeLog][Platform][Menu] The deprecated iconName and iconSource properties were removed. Use the icon property instead. [ChangeLog][Platform][MenuItem] The deprecated iconName and iconSource properties were removed. Use the icon property instead. [ChangeLog][Platform][SystemTrayIcon] The deprecated iconName and iconSource properties were removed. Use the icon property instead. Task-number: QTBUG-84715 Change-Id: I91a8ceb1a291b78fc342756de24e18b818a49b4b Reviewed-by: Shawn Rutledge --- tests/auto/platform/data/tst_menuitem.qml | 31 +++++++++-------- tests/auto/platform/data/tst_systemtrayicon.qml | 46 ++++++++++++++----------- tests/manual/systemtrayicon/systemtrayicon.qml | 2 +- 3 files changed, 43 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/auto/platform/data/tst_menuitem.qml b/tests/auto/platform/data/tst_menuitem.qml index 29d369bc..316af97d 100644 --- a/tests/auto/platform/data/tst_menuitem.qml +++ b/tests/auto/platform/data/tst_menuitem.qml @@ -68,8 +68,9 @@ TestCase { } } - SignalSpy { - id: spy + Component { + id: signalSpyComponent + SignalSpy {} } function test_properties_data() { @@ -81,30 +82,32 @@ TestCase { {tag: "checked", signal: "checkedChanged", init: false, value: true}, {tag: "role", signal: "roleChanged", init: MenuItem.TextHeuristicRole, value: MenuItem.AboutRole}, {tag: "text", signal: "textChanged", init: "", value: "text"}, - {tag: "iconSource", signal: "iconSourceChanged", init: "", value: "qrc:/undo.png"}, - {tag: "iconName", signal: "iconNameChanged", init: "", value: "edit-undo"}, + {tag: "icon.source", signal: "iconChanged", init: "", value: "qrc:/undo.png"}, + {tag: "icon.name", signal: "iconChanged", init: "", value: "edit-undo"}, {tag: "shortcut", signal: "shortcutChanged", init: undefined, value: StandardKey.Undo} ] } function test_properties(data) { - var item = menuItem.createObject(testCase) + let item = createTemporaryObject(menuItem, testCase) verify(item) - spy.target = item - spy.signalName = data.signal + let groupedProperty = data.tag.indexOf(".") !== -1 + let spy = createTemporaryObject(signalSpyComponent, testCase, { + target: item, signalName: data.signal + }) + verify(spy) verify(spy.valid) - compare(item[data.tag], data.init) - item[data.tag] = data.value + let propertyName = groupedProperty ? data.tag.split('.')[1] : data.tag + let object = !groupedProperty ? item : item.icon + compare(object[propertyName], data.init) + object[propertyName] = data.value compare(spy.count, 1) - compare(item[data.tag], data.value) + compare(object[propertyName], data.value) - item[data.tag] = data.value + object[propertyName] = data.value compare(spy.count, 1) - - spy.clear() - item.destroy() } function test_role() { diff --git a/tests/auto/platform/data/tst_systemtrayicon.qml b/tests/auto/platform/data/tst_systemtrayicon.qml index ce7d8b8d..d7a63551 100644 --- a/tests/auto/platform/data/tst_systemtrayicon.qml +++ b/tests/auto/platform/data/tst_systemtrayicon.qml @@ -61,44 +61,48 @@ TestCase { name: "SystemTrayIcon" Component { - id: systemTrayIcon + id: systemTrayIconComponent // Check that icon.name can be used in this Qt.labs.platform version SystemTrayIcon { icon.name: "" } } - SignalSpy { - id: spy + Component { + id: signalSpyComponent + SignalSpy {} } function test_properties_data() { return [ {tag: "visible", signal: "visibleChanged", init: false, value: true}, - {tag: "iconSource", signal: "iconSourceChanged", init: "", value: "qrc:/tray.png"}, - {tag: "iconName", signal: "iconNameChanged", init: "", value: "icon-name"}, + {tag: "icon.source", signal: "iconChanged", init: "", value: "qrc:/tray.png"}, + {tag: "icon.name", signal: "iconChanged", init: "", value: "icon-name"}, {tag: "tooltip", signal: "tooltipChanged", init: "", value: "tooltip"}, ] } function test_properties(data) { - var icon = systemTrayIcon.createObject(testCase) + let icon = createTemporaryObject(systemTrayIconComponent, testCase) verify(icon) - spy.target = icon - spy.signalName = data.signal + let groupedProperty = data.tag.indexOf(".") !== -1 + let spy = createTemporaryObject(signalSpyComponent, testCase, { + target: icon, signalName: data.signal + }) + verify(spy) verify(spy.valid) - compare(icon[data.tag], data.init) - icon[data.tag] = data.value - compare(spy.count, 1) - compare(icon[data.tag], data.value) + let propertyName = groupedProperty ? data.tag.split('.')[1] : data.tag + let object = !groupedProperty ? icon : icon.icon + compare(object[propertyName], data.init) - icon[data.tag] = data.value + object[propertyName] = data.value compare(spy.count, 1) + compare(object[propertyName], data.value) - spy.clear() - icon.destroy() + object[propertyName] = data.value + compare(spy.count, 1) } function test_messageIcon() { @@ -119,17 +123,17 @@ TestCase { } function test_activated() { - var icon = systemTrayIcon.createObject(testCase) + let icon = createTemporaryObject(systemTrayIconComponent, testCase) verify(icon) - spy.target = icon - spy.signalName = "activated" + let spy = createTemporaryObject(signalSpyComponent, testCase, { + target: icon, signalName: "activated" + }) + verify(spy) + verify(spy.valid) icon.activated(SystemTrayIcon.Trigger) compare(spy.count, 1) compare(spy.signalArguments[0][0], SystemTrayIcon.Trigger) - - spy.clear() - icon.destroy() } } diff --git a/tests/manual/systemtrayicon/systemtrayicon.qml b/tests/manual/systemtrayicon/systemtrayicon.qml index a7e656d4..03855b44 100644 --- a/tests/manual/systemtrayicon/systemtrayicon.qml +++ b/tests/manual/systemtrayicon/systemtrayicon.qml @@ -75,7 +75,7 @@ ApplicationWindow { SystemTrayIcon { visible: true - iconSource: "qrc:/files/images/qt_logo_green_256.png" + icon.source: "qrc:/files/images/qt_logo_green_256.png" menu: Menu { MenuItem { -- cgit v1.2.3 From 31fbd97b0e39e14f79d0d7be6fd277ebd6a2fa7a Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 5 Jun 2020 13:31:53 +0200 Subject: ApplicationWindow: remove deprecated overlay API [ChangeLog][Controls][ApplicationWindow] The deprecated overlay properties and attached API were removed. Use the Overlay attached type instead. Task-number: QTBUG-84715 Change-Id: I0781ea55ea502ffe5277385e82492291724d2090 Reviewed-by: Richard Moe Gustavsen --- tests/auto/controls/data/tst_popup.qml | 43 +++++++++++----------- .../data/attachedProperties.qml | 11 ------ .../tst_qquickapplicationwindow.cpp | 19 ---------- tests/auto/qquickmenu/data/applicationwindow.qml | 1 + tests/auto/qquickmenu/tst_qquickmenu.cpp | 25 ++++++++----- 5 files changed, 37 insertions(+), 62 deletions(-) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml index 71d6f2d7..0c6ab78a 100644 --- a/tests/auto/controls/data/tst_popup.qml +++ b/tests/auto/controls/data/tst_popup.qml @@ -1062,8 +1062,8 @@ TestCase { function findOverlay(window, popup) { var item = popup.contentItem.parent - var idx = indexOf(window.overlay.children, item) - return window.overlay.children[idx - 1] + var idx = indexOf(window.Overlay.overlay.children, item) + return window.Overlay.overlay.children[idx - 1] } function test_overlay() { @@ -1073,42 +1073,41 @@ TestCase { window.requestActivate() tryCompare(window, "active", true) - compare(window.overlay.children.length, 0) - compare(window.overlay, window.Overlay.overlay) + compare(window.Overlay.overlay.children.length, 0) var firstOverlay = findOverlay(window, window.firstDrawer) verify(!firstOverlay) window.firstDrawer.open() - compare(window.overlay.children.length, 2) // 1 drawer + 1 overlay + compare(window.Overlay.overlay.children.length, 2) // 1 drawer + 1 overlay firstOverlay = findOverlay(window, window.firstDrawer) verify(firstOverlay) compare(firstOverlay.z, window.firstDrawer.z) - compare(indexOf(window.overlay.children, firstOverlay), - indexOf(window.overlay.children, window.firstDrawer.contentItem.parent) - 1) + compare(indexOf(window.Overlay.overlay.children, firstOverlay), + indexOf(window.Overlay.overlay.children, window.firstDrawer.contentItem.parent) - 1) tryCompare(firstOverlay, "opacity", 1.0) var secondOverlay = findOverlay(window, window.secondDrawer) verify(!secondOverlay) window.secondDrawer.open() - compare(window.overlay.children.length, 4) // 2 drawers + 2 overlays + compare(window.Overlay.overlay.children.length, 4) // 2 drawers + 2 overlays secondOverlay = findOverlay(window, window.secondDrawer) verify(secondOverlay) compare(secondOverlay.z, window.secondDrawer.z) - compare(indexOf(window.overlay.children, secondOverlay), - indexOf(window.overlay.children, window.secondDrawer.contentItem.parent) - 1) + compare(indexOf(window.Overlay.overlay.children, secondOverlay), + indexOf(window.Overlay.overlay.children, window.secondDrawer.contentItem.parent) - 1) tryCompare(secondOverlay, "opacity", 1.0) window.firstDrawer.close() tryCompare(window.firstDrawer, "visible", false) firstOverlay = findOverlay(window, window.firstDrawer) verify(!firstOverlay) - compare(window.overlay.children.length, 2) // 1 drawer + 1 overlay + compare(window.Overlay.overlay.children.length, 2) // 1 drawer + 1 overlay window.secondDrawer.close() tryCompare(window.secondDrawer, "visible", false) secondOverlay = findOverlay(window, window.secondDrawer) verify(!secondOverlay) - compare(window.overlay.children.length, 0) + compare(window.Overlay.overlay.children.length, 0) var modalOverlay = findOverlay(window, window.modalPopup) verify(!modalOverlay) @@ -1118,7 +1117,7 @@ TestCase { compare(modalOverlay.z, window.modalPopup.z) compare(window.modalPopup.visible, true) tryCompare(modalOverlay, "opacity", 1.0) - compare(window.overlay.children.length, 2) // 1 popup + 1 overlay + compare(window.Overlay.overlay.children.length, 2) // 1 popup + 1 overlay var modelessOverlay = findOverlay(window, window.modelessPopup) verify(!modelessOverlay) @@ -1128,13 +1127,13 @@ TestCase { compare(modelessOverlay.z, window.modelessPopup.z) compare(window.modelessPopup.visible, true) tryCompare(modelessOverlay, "opacity", 1.0) - compare(window.overlay.children.length, 4) // 2 popups + 2 overlays + compare(window.Overlay.overlay.children.length, 4) // 2 popups + 2 overlays window.modelessPopup.close() tryCompare(window.modelessPopup, "visible", false) modelessOverlay = findOverlay(window, window.modelessPopup) verify(!modelessOverlay) - compare(window.overlay.children.length, 2) // 1 popup + 1 overlay + compare(window.Overlay.overlay.children.length, 2) // 1 popup + 1 overlay compare(window.modalPopup.visible, true) compare(modalOverlay.opacity, 1.0) @@ -1143,29 +1142,29 @@ TestCase { tryCompare(window.modalPopup, "visible", false) modalOverlay = findOverlay(window, window.modalPopup) verify(!modalOverlay) - compare(window.overlay.children.length, 0) + compare(window.Overlay.overlay.children.length, 0) window.plainPopup.open() tryCompare(window.plainPopup, "visible", true) - compare(window.overlay.children.length, 1) // only popup added, no overlays involved + compare(window.Overlay.overlay.children.length, 1) // only popup added, no overlays involved window.plainPopup.modal = true - compare(window.overlay.children.length, 2) // overlay added + compare(window.Overlay.overlay.children.length, 2) // overlay added window.plainPopup.close() tryCompare(window.plainPopup, "visible", false) - compare(window.overlay.children.length, 0) // popup + overlay removed + compare(window.Overlay.overlay.children.length, 0) // popup + overlay removed window.modalPopupWithoutDim.open() tryCompare(window.modalPopupWithoutDim, "visible", true) - compare(window.overlay.children.length, 1) // only popup added, no overlays involved + compare(window.Overlay.overlay.children.length, 1) // only popup added, no overlays involved window.modalPopupWithoutDim.dim = true - compare(window.overlay.children.length, 2) // overlay added + compare(window.Overlay.overlay.children.length, 2) // overlay added window.modalPopupWithoutDim.close() tryCompare(window.modalPopupWithoutDim, "visible", false) - compare(window.overlay.children.length, 0) // popup + overlay removed + compare(window.Overlay.overlay.children.length, 0) // popup + overlay removed } function test_attached_applicationwindow() { diff --git a/tests/auto/qquickapplicationwindow/data/attachedProperties.qml b/tests/auto/qquickapplicationwindow/data/attachedProperties.qml index 53a139c1..fdb349ce 100644 --- a/tests/auto/qquickapplicationwindow/data/attachedProperties.qml +++ b/tests/auto/qquickapplicationwindow/data/attachedProperties.qml @@ -65,7 +65,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } Item { @@ -76,7 +75,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } QtObject { @@ -87,7 +85,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } property alias childWindow: childWindow @@ -103,7 +100,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay Control { id: childWindowControl @@ -113,7 +109,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } Item { @@ -124,7 +119,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } QtObject { @@ -135,7 +129,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } } @@ -152,7 +145,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay Control { id: childAppWindowControl @@ -162,7 +154,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } Item { @@ -173,7 +164,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } QtObject { @@ -184,7 +174,6 @@ ApplicationWindow { property Item attached_activeFocusControl: ApplicationWindow.activeFocusControl property Item attached_header: ApplicationWindow.header property Item attached_footer: ApplicationWindow.footer - property Item attached_overlay: ApplicationWindow.overlay } } } diff --git a/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp b/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp index b907f5c3..baaa3503 100644 --- a/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp +++ b/tests/auto/qquickapplicationwindow/tst_qquickapplicationwindow.cpp @@ -287,7 +287,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QCOMPARE(childControl->property("attached_activeFocusControl").value(), window->activeFocusControl()); QCOMPARE(childControl->property("attached_header").value(), window->header()); QCOMPARE(childControl->property("attached_footer").value(), window->footer()); - QCOMPARE(childControl->property("attached_overlay").value(), window->overlay()); QQuickItem *childItem = object->property("childItem").value(); QVERIFY(childItem); @@ -296,7 +295,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QCOMPARE(childItem->property("attached_activeFocusControl").value(), window->activeFocusControl()); QCOMPARE(childItem->property("attached_header").value(), window->header()); QCOMPARE(childItem->property("attached_footer").value(), window->footer()); - QCOMPARE(childItem->property("attached_overlay").value(), window->overlay()); QObject *childObject = object->property("childObject").value(); QVERIFY(childObject); @@ -305,7 +303,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childObject->property("attached_activeFocusControl").value()); QVERIFY(!childObject->property("attached_header").value()); QVERIFY(!childObject->property("attached_footer").value()); - QVERIFY(!childObject->property("attached_overlay").value()); QQuickWindow *childWindow = object->property("childWindow").value(); QVERIFY(childWindow); @@ -314,7 +311,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childWindow->property("attached_activeFocusControl").value()); QVERIFY(!childWindow->property("attached_header").value()); QVERIFY(!childWindow->property("attached_footer").value()); - QVERIFY(!childWindow->property("attached_overlay").value()); QQuickItem *childWindowControl = object->property("childWindowControl").value(); QVERIFY(childWindowControl); @@ -323,7 +319,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childWindowControl->property("attached_activeFocusControl").value()); QVERIFY(!childWindowControl->property("attached_header").value()); QVERIFY(!childWindowControl->property("attached_footer").value()); - QCOMPARE(childWindowControl->property("attached_overlay").value(), QQuickOverlay::overlay(childWindow)); QQuickItem *childWindowItem = object->property("childWindowItem").value(); QVERIFY(childWindowItem); @@ -332,7 +327,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childWindowItem->property("attached_activeFocusControl").value()); QVERIFY(!childWindowItem->property("attached_header").value()); QVERIFY(!childWindowItem->property("attached_footer").value()); - QCOMPARE(childWindowItem->property("attached_overlay").value(), QQuickOverlay::overlay(childWindow)); QObject *childWindowObject = object->property("childWindowObject").value(); QVERIFY(childWindowObject); @@ -341,7 +335,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childWindowObject->property("attached_activeFocusControl").value()); QVERIFY(!childWindowObject->property("attached_header").value()); QVERIFY(!childWindowObject->property("attached_footer").value()); - QVERIFY(!childWindowObject->property("attached_overlay").value()); QQuickApplicationWindow *childAppWindow = object->property("childAppWindow").value(); QVERIFY(childAppWindow); @@ -350,7 +343,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childAppWindow->property("attached_activeFocusControl").value()); QVERIFY(!childAppWindow->property("attached_header").value()); QVERIFY(!childAppWindow->property("attached_footer").value()); - QVERIFY(!childAppWindow->property("attached_overlay").value()); QQuickItem *childAppWindowControl = object->property("childAppWindowControl").value(); QVERIFY(childAppWindowControl); @@ -359,7 +351,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QCOMPARE(childAppWindowControl->property("attached_activeFocusControl").value(), childAppWindow->activeFocusControl()); QCOMPARE(childAppWindowControl->property("attached_header").value(), childAppWindow->header()); QCOMPARE(childAppWindowControl->property("attached_footer").value(), childAppWindow->footer()); - QCOMPARE(childAppWindowControl->property("attached_overlay").value(), childAppWindow->overlay()); QQuickItem *childAppWindowItem = object->property("childAppWindowItem").value(); QVERIFY(childAppWindowItem); @@ -368,7 +359,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QCOMPARE(childAppWindowItem->property("attached_activeFocusControl").value(), childAppWindow->activeFocusControl()); QCOMPARE(childAppWindowItem->property("attached_header").value(), childAppWindow->header()); QCOMPARE(childAppWindowItem->property("attached_footer").value(), childAppWindow->footer()); - QCOMPARE(childAppWindowItem->property("attached_overlay").value(), childAppWindow->overlay()); QObject *childAppWindowObject = object->property("childAppWindowObject").value(); QVERIFY(childAppWindowObject); @@ -377,7 +367,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childAppWindowObject->property("attached_activeFocusControl").value()); QVERIFY(!childAppWindowObject->property("attached_header").value()); QVERIFY(!childAppWindowObject->property("attached_footer").value()); - QVERIFY(!childAppWindowObject->property("attached_overlay").value()); window->show(); window->requestActivate(); @@ -416,7 +405,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QCOMPARE(childControl->property("attached_activeFocusControl").value(), childAppWindowControl); QCOMPARE(childControl->property("attached_header").value(), childAppWindow->header()); QCOMPARE(childControl->property("attached_footer").value(), childAppWindow->footer()); - QCOMPARE(childControl->property("attached_overlay").value(), childAppWindow->overlay()); childItem->setParentItem(childAppWindow->contentItem()); QCOMPARE(childItem->window(), childAppWindow); @@ -425,7 +413,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QCOMPARE(childItem->property("attached_activeFocusControl").value(), childAppWindowControl); QCOMPARE(childItem->property("attached_header").value(), childAppWindow->header()); QCOMPARE(childItem->property("attached_footer").value(), childAppWindow->footer()); - QCOMPARE(childItem->property("attached_overlay").value(), childAppWindow->overlay()); childControl->setParentItem(nullptr); QVERIFY(!childControl->window()); @@ -434,7 +421,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childControl->property("attached_activeFocusControl").value()); QVERIFY(!childControl->property("attached_header").value()); QVERIFY(!childControl->property("attached_footer").value()); - QVERIFY(!childControl->property("attached_overlay").value()); childItem->setParentItem(nullptr); QVERIFY(!childItem->window()); @@ -443,7 +429,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childItem->property("attached_activeFocusControl").value()); QVERIFY(!childItem->property("attached_header").value()); QVERIFY(!childItem->property("attached_footer").value()); - QVERIFY(!childItem->property("attached_overlay").value()); childAppWindow->close(); qApp->processEvents(); @@ -464,7 +449,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childControl->property("attached_contentItem").value()); QVERIFY(!childControl->property("attached_header").value()); QVERIFY(!childControl->property("attached_footer").value()); - QCOMPARE(childControl->property("attached_overlay").value(), QQuickOverlay::overlay(childWindow)); childItem->setParentItem(childWindow->contentItem()); QCOMPARE(childItem->window(), childWindow); @@ -473,7 +457,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childControl->property("attached_contentItem").value()); QVERIFY(!childControl->property("attached_header").value()); QVERIFY(!childControl->property("attached_footer").value()); - QCOMPARE(childControl->property("attached_overlay").value(), QQuickOverlay::overlay(childWindow)); childControl->setParentItem(nullptr); QVERIFY(!childControl->window()); @@ -482,7 +465,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childControl->property("attached_activeFocusControl").value()); QVERIFY(!childControl->property("attached_header").value()); QVERIFY(!childControl->property("attached_footer").value()); - QVERIFY(!childControl->property("attached_overlay").value()); childItem->setParentItem(nullptr); QVERIFY(!childItem->window()); @@ -491,7 +473,6 @@ void tst_QQuickApplicationWindow::attachedProperties() QVERIFY(!childItem->property("attached_activeFocusControl").value()); QVERIFY(!childItem->property("attached_header").value()); QVERIFY(!childItem->property("attached_footer").value()); - QVERIFY(!childItem->property("attached_overlay").value()); childWindow->close(); } diff --git a/tests/auto/qquickmenu/data/applicationwindow.qml b/tests/auto/qquickmenu/data/applicationwindow.qml index 986853e4..13f14d2d 100644 --- a/tests/auto/qquickmenu/data/applicationwindow.qml +++ b/tests/auto/qquickmenu/data/applicationwindow.qml @@ -59,6 +59,7 @@ ApplicationWindow { property alias emptyMenu: emptyMenu property alias menu: menu property alias menuButton: menuButton + property Overlay overlay: menu.Overlay.overlay Menu { id: emptyMenu diff --git a/tests/auto/qquickmenu/tst_qquickmenu.cpp b/tests/auto/qquickmenu/tst_qquickmenu.cpp index 54a5d9f4..37d1e5ac 100644 --- a/tests/auto/qquickmenu/tst_qquickmenu.cpp +++ b/tests/auto/qquickmenu/tst_qquickmenu.cpp @@ -157,9 +157,12 @@ void tst_QQuickMenu::mouse() QVERIFY(QTest::qWaitForWindowActive(window)); QQuickMenu *menu = window->property("menu").value(); + QVERIFY(menu); menu->open(); QVERIFY(menu->isVisible()); - QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem())); + QQuickOverlay *overlay = window->property("overlay").value(); + QVERIFY(overlay); + QVERIFY(overlay->childItems().contains(menu->contentItem()->parentItem())); QTRY_VERIFY(menu->isOpened()); QQuickItem *firstItem = menu->itemAt(0); @@ -182,14 +185,14 @@ void tst_QQuickMenu::mouse() QCOMPARE(triggeredSpy.count(), 1); QTRY_COMPARE(visibleSpy.count(), 1); QVERIFY(!menu->isVisible()); - QVERIFY(!window->overlay()->childItems().contains(menu->contentItem())); + QVERIFY(!overlay->childItems().contains(menu->contentItem())); QCOMPARE(menu->currentIndex(), -1); QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1)); menu->open(); QCOMPARE(visibleSpy.count(), 2); QVERIFY(menu->isVisible()); - QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem())); + QVERIFY(overlay->childItems().contains(menu->contentItem()->parentItem())); QTRY_VERIFY(menu->isOpened()); // Ensure that we have enough space to click outside of the menu. @@ -199,12 +202,12 @@ void tst_QQuickMenu::mouse() QPoint(menu->contentItem()->width() + 1, menu->contentItem()->height() + 1)); QTRY_COMPARE(visibleSpy.count(), 3); QVERIFY(!menu->isVisible()); - QVERIFY(!window->overlay()->childItems().contains(menu->contentItem()->parentItem())); + QVERIFY(!overlay->childItems().contains(menu->contentItem()->parentItem())); menu->open(); QCOMPARE(visibleSpy.count(), 4); QVERIFY(menu->isVisible()); - QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem())); + QVERIFY(overlay->childItems().contains(menu->contentItem()->parentItem())); QTRY_VERIFY(menu->isOpened()); // Hover-highlight through the menu items one by one @@ -237,7 +240,7 @@ void tst_QQuickMenu::mouse() // QCOMPARE(triggeredSpy.count(), 1); // QCOMPARE(visibleSpy.count(), 5); // QVERIFY(!menu->isVisible()); -// QVERIFY(!window->overlay()->childItems().contains(menu->contentItem())); +// QVERIFY(!overlay->childItems().contains(menu->contentItem())); // QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1)); } @@ -289,7 +292,9 @@ void tst_QQuickMenu::contextMenuKeyboard() menu->open(); QCOMPARE(visibleSpy.count(), 1); QVERIFY(menu->isVisible()); - QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem())); + QQuickOverlay *overlay = window->property("overlay").value(); + QVERIFY(overlay); + QVERIFY(overlay->childItems().contains(menu->contentItem()->parentItem())); QTRY_VERIFY(menu->isOpened()); QVERIFY(!firstItem->hasActiveFocus()); QVERIFY(!firstItem->property("highlighted").toBool()); @@ -322,7 +327,7 @@ void tst_QQuickMenu::contextMenuKeyboard() QCOMPARE(secondTriggeredSpy.count(), 1); QTRY_COMPARE(visibleSpy.count(), 2); QVERIFY(!menu->isVisible()); - QVERIFY(!window->overlay()->childItems().contains(menu->contentItem())); + QVERIFY(!overlay->childItems().contains(menu->contentItem())); QVERIFY(!firstItem->hasActiveFocus()); QVERIFY(!firstItem->hasVisualFocus()); QVERIFY(!firstItem->isHighlighted()); @@ -352,7 +357,7 @@ void tst_QQuickMenu::contextMenuKeyboard() QCOMPARE(firstTriggeredSpy.count(), 1); QTRY_COMPARE(visibleSpy.count(), 4); QVERIFY(!menu->isVisible()); - QVERIFY(!window->overlay()->childItems().contains(menu->contentItem())); + QVERIFY(!overlay->childItems().contains(menu->contentItem())); QVERIFY(!firstItem->hasActiveFocus()); QVERIFY(!firstItem->hasVisualFocus()); QVERIFY(!firstItem->isHighlighted()); @@ -365,7 +370,7 @@ void tst_QQuickMenu::contextMenuKeyboard() menu->open(); QCOMPARE(visibleSpy.count(), 5); QVERIFY(menu->isVisible()); - QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem())); + QVERIFY(overlay->childItems().contains(menu->contentItem()->parentItem())); QTRY_VERIFY(menu->isOpened()); QVERIFY(!firstItem->hasActiveFocus()); QVERIFY(!firstItem->hasVisualFocus()); -- cgit v1.2.3 From 2104dcd828d7c3da23300014fdddbc63f9c23cb3 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 9 Jun 2020 11:59:29 +0200 Subject: Use QList instead of QVector Task-number: QTBUG-84469 Change-Id: Ic36741d2bcaec8d5e5dc96638b7122f8ce51bdb2 Reviewed-by: Mitch Curtis --- tests/auto/qquickheaderview/tst_qquickheaderview.cpp | 2 +- tests/auto/qquickiconlabel/tst_qquickiconlabel.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/qquickheaderview/tst_qquickheaderview.cpp b/tests/auto/qquickheaderview/tst_qquickheaderview.cpp index 611e39cb..d8d71183 100644 --- a/tests/auto/qquickheaderview/tst_qquickheaderview.cpp +++ b/tests/auto/qquickheaderview/tst_qquickheaderview.cpp @@ -203,7 +203,7 @@ public: } private: - QVector hData, vData; + QList hData, vData; }; class tst_QQuickHeaderView : public QQmlDataTest { diff --git a/tests/auto/qquickiconlabel/tst_qquickiconlabel.cpp b/tests/auto/qquickiconlabel/tst_qquickiconlabel.cpp index 0ecc95c5..7a1cb259 100644 --- a/tests/auto/qquickiconlabel/tst_qquickiconlabel.cpp +++ b/tests/auto/qquickiconlabel/tst_qquickiconlabel.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include +#include #include @@ -64,13 +64,13 @@ tst_qquickiconlabel::tst_qquickiconlabel() void tst_qquickiconlabel::display_data() { - QTest::addColumn >("displayTypes"); + QTest::addColumn >("displayTypes"); QTest::addColumn("mirrored"); QTest::addColumn("labelWidth"); QTest::addColumn("labelHeight"); QTest::addColumn("spacing"); - typedef QVector DisplayVector; + typedef QList DisplayVector; QQuickIconLabel::Display IconOnly = QQuickIconLabel::IconOnly; QQuickIconLabel::Display TextOnly = QQuickIconLabel::TextOnly; QQuickIconLabel::Display TextUnderIcon = QQuickIconLabel::TextUnderIcon; @@ -108,7 +108,7 @@ void tst_qquickiconlabel::display_data() void tst_qquickiconlabel::display() { - QFETCH(QVector, displayTypes); + QFETCH(QList, displayTypes); QFETCH(bool, mirrored); QFETCH(qreal, labelWidth); QFETCH(qreal, labelHeight); -- cgit v1.2.3 From 4f84ebeedf679ccf49ebf0aaf0d12459190b6265 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Tue, 2 Jun 2020 15:26:29 +0200 Subject: Qt6: Port QtQuickControls2 to QStringView Task-number: QTBUG-84319 Change-Id: I7aaae36df79b1a935a3c4d31039cb880405f0d63 Reviewed-by: Mitch Curtis --- tests/auto/sanity/tst_sanity.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/sanity/tst_sanity.cpp b/tests/auto/sanity/tst_sanity.cpp index b5d0054b..35c48970 100644 --- a/tests/auto/sanity/tst_sanity.cpp +++ b/tests/auto/sanity/tst_sanity.cpp @@ -211,9 +211,9 @@ void tst_Sanity::functions_data() class SignalHandlerValidator : public BaseValidator { protected: - static bool isSignalHandler(const QStringRef &name) + static bool isSignalHandler(QStringView name) { - return name.length() > 2 && name.startsWith("on") && name.at(2).isUpper(); + return name.length() > 2 && name.startsWith(QLatin1String("on")) && name.at(2).isUpper(); } virtual bool visit(QQmlJS::AST::UiScriptBinding *node) -- cgit v1.2.3 From 969a724352dfe3250efb871c70f9482d7b780165 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 5 Jun 2020 10:28:16 +0200 Subject: QQuickApplicationHelper: don't use QTest macros outside test functions This has no effect. Task-number: QTBUG-66320 Pick-to: 5.15 5.12 Change-Id: Ie6efb26243178c4044ac0bc721c21ad89769c982 Reviewed-by: Richard Moe Gustavsen --- tests/auto/cursor/tst_cursor.cpp | 1 + tests/auto/qquickdrawer/tst_qquickdrawer.cpp | 18 +++++++++++ .../tst_qquickmaterialstyleconf.cpp | 2 ++ tests/auto/qquickmenu/tst_qquickmenu.cpp | 27 +++++++++++++++++ tests/auto/qquickpopup/tst_qquickpopup.cpp | 24 +++++++++++++++ .../tst_qquickuniversalstyleconf.cpp | 1 + tests/auto/shared/visualtestutil.h | 35 ++++++++++++++++++---- 7 files changed, 103 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/cursor/tst_cursor.cpp b/tests/auto/cursor/tst_cursor.cpp index 2491a972..ed5db5b1 100644 --- a/tests/auto/cursor/tst_cursor.cpp +++ b/tests/auto/cursor/tst_cursor.cpp @@ -182,6 +182,7 @@ void tst_cursor::scrollBar() // Ensure that the mouse cursor has the correct shape when over a scrollbar // which is itself over a text area with IBeamCursor. QQuickApplicationHelper helper(this, QStringLiteral("scrollbar.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); diff --git a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp index 7644cacf..108cd4a1 100644 --- a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp +++ b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp @@ -180,6 +180,7 @@ void tst_QQuickDrawer::visible() { QFETCH(QString, source); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -220,6 +221,7 @@ void tst_QQuickDrawer::visible() void tst_QQuickDrawer::state() { QQuickApplicationHelper helper(this, "applicationwindow.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -340,6 +342,7 @@ void tst_QQuickDrawer::position() QFETCH(qreal, position); QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); @@ -387,6 +390,7 @@ void tst_QQuickDrawer::dragMargin() QFETCH(qreal, dragFromRight); QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); @@ -433,6 +437,7 @@ static QRectF geometry(const QQuickItem *item) void tst_QQuickDrawer::reposition() { QQuickApplicationHelper helper(this, QStringLiteral("reposition.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); @@ -491,6 +496,7 @@ void tst_QQuickDrawer::reposition() void tst_QQuickDrawer::header() { QQuickApplicationHelper helper(this, QStringLiteral("header.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); @@ -545,6 +551,7 @@ void tst_QQuickDrawer::hover() QFETCH(bool, modal); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); window->requestActivate(); @@ -628,6 +635,7 @@ void tst_QQuickDrawer::wheel() QFETCH(bool, modal); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -690,6 +698,7 @@ void tst_QQuickDrawer::wheel() void tst_QQuickDrawer::multiple() { QQuickApplicationHelper helper(this, QStringLiteral("multiple.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -834,6 +843,7 @@ void tst_QQuickDrawer::touch() QFETCH(QPoint, to); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -868,6 +878,7 @@ void tst_QQuickDrawer::touch() void tst_QQuickDrawer::multiTouch() { QQuickApplicationHelper helper(this, QStringLiteral("multiTouch.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -981,6 +992,7 @@ void tst_QQuickDrawer::multiTouch() void tst_QQuickDrawer::grabber() { QQuickApplicationHelper helper(this, QStringLiteral("grabber.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -1025,6 +1037,7 @@ void tst_QQuickDrawer::interactive() { QFETCH(QString, source); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -1087,6 +1100,7 @@ void tst_QQuickDrawer::flickable() QFETCH(QPoint, to); QQuickApplicationHelper helper(this, QStringLiteral("flickable.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -1143,6 +1157,7 @@ void tst_QQuickDrawer::dragOverModalShadow() QFETCH(bool, mouse); QQuickApplicationHelper helper(this, QStringLiteral("dragOverModalShadow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1199,6 +1214,7 @@ void tst_QQuickDrawer::nonModal() QFETCH(bool, mouse); QQuickApplicationHelper helper(this, QStringLiteral("window.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1282,6 +1298,7 @@ void tst_QQuickDrawer::slider() QFETCH(int, delta); QQuickApplicationHelper helper(this, QStringLiteral("slider.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1325,6 +1342,7 @@ void tst_QQuickDrawer::slider() void tst_QQuickDrawer::topEdgeScreenEdge() { QQuickApplicationHelper helper(this, QStringLiteral("topEdgeScreenEdge.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); diff --git a/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp b/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp index 72136445..7612b99b 100644 --- a/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp +++ b/tests/auto/qquickmaterialstyleconf/tst_qquickmaterialstyleconf.cpp @@ -57,6 +57,7 @@ private slots: void tst_qquickmaterialstyleconf::conf() { QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QFont customFont; customFont.setFamily("Courier"); @@ -101,6 +102,7 @@ void tst_qquickmaterialstyleconf::variants() qputenv("QT_QUICK_CONTROLS_CONF", confPath); QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); diff --git a/tests/auto/qquickmenu/tst_qquickmenu.cpp b/tests/auto/qquickmenu/tst_qquickmenu.cpp index 37d1e5ac..9d29c675 100644 --- a/tests/auto/qquickmenu/tst_qquickmenu.cpp +++ b/tests/auto/qquickmenu/tst_qquickmenu.cpp @@ -106,6 +106,7 @@ private slots: void tst_QQuickMenu::defaults() { QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickMenu *emptyMenu = helper.appWindow->property("emptyMenu").value(); QCOMPARE(emptyMenu->isVisible(), false); @@ -117,6 +118,7 @@ void tst_QQuickMenu::defaults() void tst_QQuickMenu::count() { QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickMenu *menu = helper.window->property("emptyMenu").value(); QVERIFY(menu); @@ -149,6 +151,7 @@ void tst_QQuickMenu::mouse() QSKIP("Mouse hovering not functional on offscreen/minimal platforms"); QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); @@ -247,6 +250,7 @@ void tst_QQuickMenu::mouse() void tst_QQuickMenu::pressAndHold() { QQuickApplicationHelper helper(this, QLatin1String("pressAndHold.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -271,6 +275,7 @@ void tst_QQuickMenu::contextMenuKeyboard() QSKIP("This platform only allows tab focus for text controls"); QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); @@ -456,6 +461,7 @@ void tst_QQuickMenu::disabledMenuItemKeyNavigation() QSKIP("This platform only allows tab focus for text controls"); QQuickApplicationHelper helper(this, QLatin1String("disabledMenuItemKeyNavigation.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); @@ -520,6 +526,7 @@ void tst_QQuickMenu::mnemonics() #endif QQuickApplicationHelper helper(this, QLatin1String("mnemonics.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -567,6 +574,7 @@ void tst_QQuickMenu::menuButton() QSKIP("This platform only allows tab focus for text controls"); QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); @@ -593,6 +601,7 @@ void tst_QQuickMenu::menuButton() void tst_QQuickMenu::addItem() { QQuickApplicationHelper helper(this, QLatin1String("addItem.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -614,6 +623,7 @@ void tst_QQuickMenu::addItem() void tst_QQuickMenu::menuSeparator() { QQuickApplicationHelper helper(this, QLatin1String("menuSeparator.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; centerOnScreen(window); moveMouseAway(window); @@ -691,6 +701,7 @@ void tst_QQuickMenu::menuSeparator() void tst_QQuickMenu::repeater() { QQuickApplicationHelper helper(this, QLatin1String("repeater.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -735,6 +746,7 @@ void tst_QQuickMenu::repeater() void tst_QQuickMenu::order() { QQuickApplicationHelper helper(this, QLatin1String("order.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -756,6 +768,7 @@ void tst_QQuickMenu::order() void tst_QQuickMenu::popup() { QQuickApplicationHelper helper(this, QLatin1String("popup.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); moveMouseAway(window); @@ -912,6 +925,7 @@ void tst_QQuickMenu::popup() void tst_QQuickMenu::actions() { QQuickApplicationHelper helper(this, QLatin1String("actions.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -980,6 +994,7 @@ void tst_QQuickMenu::actions() void tst_QQuickMenu::removeTakeItem() { QQuickApplicationHelper helper(this, QLatin1String("removeTakeItem.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1037,6 +1052,7 @@ void tst_QQuickMenu::subMenuMouse() QFETCH(bool, cascade); QQuickApplicationHelper helper(this, QLatin1String("subMenus.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); moveMouseAway(window); @@ -1143,6 +1159,7 @@ void tst_QQuickMenu::subMenuDisabledMouse() QFETCH(bool, cascade); QQuickApplicationHelper helper(this, QLatin1String("subMenuDisabled.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); moveMouseAway(window); @@ -1205,6 +1222,7 @@ void tst_QQuickMenu::subMenuKeyboard() QFETCH(bool, mirrored); QQuickApplicationHelper helper(this, QLatin1String("subMenus.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); moveMouseAway(window); @@ -1327,6 +1345,7 @@ void tst_QQuickMenu::subMenuDisabledKeyboard() QFETCH(bool, mirrored); QQuickApplicationHelper helper(this, QLatin1String("subMenuDisabled.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); moveMouseAway(window); @@ -1403,6 +1422,7 @@ void tst_QQuickMenu::subMenuPosition() QFETCH(qreal, overlap); QQuickApplicationHelper helper(this, QLatin1String("subMenus.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; // Ensure that the default size of the window fits three menus side by side. @@ -1524,6 +1544,7 @@ void tst_QQuickMenu::subMenuPosition() void tst_QQuickMenu::addRemoveSubMenus() { QQuickApplicationHelper helper(this, QLatin1String("subMenus.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1595,6 +1616,7 @@ void tst_QQuickMenu::scrollable() QFETCH(QString, qmlFilePath); QQuickApplicationHelper helper(this, qmlFilePath); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1634,6 +1656,7 @@ void tst_QQuickMenu::disableWhenTriggered() QFETCH(int, subMenuItemIndex); QQuickApplicationHelper helper(this, QLatin1String("disableWhenTriggered.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1689,6 +1712,7 @@ void tst_QQuickMenu::menuItemWidth() QFETCH(bool, mirrored); QQuickApplicationHelper helper(this, QLatin1String("menuItemWidths.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1717,6 +1741,7 @@ void tst_QQuickMenu::menuItemWidthAfterMenuWidthChanged() QFETCH(bool, mirrored); QQuickApplicationHelper helper(this, QLatin1String("menuItemWidths.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1761,6 +1786,7 @@ void tst_QQuickMenu::menuItemWidthAfterImplicitWidthChanged() QFETCH(bool, mirrored); QQuickApplicationHelper helper(this, QLatin1String("menuItemWidths.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1791,6 +1817,7 @@ void tst_QQuickMenu::menuItemWidthAfterImplicitWidthChanged() void tst_QQuickMenu::menuItemWidthAfterRetranslate() { QQuickApplicationHelper helper(this, QLatin1String("menuItemWidths.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp index 162a48ba..184d8ad8 100644 --- a/tests/auto/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp @@ -118,6 +118,7 @@ void tst_QQuickPopup::visible() { QFETCH(QString, source); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -151,6 +152,7 @@ void tst_QQuickPopup::visible() void tst_QQuickPopup::state() { QQuickApplicationHelper helper(this, "applicationwindow.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -212,6 +214,7 @@ void tst_QQuickPopup::overlay() QFETCH(bool, dim); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -374,6 +377,7 @@ void tst_QQuickPopup::zOrder() { QFETCH(QString, source); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -483,6 +487,7 @@ void tst_QQuickPopup::closePolicy() QFETCH(QQuickPopup::ClosePolicy, closePolicy); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -567,6 +572,7 @@ void tst_QQuickPopup::activeFocusOnClose1() // Test that a popup that never sets focus: true (e.g. ToolTip) doesn't affect // the active focus item when it closes. QQuickApplicationHelper helper(this, QStringLiteral("activeFocusOnClose1.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); window->requestActivate(); @@ -610,6 +616,7 @@ void tst_QQuickPopup::activeFocusOnClose2() // calling forceActiveFocus() on another item) before it closes doesn't // affect the active focus item when it closes. QQuickApplicationHelper helper(this, QStringLiteral("activeFocusOnClose2.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); window->requestActivate(); @@ -646,6 +653,7 @@ void tst_QQuickPopup::activeFocusOnClose3() // Test that a closing popup that had focus doesn't steal focus from // another popup that the focus was transferred to. QQuickApplicationHelper helper(this, QStringLiteral("activeFocusOnClose3.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); window->requestActivate(); @@ -677,6 +685,7 @@ void tst_QQuickPopup::activeFocusOnClosingSeveralPopups() { // Test that active focus isn't lost when multiple popup closing simultaneously QQuickApplicationHelper helper(this, QStringLiteral("activeFocusOnClosingSeveralPopups.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); window->requestActivate(); @@ -738,6 +747,7 @@ void tst_QQuickPopup::hover() QFETCH(bool, modal); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); window->requestActivate(); @@ -812,6 +822,7 @@ void tst_QQuickPopup::wheel() QFETCH(bool, modal); QQuickApplicationHelper helper(this, source); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -882,6 +893,7 @@ void tst_QQuickPopup::parentDestroyed() void tst_QQuickPopup::nested() { QQuickApplicationHelper helper(this, QStringLiteral("nested.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -909,6 +921,7 @@ void tst_QQuickPopup::nested() void tst_QQuickPopup::grabber() { QQuickApplicationHelper helper(this, QStringLiteral("grabber.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -961,6 +974,7 @@ void tst_QQuickPopup::cursorShape() // Ensure that the mouse cursor has the correct shape when over a popup // which is itself over an item with a different shape. QQuickApplicationHelper helper(this, QStringLiteral("cursor.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; centerOnScreen(window); moveMouseAway(window); @@ -1018,6 +1032,7 @@ void tst_QQuickPopup::closeOnEscapeWithNestedPopups() // Tests the scenario in the Gallery example, where there are nested popups that should // close in the correct order when the Escape key is pressed. QQuickApplicationHelper helper(this, QStringLiteral("closeOnEscapeWithNestedPopups.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -1081,6 +1096,7 @@ void tst_QQuickPopup::closeOnEscapeWithNestedPopups() void tst_QQuickPopup::closeOnEscapeWithVisiblePopup() { QQuickApplicationHelper helper(this, QStringLiteral("closeOnEscapeWithVisiblePopup.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -1131,6 +1147,7 @@ void tst_QQuickPopup::orientation() QFETCH(QPointF, position); QQuickApplicationHelper helper(this, "orientation.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->reportContentOrientationChange(orientation); @@ -1170,6 +1187,7 @@ void tst_QQuickPopup::qquickview() void tst_QQuickPopup::disabledPalette() { QQuickApplicationHelper helper(this, "disabledPalette.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -1206,6 +1224,7 @@ void tst_QQuickPopup::disabledPalette() void tst_QQuickPopup::disabledParentPalette() { QQuickApplicationHelper helper(this, "disabledPalette.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -1251,6 +1270,7 @@ void tst_QQuickPopup::disabledParentPalette() void tst_QQuickPopup::countChanged() { QQuickApplicationHelper helper(this, "countChanged.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -1273,6 +1293,7 @@ void tst_QQuickPopup::toolTipCrashOnClose() QSKIP("Test requires QtGraphicalEffects"); QQuickApplicationHelper helper(this, "toolTipCrashOnClose.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -1293,6 +1314,7 @@ void tst_QQuickPopup::setOverlayParentToNull() QSKIP("Test requires QtGraphicalEffects"); QQuickApplicationHelper helper(this, "toolTipCrashOnClose.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -1313,6 +1335,7 @@ void tst_QQuickPopup::tabFence() QSKIP("This platform only allows tab focus for text controls"); QQuickApplicationHelper helper(this, "tabFence.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; window->show(); @@ -1366,6 +1389,7 @@ void tst_QQuickPopup::tabFence() void tst_QQuickPopup::invisibleToolTipOpen() { QQuickApplicationHelper helper(this, "invisibleToolTipOpen.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); QQuickWindow *window = helper.window; centerOnScreen(window); diff --git a/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp b/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp index 51cc5883..08eae67c 100644 --- a/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp +++ b/tests/auto/qquickuniversalstyleconf/tst_qquickuniversalstyleconf.cpp @@ -54,6 +54,7 @@ private slots: void tst_qquickuniversalstyleconf::conf() { QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); QFont customFont; customFont.setFamily("Courier"); diff --git a/tests/auto/shared/visualtestutil.h b/tests/auto/shared/visualtestutil.h index d5e651c5..e3f4075d 100644 --- a/tests/auto/shared/visualtestutil.h +++ b/tests/auto/shared/visualtestutil.h @@ -122,19 +122,44 @@ namespace QQuickVisualTestUtil component.loadUrl(testCase->testFileUrl(testFilePath)); QObject *rootObject = component.create(); cleanup.reset(rootObject); - QVERIFY2(rootObject, qPrintable(QString::fromLatin1("Failed to create window: %1").arg(component.errorString()))); + if (!rootObject) { + errorMessage = QString::fromUtf8("Failed to create window: %1").arg(component.errorString()).toUtf8(); + return; + } window = qobject_cast(rootObject); appWindow = qobject_cast(rootObject); - QVERIFY(window); - QVERIFY(!window->isVisible()); + if (!window) { + errorMessage = QString::fromUtf8("Root object %1 must be a QQuickWindow subclass").arg(QDebug::toString(window)).toUtf8(); + return; + } + + if (window->isVisible()) { + errorMessage = QString::fromUtf8("Expected window not to be visible, but it is").toUtf8(); + return; + } + + ready = true; + } + + // Return a C-style string instead of QString because that's what QTest uses for error messages, + // so it saves code at the calling site. + inline const char *failureMessage() const + { + return errorMessage.constData(); } QQmlEngine engine; QQmlComponent component; QScopedPointer cleanup; - QQuickApplicationWindow *appWindow; - QQuickWindow *window; + QQuickApplicationWindow *appWindow = nullptr; + QQuickWindow *window = nullptr; + + bool ready = false; + // Store as a byte array so that we can return its raw data safely; + // using qPrintable() in failureMessage() will construct a throwaway QByteArray + // that is destroyed before the function returns. + QByteArray errorMessage; }; void addTestRowForEachControl(QQmlEngine *engine, const QString &sourcePath, const QString &targetPath, const QStringList &skiplist = QStringList()); -- cgit v1.2.3 From b60c02ce7d2d34eae63c78f77c0e59c09dda2212 Mon Sep 17 00:00:00 2001 From: Qt Submodule Update Bot Date: Thu, 25 Jun 2020 14:45:57 +0300 Subject: Update dependencies on 'dev' in qt/qtquickcontrols2 Change-Id: I1f6bf96f30f5dcea4d9838b0638f9412309a069e Reviewed-by: Qt CI Bot Reviewed-by: Liang Qi --- tests/auto/focus/tst_focus.cpp | 28 +++----------------------- tests/auto/qquickcontrol/tst_qquickcontrol.cpp | 15 ++------------ tests/auto/qquickdrawer/tst_qquickdrawer.cpp | 17 +++------------- tests/auto/qquickpopup/tst_qquickpopup.cpp | 13 +----------- 4 files changed, 9 insertions(+), 64 deletions(-) (limited to 'tests') diff --git a/tests/auto/focus/tst_focus.cpp b/tests/auto/focus/tst_focus.cpp index 8a1b36ad..b1b23244 100644 --- a/tests/auto/focus/tst_focus.cpp +++ b/tests/auto/focus/tst_focus.cpp @@ -43,8 +43,8 @@ #include #include #include +#include #include -#include #include "../shared/util.h" #include "../shared/visualtestutil.h" @@ -159,18 +159,7 @@ void tst_focus::policy() window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window.data())); - struct TouchDeviceDeleter - { - static inline void cleanup(QTouchDevice *device) - { - QWindowSystemInterface::unregisterTouchDevice(device); - delete device; - } - }; - - QScopedPointer device(new QTouchDevice); - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device.data()); + QScopedPointer device(QTest::createTouchDevice()); control->setFocusPolicy(Qt::NoFocus); QCOMPARE(control->focusPolicy(), Qt::NoFocus); @@ -366,18 +355,7 @@ void tst_focus::scope() window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window.data())); - struct TouchDeviceDeleter - { - static inline void cleanup(QTouchDevice *device) - { - QWindowSystemInterface::unregisterTouchDevice(device); - delete device; - } - }; - - QScopedPointer device(new QTouchDevice); - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device.data()); + QScopedPointer device(QTest::createTouchDevice()); child->forceActiveFocus(); QVERIFY(child->hasActiveFocus()); diff --git a/tests/auto/qquickcontrol/tst_qquickcontrol.cpp b/tests/auto/qquickcontrol/tst_qquickcontrol.cpp index c8d34756..6acb192f 100644 --- a/tests/auto/qquickcontrol/tst_qquickcontrol.cpp +++ b/tests/auto/qquickcontrol/tst_qquickcontrol.cpp @@ -53,16 +53,7 @@ private slots: void flickable(); private: - struct TouchDeviceDeleter - { - static inline void cleanup(QTouchDevice *device) - { - QWindowSystemInterface::unregisterTouchDevice(device); - delete device; - } - }; - - QScopedPointer touchDevice; + QScopedPointer touchDevice; }; @@ -71,9 +62,7 @@ void tst_QQuickControl::initTestCase() QQmlDataTest::initTestCase(); qputenv("QML_NO_TOUCH_COMPRESSION", "1"); - touchDevice.reset(new QTouchDevice); - touchDevice->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(touchDevice.data()); + touchDevice.reset(QTest::createTouchDevice()); } void tst_QQuickControl::flickable() diff --git a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp index 108cd4a1..c96b156c 100644 --- a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp +++ b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp @@ -40,8 +40,8 @@ #include "../shared/visualtestutil.h" #include "../shared/qtest_quickcontrols.h" +#include #include -#include #include #include #include @@ -112,16 +112,7 @@ private slots: void topEdgeScreenEdge(); private: - struct TouchDeviceDeleter - { - static inline void cleanup(QTouchDevice *device) - { - QWindowSystemInterface::unregisterTouchDevice(device); - delete device; - } - }; - - QScopedPointer touchDevice; + QScopedPointer touchDevice; }; @@ -130,9 +121,7 @@ void tst_QQuickDrawer::initTestCase() QQmlDataTest::initTestCase(); qputenv("QML_NO_TOUCH_COMPRESSION", "1"); - touchDevice.reset(new QTouchDevice); - touchDevice->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(touchDevice.data()); + touchDevice.reset(QTest::createTouchDevice()); } void tst_QQuickDrawer::defaults() diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp index 184d8ad8..30a21b9f 100644 --- a/tests/auto/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp @@ -303,18 +303,7 @@ void tst_QQuickPopup::overlay() QVERIFY(popup->isVisible()); QVERIFY(overlay->isVisible()); - struct TouchDeviceDeleter - { - static inline void cleanup(QTouchDevice *device) - { - QWindowSystemInterface::unregisterTouchDevice(device); - delete device; - } - }; - - QScopedPointer device(new QTouchDevice); - device->setType(QTouchDevice::TouchScreen); - QWindowSystemInterface::registerTouchDevice(device.data()); + QScopedPointer device(QTest::createTouchDevice()); QTest::touchEvent(window, device.data()).press(0, QPoint(1, 1)); QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); -- cgit v1.2.3 From d9f60a2560143008336439ebc8a9399cd5bda7b4 Mon Sep 17 00:00:00 2001 From: Lars Schmertmann Date: Sat, 27 Jun 2020 12:57:47 +0200 Subject: Add ; to Q_UNUSED This is required to remove the ; from the macro with Qt 6. Task-number: QTBUG-82978 Change-Id: I92ef02ede041d3965151165a479a1ea0549cc0f9 Reviewed-by: Shawn Rutledge Reviewed-by: Volker Hilsheimer --- tests/auto/accessibility/tst_accessibility.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/accessibility/tst_accessibility.cpp b/tests/auto/accessibility/tst_accessibility.cpp index 220facb3..3d9a318d 100644 --- a/tests/auto/accessibility/tst_accessibility.cpp +++ b/tests/auto/accessibility/tst_accessibility.cpp @@ -177,8 +177,8 @@ void tst_accessibility::a11y() QCOMPARE(attached->role(), role); QCOMPARE(attached->name(), text); #else - Q_UNUSED(role) - Q_UNUSED(text) + Q_UNUSED(role); + Q_UNUSED(text); #endif } @@ -264,8 +264,8 @@ void tst_accessibility::override() QCOMPARE(attached->role(), role); QCOMPARE(attached->name(), name + "Override"); #else - Q_UNUSED(role) - Q_UNUSED(text) + Q_UNUSED(role); + Q_UNUSED(text); #endif } -- cgit v1.2.3 From 0000e502a401fb6d44fbf6f52435ba4b6343dd83 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 30 Jun 2020 12:05:03 +0200 Subject: tst_designer: fix QByteArray::append() compile error The overload taking a QString was removed, but is equivalent to passing the result of toUtf8(). Change-Id: I6edbbc78ce20eb1ed23dc77583342fc31ec86408 Reviewed-by: Sona Kurazyan --- tests/auto/designer/tst_designer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/designer/tst_designer.cpp b/tests/auto/designer/tst_designer.cpp index 2c67c2c6..0d8bc73b 100644 --- a/tests/auto/designer/tst_designer.cpp +++ b/tests/auto/designer/tst_designer.cpp @@ -101,7 +101,7 @@ void tst_Designer::test_controls() "Item {\n"); QByteArray source = before; - source.append(type); + source.append(type.toUtf8()); const QByteArray after(" {" "}\n" -- cgit v1.2.3 From ab5fee7aa22c2630970734359062dfef03ca9b22 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 9 Jul 2020 14:27:32 +0200 Subject: Use QList instead of QVector Task-number: QTBUG-84469 Change-Id: I4991ab7ce8ba8d2522005b1b0a78f7b474c54419 Reviewed-by: Mitch Curtis --- tests/manual/gifs/eventcapturer.cpp | 4 ++-- tests/manual/gifs/eventcapturer.h | 6 +++--- tests/manual/gifs/tst_gifs.cpp | 20 ++++++++++---------- tests/manual/headerview/main.cpp | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/manual/gifs/eventcapturer.cpp b/tests/manual/gifs/eventcapturer.cpp index b3bbd7c8..ad88b1db 100644 --- a/tests/manual/gifs/eventcapturer.cpp +++ b/tests/manual/gifs/eventcapturer.cpp @@ -124,7 +124,7 @@ void EventCapturer::setCapturedEventTypes(QSet types) mCapturedEventTypes = types; } -QVector EventCapturer::capturedEvents() const +QList EventCapturer::capturedEvents() const { if (mMoveEventTrimFlags == TrimNone || mEvents.isEmpty()) return mEvents; @@ -167,7 +167,7 @@ QVector EventCapturer::capturedEvents() const // the indices are still valid - we could be removing from the middle of // the commands next. Also, the function is const, so we can't remove from // mEvents anyway. :) - QVector events = mEvents.mid(firstEventIndex, (lastEventIndex - firstEventIndex) + 1); + QList events = mEvents.mid(firstEventIndex, (lastEventIndex - firstEventIndex) + 1); if (mMoveEventTrimFlags.testFlag(TrimAfterReleases)) { bool lastNonMoveEventWasRelease = false; diff --git a/tests/manual/gifs/eventcapturer.h b/tests/manual/gifs/eventcapturer.h index e2b8b3a4..ea01299f 100644 --- a/tests/manual/gifs/eventcapturer.h +++ b/tests/manual/gifs/eventcapturer.h @@ -40,9 +40,9 @@ #include #include #include +#include #include #include -#include #include "capturedevent.h" @@ -72,7 +72,7 @@ public: QSet capturedEventTypes(); void setCapturedEventTypes(QSet types); - QVector capturedEvents() const; + QList capturedEvents() const; protected: bool eventFilter(QObject *object, QEvent *event) override; @@ -87,7 +87,7 @@ private: Qt::Key mStopCaptureKey; MoveEventTrimFlags mMoveEventTrimFlags; QElapsedTimer mDelayTimer; - QVector mEvents; + QList mEvents; int mDuration; int mLastCaptureTime; }; diff --git a/tests/manual/gifs/tst_gifs.cpp b/tests/manual/gifs/tst_gifs.cpp index d7d8f98d..80c3fd9f 100644 --- a/tests/manual/gifs/tst_gifs.cpp +++ b/tests/manual/gifs/tst_gifs.cpp @@ -609,19 +609,19 @@ void tst_Gifs::swipeDelegateBehind() void tst_Gifs::delegates_data() { QTest::addColumn("name"); - QTest::addColumn >("pressIndices"); + QTest::addColumn >("pressIndices"); QTest::addColumn("duration"); - QTest::newRow("ItemDelegate") << "itemdelegate" << (QVector() << 0 << 1 << 2) << 5; - QTest::newRow("CheckDelegate") << "checkdelegate" << (QVector() << 0 << 0) << 5; - QTest::newRow("RadioDelegate") << "radiodelegate" << (QVector() << 1 << 0) << 5; - QTest::newRow("SwitchDelegate") << "switchdelegate" << (QVector() << 0 << 0) << 5; + QTest::newRow("ItemDelegate") << "itemdelegate" << (QList { 0, 1, 2 }) << 5; + QTest::newRow("CheckDelegate") << "checkdelegate" << (QList { 0, 0 }) << 5; + QTest::newRow("RadioDelegate") << "radiodelegate" << (QList { 1, 0 }) << 5; + QTest::newRow("SwitchDelegate") << "switchdelegate" << (QList { 0, 0 }) << 5; } void tst_Gifs::delegates() { QFETCH(QString, name); - QFETCH(QVector, pressIndices); + QFETCH(QList, pressIndices); QFETCH(int, duration); GifRecorder gifRecorder; @@ -710,16 +710,16 @@ void tst_Gifs::dial() void tst_Gifs::checkables_data() { QTest::addColumn("name"); - QTest::addColumn >("pressIndices"); + QTest::addColumn >("pressIndices"); - QTest::newRow("checkbox") << "checkbox" << (QVector() << 1 << 2 << 2 << 1); - QTest::newRow("radiobutton") << "radiobutton" << (QVector() << 1 << 2 << 1 << 0); + QTest::newRow("checkbox") << "checkbox" << (QList { 1, 2, 2, 1 }); + QTest::newRow("radiobutton") << "radiobutton" << (QList { 1, 2, 1, 0 }); } void tst_Gifs::checkables() { QFETCH(QString, name); - QFETCH(QVector, pressIndices); + QFETCH(QList, pressIndices); GifRecorder gifRecorder; gifRecorder.setDataDirPath(dataDirPath); diff --git a/tests/manual/headerview/main.cpp b/tests/manual/headerview/main.cpp index 4c1e611c..b1573f08 100644 --- a/tests/manual/headerview/main.cpp +++ b/tests/manual/headerview/main.cpp @@ -199,7 +199,7 @@ public: } private: - QVector hData, vData; + QList hData, vData; }; int main(int argc, char *argv[]) -- cgit v1.2.3 From 937cace287cf852a169f5553b715e398d09d5488 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 13 Jul 2020 14:56:56 +0200 Subject: Replace QDesktopWidget with QScreen in manual test Change-Id: I09b9b01494575b78af8ab11d33a2ea511efc5526 Reviewed-by: Mitch Curtis --- tests/manual/viewinqwidget/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/manual/viewinqwidget/main.cpp b/tests/manual/viewinqwidget/main.cpp index 80cbb415..b6b7a5ff 100644 --- a/tests/manual/viewinqwidget/main.cpp +++ b/tests/manual/viewinqwidget/main.cpp @@ -38,9 +38,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) vLayout->addWidget(container); hLayout->addWidget(groupBox); - const QRect availableGeometry = QApplication::desktop()->availableGeometry(&widget); + const QRect availableGeometry = widget.screen()->availableGeometry(); widget.move(availableGeometry.center() - QPoint(widget.sizeHint().width() / 2, widget.sizeHint().height() / 2)); widget.show(); -- cgit v1.2.3 From 04901b170e009d844232067446fdd56f270d155d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 5 Jun 2020 09:48:52 +0200 Subject: Fix crash on exit when centering Popup within Overlay in StackView item If a Popup is centered within an Overlay, and that Overlay is destroyed before the Popup, we must make sure centerIn is cleared so we don't try to access a dangling pointer. Fixes: QTBUG-84579 Pick-to: 5.15 5.12 Change-Id: Icb2750f847f9d5710725bedc4d1c92bf4c122c03 Reviewed-by: Volker Hilsheimer --- .../data/centerInOverlayWithinStackViewItem.qml | 80 ++++++++++++++++++++++ tests/auto/qquickpopup/tst_qquickpopup.cpp | 17 +++++ 2 files changed, 97 insertions(+) create mode 100644 tests/auto/qquickpopup/data/centerInOverlayWithinStackViewItem.qml (limited to 'tests') diff --git a/tests/auto/qquickpopup/data/centerInOverlayWithinStackViewItem.qml b/tests/auto/qquickpopup/data/centerInOverlayWithinStackViewItem.qml new file mode 100644 index 00000000..076e2230 --- /dev/null +++ b/tests/auto/qquickpopup/data/centerInOverlayWithinStackViewItem.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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.Controls 2.15 + +ApplicationWindow { + width: 400 + height: 400 + + property Popup popup: stackView.currentItem.popup + + StackView { + id: stackView + objectName: "stackView" + anchors.fill: parent + + initialItem: Rectangle { + objectName: "rectangle" + + property alias popup: popup + + Popup { + id: popup + objectName: "popup" + width: 100 + height: 100 + visible: true + anchors.centerIn: Overlay.overlay + } + } + } +} diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp index 30a21b9f..d8dac979 100644 --- a/tests/auto/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp @@ -99,6 +99,7 @@ private slots: void setOverlayParentToNull(); void tabFence(); void invisibleToolTipOpen(); + void centerInOverlayWithinStackViewItem(); }; void tst_QQuickPopup::initTestCase() @@ -1403,6 +1404,22 @@ void tst_QQuickPopup::invisibleToolTipOpen() QTRY_VERIFY(mouseArea->property("isToolTipVisible").toBool()); } +void tst_QQuickPopup::centerInOverlayWithinStackViewItem() +{ + QQuickApplicationHelper helper(this, "centerInOverlayWithinStackViewItem.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); + + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickPopup *popup = window->property("popup").value(); + QVERIFY(popup); + QTRY_COMPARE(popup->isVisible(), true); + + // Shouldn't crash on exit. +} + QTEST_QUICKCONTROLS_MAIN(tst_QQuickPopup) #include "tst_qquickpopup.moc" -- cgit v1.2.3 From 4b61d6f52b166ca2b4a2e38a2fc60d631372f6a7 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 14 Jul 2020 14:18:29 +0200 Subject: Fix tst_QQuickMenu::subMenuPosition() We're still getting failures after QCOMPARE was fixed (in c78a960198d59fb9a9ddd83ad7098b1db396edfd): FAIL! : tst_QQuickMenu::Material::subMenuPosition(cascading,flip) Compared doubles are not the same (fuzzy compare) Actual (subSubMenu1->popupItem()->x()) : 3.88240550819e-11 Expected (subMenu1->popupItem()->x() - subSubMenu1->width() + overlap): 0 tst_qquickmenu.cpp(1532) : failure location Quoting Eddy: "[...] the threshold for double equality is one part in 1e12; the threshold for fuzzy-is-zero is likewise 1e-12; so 3e-11 is non-zero. One work-around, of course, would be to cast float(each operand) so as to get float's wider tolerance (one part in 100,000, null if less than 1e-5)." So that's what we do in this patch. Change-Id: Iecf1b6f4b2cf2c81eb652bb0f565ac682b024dae Pick-to: 5.15 Reviewed-by: Volker Hilsheimer --- tests/auto/qquickmenu/tst_qquickmenu.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/auto/qquickmenu/tst_qquickmenu.cpp b/tests/auto/qquickmenu/tst_qquickmenu.cpp index 9d29c675..a06b715f 100644 --- a/tests/auto/qquickmenu/tst_qquickmenu.cpp +++ b/tests/auto/qquickmenu/tst_qquickmenu.cpp @@ -1396,6 +1396,12 @@ void tst_QQuickMenu::subMenuDisabledKeyboard() QVERIFY(!subMenu->isVisible()); } +/* + QCOMPARE() compares doubles with 1-in-1e12 precision, which is too fine for these tests. + Casting to floats, compared with 1-in-1e5 precision, gives more robust results. +*/ +#define FLOAT_EQ(u, v) QCOMPARE(float(u), float(v)) + void tst_QQuickMenu::subMenuPosition_data() { QTest::addColumn("cascade"); @@ -1496,19 +1502,20 @@ void tst_QQuickMenu::subMenuPosition() if (cascade) { QCOMPARE(subMenu1->parentItem(), subMenu1Item); // vertically aligned to the parent menu item - QCOMPARE(subMenu1->popupItem()->y(), mainMenu->popupItem()->y() + subMenu1Item->y()); + // We cast to float here because we want to use its larger tolerance for equality (because it has less precision than double). + FLOAT_EQ(subMenu1->popupItem()->y(), mainMenu->popupItem()->y() + subMenu1Item->y()); if (mirrored) { // on the left of the parent menu - QCOMPARE(subMenu1->popupItem()->x(), mainMenu->popupItem()->x() - subMenu1->width() + overlap); + FLOAT_EQ(subMenu1->popupItem()->x(), mainMenu->popupItem()->x() - subMenu1->width() + overlap); } else { // on the right of the parent menu - QCOMPARE(subMenu1->popupItem()->x(), mainMenu->popupItem()->x() + mainMenu->width() - overlap); + FLOAT_EQ(subMenu1->popupItem()->x(), mainMenu->popupItem()->x() + mainMenu->width() - overlap); } } else { QCOMPARE(subMenu1->parentItem(), mainMenu->parentItem()); // centered over the parent menu - QCOMPARE(subMenu1->popupItem()->x(), mainMenu->popupItem()->x() + (mainMenu->width() - subMenu1->width()) / 2); - QCOMPARE(subMenu1->popupItem()->y(), mainMenu->popupItem()->y() + (mainMenu->height() - subMenu1->height()) / 2); + FLOAT_EQ(subMenu1->popupItem()->x(), mainMenu->popupItem()->x() + (mainMenu->width() - subMenu1->width()) / 2); + FLOAT_EQ(subMenu1->popupItem()->y(), mainMenu->popupItem()->y() + (mainMenu->height() - subMenu1->height()) / 2); } // open the sub-sub-menu (can flip) @@ -1525,22 +1532,24 @@ void tst_QQuickMenu::subMenuPosition() if (cascade) { QCOMPARE(subSubMenu1->parentItem(), subSubMenu1Item); // vertically aligned to the parent menu item - QCOMPARE(subSubMenu1->popupItem()->y(), subMenu1->popupItem()->y() + subSubMenu1Item->y()); + FLOAT_EQ(subSubMenu1->popupItem()->y(), subMenu1->popupItem()->y() + subSubMenu1Item->y()); if (mirrored != flip) { // on the left of the parent menu - QCOMPARE(subSubMenu1->popupItem()->x(), subMenu1->popupItem()->x() - subSubMenu1->width() + overlap); + FLOAT_EQ(subSubMenu1->popupItem()->x(), subMenu1->popupItem()->x() - subSubMenu1->width() + overlap); } else { // on the right of the parent menu - QCOMPARE(subSubMenu1->popupItem()->x(), subMenu1->popupItem()->x() + subMenu1->width() - overlap); + FLOAT_EQ(subSubMenu1->popupItem()->x(), subMenu1->popupItem()->x() + subMenu1->width() - overlap); } } else { QCOMPARE(subSubMenu1->parentItem(), subMenu1->parentItem()); // centered over the parent menu - QCOMPARE(subSubMenu1->popupItem()->x(), subMenu1->popupItem()->x() + (subMenu1->width() - subSubMenu1->width()) / 2); - QCOMPARE(subSubMenu1->popupItem()->y(), subMenu1->popupItem()->y() + (subMenu1->height() - subSubMenu1->height()) / 2); + FLOAT_EQ(subSubMenu1->popupItem()->x(), subMenu1->popupItem()->x() + (subMenu1->width() - subSubMenu1->width()) / 2); + FLOAT_EQ(subSubMenu1->popupItem()->y(), subMenu1->popupItem()->y() + (subMenu1->height() - subSubMenu1->height()) / 2); } } +#undef FLOAT_EQ + void tst_QQuickMenu::addRemoveSubMenus() { QQuickApplicationHelper helper(this, QLatin1String("subMenus.qml")); -- cgit v1.2.3 From 49ffc6e6af83b295c67fd119b79c925879cc292e Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 27 Feb 2020 15:36:20 +0100 Subject: ComboBox: add implicitContentWidthPolicy [ChangeLog][Controls][ComboBox] Added implicitContentWidthPolicy, which controls how the implicitContentWidth of the ComboBox is calculated. This can be used to automatically ensure that text is not elided. Fixes: QTBUG-78281 Change-Id: If669fa4ef05e5da498992843469000ef39c335ec Reviewed-by: Shawn Rutledge --- tests/auto/controls/data/tst_combobox.qml | 186 +++++++++++++++++++++++++++++- 1 file changed, 182 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 64a525bf..7369f263 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -48,10 +48,10 @@ ** ****************************************************************************/ -import QtQuick 2.14 -import QtQuick.Window 2.2 -import QtTest 1.0 -import QtQuick.Controls 2.12 +import QtQuick 2.15 +import QtQuick.Window 2.15 +import QtTest 1.15 +import QtQuick.Controls 2.15 TestCase { id: testCase @@ -1970,4 +1970,182 @@ TestCase { compare(comboBox1.currentIndex, 9) compare(currentIndexSpy.count, 1) } + + Component { + id: appFontTextFieldComponent + TextField { + objectName: "appFontTextField" + font: Qt.application.font + // We don't want the background's implicit width to interfere with our tests, + // which are about implicit width of the contentItem of ComboBox, which is by default TextField. + background: null + } + } + + Component { + id: appFontContentItemComboBoxComponent + ComboBox { + // Override the contentItem so that the font doesn't vary between styles. + contentItem: TextField { + objectName: "appFontContentItemTextField" + // We do this just to be extra sure that the font never comes from the control, + // as we want it to match that of the TextField in the appFontTextFieldComponent. + font: Qt.application.font + background: null + } + } + } + + Component { + id: twoItemListModelComponent + + ListModel { + ListElement { display: "Short" } + ListElement { display: "Kinda long" } + } + } + + function appendedToModel(model, item) { + if (Array.isArray(model)) { + let newModel = model + newModel.push(item) + return newModel + } + + if (model.hasOwnProperty("append")) { + model.append({ display: item }) + // To account for the fact that changes to a JS array are not seen by the QML engine, + // we need to reassign the entire model and hence return it. For simplicity in the + // calling code, we do it for the ListModel code path too. It should be a no-op. + return model + } + + console.warn("appendedToModel: unrecognised model") + return undefined + } + + function removedFromModel(model, index, count) { + if (Array.isArray(model)) { + let newModel = model + newModel.splice(index, count) + return newModel + } + + if (model.hasOwnProperty("remove")) { + model.remove(index, count) + return model + } + + console.warn("removedFromModel: unrecognised model") + return undefined + } + + // We don't use a data-driven test for the policy because the checks vary a lot based on which enum we're testing. + function test_implicitContentWidthPolicy_ContentItemImplicitWidth() { + // Set ContentItemImplicitWidth and ensure that implicitContentWidth is as wide as the current item + // by comparing it against the implicitWidth of an identical TextField + let control = createTemporaryObject(appFontContentItemComboBoxComponent, testCase, { + model: ["Short", "Kinda long"], + implicitContentWidthPolicy: ComboBox.ContentItemImplicitWidth + }) + verify(control) + compare(control.implicitContentWidthPolicy, ComboBox.ContentItemImplicitWidth) + + let textField = createTemporaryObject(appFontTextFieldComponent, testCase) + verify(textField) + // Don't set any text on textField because we're not accounting for the widest + // text here, so we want to compare it against an empty TextField. + compare(control.implicitContentWidth, textField.implicitWidth) + + textField.font.pixelSize *= 2 + control.font.pixelSize *= 2 + compare(control.implicitContentWidth, textField.implicitWidth) + } + + function test_implicitContentWidthPolicy_WidestText_data() { + return [ + { tag: "Array", model: ["Short", "Kinda long"] }, + { tag: "ListModel", model: twoItemListModelComponent.createObject(testCase) }, + ] + } + + function test_implicitContentWidthPolicy_WidestText(data) { + let control = createTemporaryObject(appFontContentItemComboBoxComponent, testCase, { + model: data.model, + implicitContentWidthPolicy: ComboBox.WidestText + }) + verify(control) + compare(control.implicitContentWidthPolicy, ComboBox.WidestText) + + let textField = createTemporaryObject(appFontTextFieldComponent, testCase) + verify(textField) + textField.text = "Kinda long" + // Note that we don't need to change the current index here, as the implicitContentWidth + // is set to the implicitWidth of the TextField within the ComboBox as if it had the largest + // text from the model set on it. + // We use Math.ceil because TextInput uses qCeil internally, whereas the implicitWidth + // binding for TextField does not. + compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) + + // Add a longer item; it should affect the implicit content width. + let modifiedModel = appendedToModel(data.model, "Moderately long") + control.model = modifiedModel + textField.text = "Moderately long" + compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) + + // Remove the last two items; it should use the only remaining item's width. + modifiedModel = removedFromModel(data.model, 1, 2) + control.model = modifiedModel + compare(control.count, 1) + compare(control.currentText, "Short") + textField.text = "Short" + compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) + + // Changes in font should result in the implicitContentWidth being updated. + textField.font.pixelSize *= 2 + // We have to change the contentItem's font size manually since we break the + // style's binding to the control's font when we set Qt.application.font to it. + control.contentItem.font.pixelSize *= 2 + control.font.pixelSize *= 2 + compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) + } + + function test_implicitContentWidthPolicy_WidestTextWhenCompleted_data() { + return test_implicitContentWidthPolicy_WidestText_data() + } + + function test_implicitContentWidthPolicy_WidestTextWhenCompleted(data) { + let control = createTemporaryObject(appFontContentItemComboBoxComponent, testCase, { + model: data.model, + implicitContentWidthPolicy: ComboBox.WidestTextWhenCompleted + }) + verify(control) + compare(control.implicitContentWidthPolicy, ComboBox.WidestTextWhenCompleted) + + let textField = createTemporaryObject(appFontTextFieldComponent, testCase) + verify(textField) + textField.text = "Kinda long" + compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) + + // Add a longer item; it should not affect the implicit content width + // since we've already accounted for it once. + let modifiedModel = appendedToModel(data.model, "Moderately long") + control.model = modifiedModel + compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) + + // Remove the last two items; it should still not affect the implicit content width. + modifiedModel = removedFromModel(data.model, 1, 2) + control.model = modifiedModel + compare(control.count, 1) + compare(control.currentText, "Short") + compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) + + // Changes in font should not result in the implicitContentWidth being updated. + let oldTextFieldImplicitWidth = textField.implicitWidth + // Changes in font should result in the implicitContentWidth being updated. + textField.font.pixelSize *= 2 + control.contentItem.font.pixelSize *= 2 + control.font.pixelSize *= 2 + compare(Math.ceil(control.implicitContentWidth), Math.ceil(oldTextFieldImplicitWidth)) + } } -- cgit v1.2.3