From 96a511c979c7aa62f18cdd1b011fcaa40cddf686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Wed, 27 May 2020 23:34:10 +0200 Subject: [PATCH] Add some more tests for automatic stylesheet preprocessing Currently, the tests fail, but the output is by and large correct. There are some issues that still need to be analyzed. Task-number: QDS-2071 Change-Id: Idb4618171a7256ec527368d6079c756eb734db82 Reviewed-by: Thomas Hartmann --- .../qmldesigner/coretests/tst_testcore.cpp | 4 + .../data/merging/ButtonOutlineExpected.qml | 14 ++- .../data/merging/ButtonStyle.ui.Expected.qml | 105 ++++++++++++++++++ .../data/merging/ButtonStyle.ui.qml | 68 ++++++++++++ 4 files changed, 186 insertions(+), 5 deletions(-) create mode 100644 tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.Expected.qml create mode 100644 tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.qml diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp index 624c296192b..dcac5310fc5 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp @@ -3773,6 +3773,9 @@ void tst_TestCore::testMergeModelRewriter1_data() QString buttonOutlineStyleQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging/ButtonStyleOutline.qml"); QString buttonOutlineExpectedQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging/ButtonOutlineExpected.qml"); + QString buttonStyleUiQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging/ButtonStyle.ui.qml"); + QString buttonStyleUiExpectedQmlContents = readQmlFromFile(QString(TESTSRCDIR) + "/../data/merging/ButtonStyle.ui.Expected.qml"); + QTest::newRow("Simple style replacement") << simpleTemplateQmlContents << simpleStyleQmlContents << simpleExpectedQmlContents; QTest::newRow("Complex style replacement") << complexTemplateQmlContents << complexStyleQmlContents << complexExpectedQmlContents; QTest::newRow("Empty stylesheet") << emptyTemplateQmlContents << emptyStyleQmlContents << emptyExpectedQmlContents; @@ -3783,6 +3786,7 @@ void tst_TestCore::testMergeModelRewriter1_data() QTest::newRow("Button Inline styling") << buttonTemplateQmlContents << buttonInlineStyleQmlContents << buttonInlineExpectedQmlContents; QTest::newRow("Button Outline styling") << buttonAbsoluteTemplateQmlContents << buttonOutlineStyleQmlContents << buttonOutlineExpectedQmlContents; + QTest::newRow("Button Designer styling") << buttonAbsoluteTemplateQmlContents << buttonStyleUiQmlContents << buttonStyleUiExpectedQmlContents; } diff --git a/tests/auto/qml/qmldesigner/data/merging/ButtonOutlineExpected.qml b/tests/auto/qml/qmldesigner/data/merging/ButtonOutlineExpected.qml index ddbdd780961..a6b9e4af2f1 100644 --- a/tests/auto/qml/qmldesigner/data/merging/ButtonOutlineExpected.qml +++ b/tests/auto/qml/qmldesigner/data/merging/ButtonOutlineExpected.qml @@ -22,6 +22,8 @@ T.Button { Rectangle { id: buttonNormal + x: 286 + y: 62 width: 100 height: 60 color: "#d4d4d4" @@ -31,8 +33,8 @@ T.Button { anchors.fill: parent Text { id: normalText - x: 20 - y: 20 + x: 33 + y: 24 color: "#808080" text: control.text elide: Text.ElideRight @@ -44,6 +46,8 @@ T.Button { Rectangle { id: buttonPressed + x: 123 + y: 62 width: 100 height: 60 color: "#69b5ec" @@ -53,8 +57,8 @@ T.Button { anchors.fill: parent Text { id: pressedText - x: 20 - y: 40 + x: 31 + y: 24 color: "#000000" text: control.text elide: Text.ElideRight @@ -94,4 +98,4 @@ T.Button { } } ] -} \ No newline at end of file +} diff --git a/tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.Expected.qml b/tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.Expected.qml new file mode 100644 index 00000000000..f50c211ecb7 --- /dev/null +++ b/tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.Expected.qml @@ -0,0 +1,105 @@ +import QtQuick 2.10 +import QtQuick.Templates 2.1 as T + +T.Button { + id: control + + implicitWidth: Math.max( + background ? background.implicitWidth : 0, + contentItem.implicitWidth + leftPadding + rightPadding) + implicitHeight: Math.max( + background ? background.implicitHeight : 0, + contentItem.implicitHeight + topPadding + bottomPadding) + leftPadding: 4 + rightPadding: 4 + + text: "My Button" + + background: Item { + implicitWidth: buttonNormal.width + implicitHeight: buttonNormal.height + opacity: enabled ? 1 : 0.3 + + Image { + id: buttonNormal + color: "#d4d4d4" + x: 14 + y: 5 + width: 100 //Bit of black magic to define the default size + height: 40 + + border.color: "gray" + border.width: 1 + radius: 2 + anchors.fill: parent //binding has to be preserved + source: "assets/buttonNormal.png" + + Text { + id: normalText + x: 58 + y: 50 //id only required to preserve binding + text: control.text //binding has to be preserved + //anchors.fill: parent + color: "#BBBBBB" + font.letterSpacing: 0.594 + font.pixelSize: 24 + } + } + + Image { + id: buttonPressed + x: 290 + y: 5 + width: 100 //Bit of black magic to define the default size + height: 40 + source: "assets/buttonPressed.png" + + border.color: "gray" + border.width: 1 + radius: 2 + anchors.fill: parent //binding has to be preserved + + Text { + id: pressedText //id only required to preserve binding + x: 58 + y: 50 + text: control.text //binding has to be preserved + //anchors.fill: parent + color: "#E1E1E1" + + font.letterSpacing: 0.594 + font.pixelSize: 24 + } + } + } + + contentItem: Item {} + + states: [ + State { + name: "normal" + when: !control.down + PropertyChanges { + target: buttonPressed + visible: false + } + PropertyChanges { + target: buttonNormal + visible: true + } + }, + State { + name: "down" + when: control.down + PropertyChanges { + target: buttonPressed + visible: true + } + PropertyChanges { + target: buttonNormal + visible: false + } + } + ] +} + diff --git a/tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.qml b/tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.qml new file mode 100644 index 00000000000..c16d51997c1 --- /dev/null +++ b/tests/auto/qml/qmldesigner/data/merging/ButtonStyle.ui.qml @@ -0,0 +1,68 @@ +import QtQuick 2.8 + +Item { + id: buttonStyle + width: 576 + height: 169 + + Image { + id: buttonStyleAsset + x: 0 + y: 0 + source: "assets/ButtonStyle.png" + } + + Image { + id: buttonNormal + x: 14 + y: 5 + source: "assets/buttonNormal.png" + } + + Text { + id: normalText + x: 72 + y: 55 + color: "#BBBBBB" + text: "Button Normal" + font.letterSpacing: 0.594 + font.pixelSize: 24 + } + + Image { + id: buttonPressed + x: 290 + y: 5 + source: "assets/buttonPressed.png" + } + + Text { + id: pressedText + x: 348 + y: 55 + color: "#E1E1E1" + text: "Button Pressed" + font.letterSpacing: 0.594 + font.pixelSize: 24 + } + + Text { + id: annotation_text_to_b_219_17 + x: 78 + y: 137 + color: "#E1E1E1" + text: "Annotation Text - To be skipped on import " + font.letterSpacing: 0.594 + font.pixelSize: 24 + } +} + +/*##^## +Designer { + D{i:0;UUID:"2c9c0d7afb27ed7fc52953dffad06338"}D{i:1;UUID:"2c9c0d7afb27ed7fc52953dffad06338_asset"} +D{i:2;UUID:"fe9b73e310828dc3f213ba5ef14960b0"}D{i:3;UUID:"5c926d0aacc8788795645ff693c5211c"} +D{i:4;UUID:"261e8907a5da706273665c336dfec28a"}D{i:5;UUID:"7f46944edba773280017e4c8389c8ee0"} +D{i:6;UUID:"f4adf85e9cbce87a9e84a0aaa67d8a80"} +} +##^##*/ +