diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2022-05-02 15:42:53 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-05-07 21:25:39 +0000 |
commit | c5e049c7d3cb1b3bdc6727e06412d794e335355a (patch) | |
tree | a697e1a47c44e1ad062cae8b3549f7023edb9584 /tests/auto/quickcontrols2 | |
parent | ff286158a7511f01eae52193b0df839edfed88d4 (diff) |
Add file selector for custom styles when using run-time style selection
Previously this was only available for QQuickStylePlugin-based styles.
This patch makes it available for qmldir-based styles when using
run-time style selection.
The existing documentation doesn't differentiate between built-in
styles and custom styles:
"Qt Quick Controls extends the built-in selectors with the name
(lowercase) of the style that an application is running with."
So this is a bug fix.
Change-Id: Ib2ed56ad8398db49d192db6a6023d776caaa4457
Fixes: QTBUG-99117
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit fdd62a5b81d5c3de423118bb24d5ac18a7fddbe5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quickcontrols2')
4 files changed, 97 insertions, 0 deletions
diff --git a/tests/auto/quickcontrols2/styleimports/data/+FileSystemStyle/CustomComponent.qml b/tests/auto/quickcontrols2/styleimports/data/+FileSystemStyle/CustomComponent.qml new file mode 100644 index 0000000000..ee5ffe1151 --- /dev/null +++ b/tests/auto/quickcontrols2/styleimports/data/+FileSystemStyle/CustomComponent.qml @@ -0,0 +1,5 @@ +import QtQuick + +Item { + objectName: "+FileSystemStyle/CustomComponent.qml" +} diff --git a/tests/auto/quickcontrols2/styleimports/data/CustomComponent.qml b/tests/auto/quickcontrols2/styleimports/data/CustomComponent.qml new file mode 100644 index 0000000000..220630f812 --- /dev/null +++ b/tests/auto/quickcontrols2/styleimports/data/CustomComponent.qml @@ -0,0 +1,5 @@ +import QtQuick + +Item { + objectName: "CustomComponent.qml" +} diff --git a/tests/auto/quickcontrols2/styleimports/data/customStyleSelector.qml b/tests/auto/quickcontrols2/styleimports/data/customStyleSelector.qml new file mode 100644 index 0000000000..7d36842131 --- /dev/null +++ b/tests/auto/quickcontrols2/styleimports/data/customStyleSelector.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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 +import QtQuick.Controls + +ApplicationWindow { + title: "Test Application Window" + width: 400 + height: 400 + + property alias customComponent: customComponent + + CustomComponent { + id: customComponent + } +} diff --git a/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp b/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp index 6f8e50fa0f..cdbccb38e0 100644 --- a/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp +++ b/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp @@ -54,6 +54,7 @@ private slots: void select(); void platformSelectors(); + void customStyleSelector(); void fallbackStyleShouldNotOverwriteTheme_data(); void fallbackStyleShouldNotOverwriteTheme(); @@ -180,6 +181,7 @@ void tst_StyleImports::select() } } +// Tests that the various platforms are available as selectors. void tst_StyleImports::platformSelectors() { QQuickStyle::setStyle(QLatin1String("PlatformStyle")); @@ -204,6 +206,27 @@ void tst_StyleImports::platformSelectors() #endif } +// Tests that a file selector is added for custom styles. +// Note that this is different to the regular QML import mechanism +// that results in e.g. FileSystemStyle/Button.qml being found; +// it allows non-template (Controls), custom user types to be +// picked up via selectors. +void tst_StyleImports::customStyleSelector() +{ + QQuickStyle::setStyle(QLatin1String("FileSystemStyle")); + + QQmlApplicationEngine engine; + engine.addImportPath(dataDirectory() + QLatin1String("/styles")); + engine.load(testFileUrl("customStyleSelector.qml")); + QVERIFY(!engine.rootObjects().isEmpty()); + QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first()); + QVERIFY(window); + + QObject *customComponent = window->property("customComponent").value<QObject*>(); + QVERIFY(customComponent); + QCOMPARE(customComponent->objectName(), "+FileSystemStyle/CustomComponent.qml"); +} + void tst_StyleImports::fallbackStyleShouldNotOverwriteTheme_data() { QTest::addColumn<QString>("style"); |