From 81e8cd67198768a08f5c65ec026e1553f78e1375 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 30 Sep 2020 14:22:42 +0200 Subject: Make tests explicitly use Basic where necessary The previous commit changes the how the default style is set, and since the tests all assumed that Basic was the default, we now need to ensure it is explicitly set. If we want to, we can revert this patch (or file-by-file) later and ensure that these tests work with all styles. For now, just keep things working as they used to. Tests that use QTEST_QUICKCONTROLS_MAIN are not changed, as they already run with all built-in styles. Tests that don't use types that will cause issues, like tst_qquickcolor, do not need to be changed. tst_snippets can be run manually to produce screenshots, so we specify its style in a qtquickcontrols2.conf file to allow it to be overridden by e.g. application arguments (QQuickStyle::setStyle() takes precedence over all other approaches of setting a style). Change-Id: Ifae7e959f89a41a757c170272038fad139bba04f Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- src/quickcontrols2/qquickstyle.cpp | 5 +++++ src/quickcontrols2/qquickstyle_p.h | 1 + src/quickcontrols2/qquickstyleplugin.cpp | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 5b45a98a..7ad4a38d 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -260,6 +260,11 @@ struct QQuickStyleSpec Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) +QString QQuickStylePrivate::style() +{ + return styleSpec()->style; +} + QString QQuickStylePrivate::effectiveStyleName(const QString &styleName) { return !styleName.isEmpty() ? styleName : QLatin1String("Basic"); diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index e2db35d7..8d0e5a8d 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -58,6 +58,7 @@ class QSettings; class Q_QUICKCONTROLS2_EXPORT QQuickStylePrivate { public: + static QString style(); static QString effectiveStyleName(const QString &styleName); static QString fallbackStyle(); static bool isCustomStyle(); diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index 730a8423..27299b21 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -63,7 +63,9 @@ void QQuickStylePlugin::registerTypes(const char *uri) qCDebug(lcStylePlugin).nospace() << "registerTypes called with uri " << uri << "; plugin name is " << name(); const QTypeRevision latestControlsRevision = QQmlMetaType::latestModuleVersion(QLatin1String("QtQuick.Controls")); - QString styleName = QQuickStyle::name(); + // Use the private function because we don't want to cause resolve() to be called, + // as the logic that assigns a default style if one wasn't set would interfere with compile-time style selection. + QString styleName = QQuickStylePrivate::style(); if (!latestControlsRevision.isValid() && styleName.isEmpty()) { // The user hasn't imported QtQuick.Controls, nor set a style via the runtime methods. qCDebug(lcStylePlugin).nospace() << uri << " imported before QtQuick.Controls; using compile-time style selection"; -- cgit v1.2.3