diff options
Diffstat (limited to 'tests/auto/quick/qquickanchors')
-rw-r--r-- | tests/auto/quick/qquickanchors/CMakeLists.txt | 6 | ||||
-rw-r--r-- | tests/auto/quick/qquickanchors/data/centerin.qml | 7 | ||||
-rw-r--r-- | tests/auto/quick/qquickanchors/tst_qquickanchors.cpp | 25 |
3 files changed, 32 insertions, 6 deletions
diff --git a/tests/auto/quick/qquickanchors/CMakeLists.txt b/tests/auto/quick/qquickanchors/CMakeLists.txt index af46206a7c..9bc4d5203b 100644 --- a/tests/auto/quick/qquickanchors/CMakeLists.txt +++ b/tests/auto/quick/qquickanchors/CMakeLists.txt @@ -7,6 +7,12 @@ ## tst_qquickanchors Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qquickanchors LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/tests/auto/quick/qquickanchors/data/centerin.qml b/tests/auto/quick/qquickanchors/data/centerin.qml index b880219f0f..94c344b4e8 100644 --- a/tests/auto/quick/qquickanchors/data/centerin.qml +++ b/tests/auto/quick/qquickanchors/data/centerin.qml @@ -22,4 +22,11 @@ Rectangle { anchors.centerIn: parent; anchors.alignWhenCentered: false } + + Rectangle { + objectName: "centered4" + width: 0.9; height: 0.9; color: "plum" + anchors.centerIn: parent; + anchors.alignWhenCentered: false + } } diff --git a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp index 7dd3eaece0..508a3906fc 100644 --- a/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp +++ b/tests/auto/quick/qquickanchors/tst_qquickanchors.cpp @@ -1,5 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + #include <qtest.h> #include <QSignalSpy> #include <private/qquickitem_p.h> @@ -143,15 +144,16 @@ void tst_qquickanchors::basicAnchorsRTL() qApp->processEvents(); QQuickItem* rootItem = qobject_cast<QQuickItem*>(view->rootObject()); - foreach (QObject *child, rootItem->children()) { + const QObjectList children = rootItem->children(); + for (QObject *child : children) { bool mirrored = QQuickItemPrivate::get(qobject_cast<QQuickItem*>(child))->anchors()->mirrored(); QCOMPARE(mirrored, false); } - foreach (QObject *child, rootItem->children()) + for (QObject *child : children) mirrorAnchors(qobject_cast<QQuickItem*>(child)); - foreach (QObject *child, rootItem->children()) { + for (QObject *child : children) { bool mirrored = QQuickItemPrivate::get(qobject_cast<QQuickItem*>(child))->anchors()->mirrored(); QCOMPARE(mirrored, true); } @@ -273,7 +275,8 @@ void tst_qquickanchors::illegalSets_data() << "Rectangle { id: rect; Rectangle { anchors.left: rect.left; anchors.right: rect.right; anchors.horizontalCenter: rect.horizontalCenter } }" << "<Unknown File>:2:23: QML Rectangle: Cannot specify left, right, and horizontalCenter anchors at the same time."; - foreach (const QString &side, QStringList() << "left" << "right") { + const QStringList leftRight = {"left", "right"}; + for (const QString &side : leftRight) { QTest::newRow("H - anchor to V") << QString("Rectangle { Rectangle { anchors.%1: parent.top } }").arg(side) << "<Unknown File>:2:13: QML Rectangle: Cannot anchor a horizontal edge to a vertical edge."; @@ -296,7 +299,8 @@ void tst_qquickanchors::illegalSets_data() << "Rectangle { Text { id: text1; text: \"Hello\" } Text { anchors.baseline: text1.baseline; anchors.top: text1.top; } }" << "<Unknown File>:2:47: QML Text: Baseline anchor cannot be used in conjunction with top, bottom, or verticalCenter anchors."; - foreach (const QString &side, QStringList() << "top" << "bottom" << "baseline") { + const QStringList topBottomBaseline = {"top", "bottom", "baseline"}; + for (const QString &side : topBottomBaseline) { QTest::newRow("V - anchor to H") << QString("Rectangle { Rectangle { anchors.%1: parent.left } }").arg(side) @@ -516,6 +520,15 @@ void tst_qquickanchors::centerIn() QCOMPARE(rect3->x(), 94.5); QCOMPARE(rect3->y(), 94.5); + //QTBUG-95224 (fractional positions are not center-rounded correctly) + // The center anchor lines on the parent will be rounded from 41.2 / 2 == 20.6 to 21 + // rect4 has anchors.alignWhenCentered: false, so no rounding will be done on that items position. + // As a result, the expected position of rect4 will be 21 - 0.9/2 = 20.55 + QQuickRectangle* rect4 = findItem<QQuickRectangle>(view->rootObject(), QLatin1String("centered4")); + view->rootObject()->setWidth(41.2); + view->rootObject()->setHeight(41.2); + QCOMPARE(rect4->x(), 20.55); + QCOMPARE(rect4->y(), 20.55); delete view; } |