From 37daab473ab724df538baeff1c4214f902edb41e Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 7 Sep 2020 14:23:02 +0200 Subject: Native style: call QQuickStylePlugin::registerTypes() from style plugins This ensures that we received the warning we expect in tst_StyleImports::importStyleWithoutControls when run with native styles. Change-Id: I290f4e72222688e68ae36ace36f1d8be4bedaf31 Reviewed-by: Richard Moe Gustavsen --- .../macos/qtquickcontrols2macosstyleplugin.cpp | 2 +- .../windows/qtquickcontrols2windowsstyleplugin.cpp | 2 +- .../qtquickcontrols2nativestyleplugin.cpp | 3 ++ .../data/importWindowsStyleWithoutControls.qml | 57 ++++++++++++++++++++++ .../data/importmacOSStyleWithoutControls.qml | 57 ++++++++++++++++++++++ tests/auto/styleimports/tst_styleimports.cpp | 8 ++- 6 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml create mode 100644 tests/auto/styleimports/data/importmacOSStyleWithoutControls.qml diff --git a/src/imports/controls/macos/qtquickcontrols2macosstyleplugin.cpp b/src/imports/controls/macos/qtquickcontrols2macosstyleplugin.cpp index 268eb026..a6a26b89 100644 --- a/src/imports/controls/macos/qtquickcontrols2macosstyleplugin.cpp +++ b/src/imports/controls/macos/qtquickcontrols2macosstyleplugin.cpp @@ -57,7 +57,7 @@ QString QtQuickControls2MacOSStylePlugin::name() const void QtQuickControls2MacOSStylePlugin::registerTypes(const char *uri) { - Q_UNUSED(uri); + QQuickStylePlugin::registerTypes(uri); } QT_END_NAMESPACE diff --git a/src/imports/controls/windows/qtquickcontrols2windowsstyleplugin.cpp b/src/imports/controls/windows/qtquickcontrols2windowsstyleplugin.cpp index 6d95e7f6..9c50f4fb 100644 --- a/src/imports/controls/windows/qtquickcontrols2windowsstyleplugin.cpp +++ b/src/imports/controls/windows/qtquickcontrols2windowsstyleplugin.cpp @@ -57,7 +57,7 @@ QString QtQuickControls2WindowsStylePlugin::name() const void QtQuickControls2WindowsStylePlugin::registerTypes(const char *uri) { - Q_UNUSED(uri); + QQuickStylePlugin::registerTypes(uri); } QT_END_NAMESPACE diff --git a/src/imports/nativestyle/qtquickcontrols2nativestyleplugin.cpp b/src/imports/nativestyle/qtquickcontrols2nativestyleplugin.cpp index dd34d2f8..c7dce598 100644 --- a/src/imports/nativestyle/qtquickcontrols2nativestyleplugin.cpp +++ b/src/imports/nativestyle/qtquickcontrols2nativestyleplugin.cpp @@ -137,6 +137,9 @@ void QtQuickControls2NativeStylePlugin::initializeEngine(QQmlEngine *engine, con void QtQuickControls2NativeStylePlugin::registerTypes(const char *uri) { Q_UNUSED(uri); + if (!QQuickTheme::instance()) + return; + QQuickTheme::instance()->setPalette(QQuickTheme::System, QPalette()); QQuickTheme::instance()->setFont(QQuickTheme::System, QFont()); } diff --git a/tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml b/tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml new file mode 100644 index 00000000..71cb18ee --- /dev/null +++ b/tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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.Controls.Windows + +ApplicationWindow { + title: "Test Application Window" + width: 400 + height: 400 +} diff --git a/tests/auto/styleimports/data/importmacOSStyleWithoutControls.qml b/tests/auto/styleimports/data/importmacOSStyleWithoutControls.qml new file mode 100644 index 00000000..5e91c29f --- /dev/null +++ b/tests/auto/styleimports/data/importmacOSStyleWithoutControls.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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.Controls.macOS + +ApplicationWindow { + title: "Test Application Window" + width: 400 + height: 400 +} diff --git a/tests/auto/styleimports/tst_styleimports.cpp b/tests/auto/styleimports/tst_styleimports.cpp index 239f5783..8b47dee7 100644 --- a/tests/auto/styleimports/tst_styleimports.cpp +++ b/tests/auto/styleimports/tst_styleimports.cpp @@ -221,10 +221,14 @@ void tst_StyleImports::importStyleWithoutControls() const QUrl url(testFileUrl(QString::fromLatin1("import%1StyleWithoutControls.qml").arg(style))); bool success = false; - // Two warnings, because Default is used as the fallback. + // Account for extra warnings for fallback styles. + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*Default")); + if (style == QLatin1String("macOS")) + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*Fusion")); + + // Account for the warning for the current style. if (style != QLatin1String("Default")) QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*" + style)); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*Default")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, this, [url, &success](QObject *obj, const QUrl &objUrl) { -- cgit v1.2.3