diff options
| author | Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> | 2024-01-18 16:35:21 +0100 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-03-06 20:34:29 +0000 |
| commit | 2c9587278f2d589e4f1cf3ee7706c0fbaf1c2173 (patch) | |
| tree | ee30ec5878f1e75ee1cc22a0822c58d446ae6b8c | |
| parent | a550f746179d4773a6ce2ba05e033afb3c37488b (diff) | |
Update test cases for change in default size policy
The size policy of items updated as part of task QTBUG-117597. This patch
adds an autotest for default size policies.
Task-number: QTBUG-117597
Change-Id: Ibc84b2d462885d1d31313040905e74e5bb072373
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
(cherry picked from commit ef30b93682d7f82d6cbe03fb32cb775c99a26910)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
| -rw-r--r-- | tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml | 112 | ||||
| -rw-r--r-- | tests/auto/quick/qquicklayouts/tst_qquicklayouts.cpp | 9 |
2 files changed, 116 insertions, 5 deletions
diff --git a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml index a93775a6d0..99da499e08 100644 --- a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml +++ b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml @@ -3,6 +3,7 @@ import QtQuick import QtTest +import QtQuick.Controls import QtQuick.Layouts import "LayoutHelperLibrary.js" as LayoutHelpers @@ -24,6 +25,13 @@ Item { return [item.x, item.y, item.width, item.height]; } + function cleanup() { + if (LayoutSetup.useDefaultSizePolicy) { + LayoutSetup.useDefaultSizePolicy = false + compare(LayoutSetup.useDefaultSizePolicy, false) + } + } + Component { id: rectangle_Component Rectangle { @@ -1620,8 +1628,8 @@ Item { compare(rootItem.maxWidth, 66) // Should not trigger a binding loop - verify(!BindingLoopDetector.bindingLoopDetected, "Detected binding loop") - BindingLoopDetector.reset() + verify(!LayoutSetup.bindingLoopDetected, "Detected binding loop") + LayoutSetup.resetBindingLoopDetectedFlag() } @@ -1661,5 +1669,105 @@ Item { wait(0) // process the scheduled delete and actually invoke the dtor data.func(layout) // call a function that might ultimately access the deleted item (but shouldn't) } + + //--------------------------- + // Default layout size policy + Component { + id: defaultLayoutComp + Item { + id: rootItem + width: 110 + height: 100 + // Check default layout size policy + RowLayout { + spacing: 0 + anchors.fill: parent + // Rectangle item - SizePolicy { Horizontal: Fixed; Vertical: Fixed } + Rectangle {} + // Button item - SizePolicy { Horizontal: Preferred; Vertical: Fixed } + Button {} + // Frame item - SizePolicy { Horizontal: Preferred; Vertical: Preferred } + Frame {} + } + } + } + + function test_defaultLayoutSize() { + let rootItem = createTemporaryObject(defaultLayoutComp, container) + waitForRendering(rootItem) + + let rowLayout = rootItem.children[0] + + // Test default size policy disabled by default + compare(LayoutSetup.useDefaultSizePolicy, false) + + let defaultButtonWidth = rowLayout.children[1].width + let defaultFrameWidth = rowLayout.children[2].width + + // Enable attached properties for items and check its size + { + rowLayout.children[0].Layout.fillWidth = true + rowLayout.children[0].Layout.fillHeight = true + rowLayout.children[1].Layout.fillWidth = true + rowLayout.children[1].Layout.fillHeight = true + rowLayout.children[2].Layout.fillWidth = true + rowLayout.children[2].Layout.fillHeight = true + waitForRendering(rowLayout) + let isAbovePreferred = rowLayout.width >= rowLayout.implicitWidth + // Removing rectangle as width & implicitWidth be zero always, which makes validation of no use + for (let i = 1; i < rowLayout.children.length; i++) { + compare(rowLayout.children[i].width >= rowLayout.children[i].implicitWidth, isAbovePreferred) + compare(rowLayout.children[i].height, rowLayout.height) + } + } + + // Destroy existing object + rootItem.destroy() + + // Enable default size policy + LayoutSetup.useDefaultSizePolicy = true + compare(LayoutSetup.useDefaultSizePolicy, true) + rootItem = createTemporaryObject(defaultLayoutComp, container) + waitForRendering(rootItem) + rowLayout = rootItem.children[0] + + // The default size policy would stretch button and frame accordingly + { + verify(Math.abs(rowLayout.width - (rowLayout.children[0].width + rowLayout.children[1].width + rowLayout.children[2].width)) <= 1) + compare(rowLayout.children[1].width < rowLayout.children[2].width, rowLayout.children[1].implicitWidth < rowLayout.children[2].implicitWidth) + compare(rowLayout.children[1].height, rowLayout.children[1].implicitHeight) + compare(rowLayout.children[2].height, rowLayout.height) + } + + // Change the width and height of the root item to see layout size change + // Since default size policy for button and frame are Preferred, these items should + // stretch + { + let szDefaultButtonWidth = rowLayout.children[1].width + let szDefaultFrameWidth = rowLayout.children[2].width + + rootItem.width = 210 + rootItem.height = 200 + waitForRendering(rootItem) + verify(rowLayout.children[1].width > szDefaultButtonWidth) + compare(rowLayout.children[1].height, rowLayout.children[1].implicitHeight) + verify(rowLayout.children[2].width > szDefaultFrameWidth) + compare(rowLayout.children[2].height, rowLayout.height) + } + + // Disable size policies through attached properties and check item size + { + rowLayout.children[1].Layout.fillWidth = false + rowLayout.children[2].Layout.fillWidth = false + rowLayout.children[2].Layout.fillHeight = false + waitForRendering(rowLayout) + compare(rowLayout.children[1].width, defaultButtonWidth) + compare(rowLayout.children[2].width, defaultFrameWidth) + for (let index = 1; index < rowLayout.children.length; index++) + compare(rowLayout.children[index].height, rowLayout.children[index].implicitHeight) + } + + rootItem.destroy() + } } } diff --git a/tests/auto/quick/qquicklayouts/tst_qquicklayouts.cpp b/tests/auto/quick/qquicklayouts/tst_qquicklayouts.cpp index 3c018a07bc..98b5e96486 100644 --- a/tests/auto/quick/qquicklayouts/tst_qquicklayouts.cpp +++ b/tests/auto/quick/qquicklayouts/tst_qquicklayouts.cpp @@ -8,20 +8,23 @@ class Setup : public QObject { Q_OBJECT Q_PROPERTY(bool bindingLoopDetected READ wasBindingLoopDetected FINAL) + Q_PROPERTY(bool useDefaultSizePolicy READ useDefaultSizePolicy WRITE setUseDefaultSizePolicy FINAL) public: Setup() {} bool wasBindingLoopDetected() const { return mBindingLoopDetected; } + bool useDefaultSizePolicy() const { return QCoreApplication::testAttribute(Qt::AA_QtQuickUseDefaultSizePolicy); } + void setUseDefaultSizePolicy(bool policy) { QCoreApplication::setAttribute(Qt::AA_QtQuickUseDefaultSizePolicy, policy); } + public slots: - void reset() { mBindingLoopDetected = false; } + void resetBindingLoopDetectedFlag() { mBindingLoopDetected = false; } void qmlEngineAvailable(QQmlEngine *engine) { connect(engine, &QQmlEngine::warnings, this, &Setup::qmlWarnings); - - qmlRegisterSingletonInstance("org.qtproject.Test", 1, 0, "BindingLoopDetector", this); + qmlRegisterSingletonInstance("org.qtproject.Test", 1, 0, "LayoutSetup", this); } void qmlWarnings(const QList<QQmlError> &warnings) |
