aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-09-11 16:18:50 +0200
committerMitch Curtis <mitch.curtis@qt.io>2020-09-24 13:48:58 +0200
commita0f0b4f65e96aecc9949d3089a283cdfaeefbb3b (patch)
tree175f986e31860164c000b9a66c09a549b4f5da55
parent526729cb8a53972b6925cbfd7a5f5cbf124be71c (diff)
Support compile-time style selection
By allowing importing styles without first importing QtQuick.Controls, which does runtime style selection. [ChangeLog][Styles] It's now possible to select a style at compile-time by importing that style explicitly instead of QtQuick.Controls. This avoids the need to do run-time style selection and hence deploy the QtQuick.Controls plugin with the application. Change-Id: I666d6dc7727fffd2c7b05743855f2086f076465a Fixes: QTBUG-86284 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc17
-rw-r--r--src/imports/controls/doc/src/qtquickcontrols2-styles.qdoc69
-rw-r--r--src/imports/controls/qtquickcontrols2plugin.cpp61
-rw-r--r--src/quickcontrols2/qquickstyle.cpp3
-rw-r--r--src/quickcontrols2/qquickstyleplugin.cpp75
-rw-r--r--src/quickcontrols2/qquickstyleplugin_p.h2
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/shared/visualtestutil.h10
-rw-r--r--tests/auto/styleimports/data/importImagineStyleWithoutControls.qml57
-rw-r--r--tests/auto/styleimports/data/importUniversalStyleWithoutControls.qml57
-rw-r--r--tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml57
-rw-r--r--tests/auto/styleimports/data/importmacOSStyleWithoutControls.qml57
-rw-r--r--tests/auto/styleimports/tst_styleimports.cpp41
-rw-r--r--tests/auto/styleimportscompiletimematerial/CMakeLists.txt62
-rw-r--r--tests/auto/styleimportscompiletimematerial/data/importMaterialStyleWithoutControls.qml (renamed from tests/auto/styleimports/data/importMaterialStyleWithoutControls.qml)7
-rw-r--r--tests/auto/styleimportscompiletimematerial/styleimportscompiletimematerial.pro15
-rw-r--r--tests/auto/styleimportscompiletimematerial/tst_styleimportscompiletimematerial.cpp77
-rw-r--r--tests/auto/styleimportscompiletimeqmlonly/CMakeLists.txt62
-rw-r--r--tests/auto/styleimportscompiletimeqmlonly/data/QmlOnly/Button.qml (renamed from tests/auto/styleimports/data/importFusionStyleWithoutControls.qml)36
-rw-r--r--tests/auto/styleimportscompiletimeqmlonly/data/QmlOnly/qmldir3
-rw-r--r--tests/auto/styleimportscompiletimeqmlonly/data/importQmlOnlyStyleWithoutControls.qml (renamed from tests/auto/styleimports/data/importBasicStyleWithoutControls.qml)9
-rw-r--r--tests/auto/styleimportscompiletimeqmlonly/styleimportscompiletimeqmlonly.pro17
-rw-r--r--tests/auto/styleimportscompiletimeqmlonly/tst_styleimportscompiletimeqmlonly.cpp74
23 files changed, 514 insertions, 356 deletions
diff --git a/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc
index e1ddd1e3..956c2c9d 100644
--- a/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc
+++ b/src/imports/controls/doc/src/qtquickcontrols2-customize.qdoc
@@ -111,9 +111,9 @@
\section2 Definition of a Style
- In Qt Quick Controls, a style is essentially an interchangeable set of
- QML files within a single directory. There are four requirements for a style
- to be \l {Using Styles in Qt Quick Controls}{usable}:
+ In Qt Quick Controls, a style is essentially a set of QML files within a
+ single directory. There are four requirements for a style to be
+ \l {Using Styles in Qt Quick Controls}{usable}:
\list
\li At least one QML file whose name matches a control (for example,
@@ -134,6 +134,17 @@
Button 2.15 Button.qml
\endcode
+ If you're using \l {Compile-Time Style Selection}{compile-time style
+ selection}, the qmldir should also import the fallback style:
+
+ \badcode
+ # ...
+ import QtQuick.Controls.Basic auto
+ \endcode
+
+ This can also be done for \l {Run-Time Style Selection}{run-time style selection}
+ instead of using, for example, \l QQuickStyle::setFallbackStyle().
+
The directory structure for such a style looks like this:
\badcode
diff --git a/src/imports/controls/doc/src/qtquickcontrols2-styles.qdoc b/src/imports/controls/doc/src/qtquickcontrols2-styles.qdoc
index 29e73540..a26287fc 100644
--- a/src/imports/controls/doc/src/qtquickcontrols2-styles.qdoc
+++ b/src/imports/controls/doc/src/qtquickcontrols2-styles.qdoc
@@ -69,23 +69,62 @@
\section1 Using Styles in Qt Quick Controls
- In order to run an application with a specific style, either configure the
- style using \l[CPP]{QQuickStyle} in C++, pass a command line argument, or set an
- environment variable. Alternatively, the preferred style and style-specific
- attributes can be specified in a configuration file.
+ There are two ways of using styles in Qt Quick Controls:
+ run-time style selection and compile-time style selection.
- The priority of these approaches follows the order they are listed below,
+ \section2 Compile-Time Style Selection
+
+ Compile-time style selection involves using QML imports to specify the
+ style. For example, to import the Material style:
+
+ \qml
+ import QtQuick.Controls.Material
+
+ ApplicationWindow {
+ // ...
+ }
+ \endqml
+
+ Notice that QtQuick.Controls (which is responsible for run-time style
+ selection) is not imported. The fallback style is specified by the qmldir
+ of the style:
+
+ \badcode
+ module QtQuick.Controls.Material
+ # ...
+ import QtQuick.Controls.Basic auto
+ \endcode
+
+ The benefit of compile-time style selection is that the QtQuick.Controls plugin
+ is not used and therefore does not need to be deployed with the application.
+
+ \section2 Run-Time Style Selection
+
+ Run-time style selection involves importing \c QtQuick.Controls:
+
+ \qml
+ import QtQuick.Controls
+ \endqml
+
+ The QtQuick.Controls plugin will import the style and fallback
+ style that were set at runtime via one of the following approaches:
+
+ \list
+ \li \l[CPP]{QQuickStyle::setStyle()}
+ \li The \c -style command line argument
+ \li The \c QT_QUICK_CONTROLS_STYLE environment variable
+ \li The \c qtquickcontrols2.conf configuration file
+ \endlist
+
+ The priority of these approaches follows the order they are listed,
from highest to lowest. That is, using \c QQuickStyle to set the style will
always take priority over using the command line argument, for example.
- \warning When resolving a given style name to an absolute path, \c QQuickStyle
- may search the root resource directory (\c {:}). Consequently, make sure
- that your resource directories are named differently than the names of the
- styles that your application supports. Otherwise, the styles may not load.
- For example, avoid naming a resource directory \c :/material
- (or \c {:/Material}) if the application supports the Material style.
+ The benefit of run-time style selection is that a single application binary
+ can support multiple styles, meaning that the end user can choose which
+ style to run the application with.
- \section2 Using QQuickStyle in C++
+ \section3 Using QQuickStyle in C++
\l[CPP]{QQuickStyle} provides C++ API for configuring a specific
style. The following example runs a Qt Quick Controls application
@@ -98,7 +137,7 @@
See the detailed description of \l[CPP]{QQuickStyle} for more
details.
- \section2 Command line argument
+ \section3 Command line argument
Passing a \c -style command line argument is the convenient way to test different
styles. It takes precedence over the other methods listed below. The following
@@ -108,7 +147,7 @@
./app -style material
\endcode
- \section2 Environment variable
+ \section3 Environment variable
Setting the \c QT_QUICK_CONTROLS_STYLE environment variable can be used to set
a system-wide style preference. It takes precedence over the configuration file
@@ -122,7 +161,7 @@
See \l {Supported Environment Variables in Qt Quick Controls} for the full list
of supported environment variables.
- \section2 Configuration file
+ \section3 Configuration file
Qt Quick Controls support a special configuration file, \c :/qtquickcontrols2.conf,
that is built into an application's resources.
diff --git a/src/imports/controls/qtquickcontrols2plugin.cpp b/src/imports/controls/qtquickcontrols2plugin.cpp
index 88fce5ca..2bd4047d 100644
--- a/src/imports/controls/qtquickcontrols2plugin.cpp
+++ b/src/imports/controls/qtquickcontrols2plugin.cpp
@@ -34,7 +34,6 @@
**
****************************************************************************/
-#include <QtCore/private/qfileselector_p.h>
#include <QtCore/qloggingcategory.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlextensionplugin.h>
@@ -45,7 +44,7 @@
QT_BEGIN_NAMESPACE
-Q_LOGGING_CATEGORY(lcQtQuickControlsStylePlugin, "qt.quick.controls.qtquickcontrols2plugin")
+Q_LOGGING_CATEGORY(lcQtQuickControls2Plugin, "qt.quick.controls.qtquickcontrols2plugin")
class QtQuickControls2Plugin : public QQmlExtensionPlugin
{
@@ -60,8 +59,6 @@ public:
void unregisterTypes() override;
private:
- QQuickTheme *createTheme(const QString &name);
-
// We store these because the style plugins can be unregistered before
// QtQuickControls2Plugin, and since QQuickStylePlugin calls QQuickStylePrivate::reset(),
// the style information can be lost when it comes time to call qmlUnregisterModuleImport().
@@ -110,24 +107,22 @@ QtQuickControls2Plugin::~QtQuickControls2Plugin()
void QtQuickControls2Plugin::registerTypes(const char *uri)
{
- qCDebug(lcQtQuickControlsStylePlugin) << "registerTypes() called with uri" << uri;
+ qCDebug(lcQtQuickControls2Plugin) << "registerTypes() called with uri" << uri;
// It's OK that the style is resolved more than once; some accessors like name() cause it to be called, for example.
QQuickStylePrivate::init();
const QString styleName = QQuickStylePrivate::effectiveStyleName(QQuickStyle::name());
const QString fallbackStyleName = QQuickStylePrivate::effectiveStyleName(QQuickStylePrivate::fallbackStyle());
- qCDebug(lcQtQuickControlsStylePlugin) << "style:" << QQuickStyle::name() << "effective style:" << styleName
+ qCDebug(lcQtQuickControls2Plugin) << "style:" << QQuickStyle::name() << "effective style:" << styleName
<< "fallback style:" << QQuickStylePrivate::fallbackStyle() << "effective fallback style:" << fallbackStyleName;
- createTheme(styleName);
-
// If the style is Basic, we don't need to register the fallback because the Basic style
// provides all controls. Also, if we didn't return early here, we can get an infinite import loop
// when the style is set to Basic.
if (styleName != fallbackStyleName && styleName != QLatin1String("Basic")) {
registeredFallbackStyleUri = ::fallbackStyleUri();
- qCDebug(lcQtQuickControlsStylePlugin) << "calling qmlRegisterModuleImport() to register fallback style with"
+ qCDebug(lcQtQuickControls2Plugin) << "calling qmlRegisterModuleImport() to register fallback style with"
<< " uri \"" << qtQuickControlsUri << "\" moduleMajor" << QQmlModuleImportModuleAny
<< "import" << registeredFallbackStyleUri << "importMajor" << QQmlModuleImportAuto;
// The fallback style must be a built-in style, so we match the version number.
@@ -141,19 +136,15 @@ void QtQuickControls2Plugin::registerTypes(const char *uri)
customStyle = QQuickStylePrivate::isCustomStyle();
registeredStyleUri = ::styleUri();
const int importMajor = !customStyle ? QQmlModuleImportAuto : QQmlModuleImportLatest;
- qCDebug(lcQtQuickControlsStylePlugin).nospace() << "calling qmlRegisterModuleImport() to register primary style with"
+ qCDebug(lcQtQuickControls2Plugin).nospace() << "calling qmlRegisterModuleImport() to register primary style with"
<< " uri \"" << qtQuickControlsUri << "\" moduleMajor " << importMajor
<< " import " << registeredStyleUri << " importMajor " << importMajor;
qmlRegisterModuleImport(qtQuickControlsUri, QQmlModuleImportModuleAny, registeredStyleUri.toUtf8().constData(), importMajor);
-
- const QString style = QQuickStyle::name();
- if (!style.isEmpty())
- QFileSelectorPrivate::addStatics(QStringList() << style);
}
void QtQuickControls2Plugin::unregisterTypes()
{
- qCDebug(lcQtQuickControlsStylePlugin) << "unregisterTypes() called";
+ qCDebug(lcQtQuickControls2Plugin) << "unregisterTypes() called";
if (!registeredFallbackStyleUri.isEmpty()) {
// We registered a fallback style, so now we need to unregister it.
@@ -166,46 +157,6 @@ void QtQuickControls2Plugin::unregisterTypes()
qmlUnregisterModuleImport(qtQuickControlsUri, QQmlModuleImportModuleAny, registeredStyleUri.toUtf8().constData(), importMajor);
customStyle = false;
registeredStyleUri.clear();
-
- QQuickThemePrivate::instance.reset();
- QQuickStylePrivate::reset();
-}
-
-/*!
- \internal
-
- Responsible for setting the font and palette settings that were specified in the
- qtquickcontrols2.conf file.
-
- Style-specific settings (e.g. Variant=Dense) are read in the constructor of the
- appropriate style plugin (e.g. QtQuickControls2MaterialStylePlugin).
-
- Implicit style-specific font and palette values are assigned in the relevant theme
- (e.g. QQuickMaterialTheme).
-*/
-QQuickTheme *QtQuickControls2Plugin::createTheme(const QString &name)
-{
- qCDebug(lcQtQuickControlsStylePlugin) << "creating QQuickTheme instance to be initialized by style-specific theme of" << name;
-
- QQuickTheme *theme = new QQuickTheme;
-#if QT_CONFIG(settings)
- QQuickThemePrivate *p = QQuickThemePrivate::get(theme);
- QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(name);
- if (settings) {
- p->defaultFont.reset(QQuickStylePrivate::readFont(settings));
- // Set the default font as the System scope, because that's what
- // QQuickControlPrivate::parentFont() uses as its fallback if no
- // parent item has a font explicitly set. QQuickControlPrivate::parentFont()
- // is used as the starting point for font inheritance/resolution.
- // The same goes for palettes below.
- theme->setFont(QQuickTheme::System, *p->defaultFont);
-
- p->defaultPalette.reset(QQuickStylePrivate::readPalette(settings));
- theme->setPalette(QQuickTheme::System, *p->defaultPalette);
- }
-#endif
- QQuickThemePrivate::instance.reset(theme);
- return theme;
}
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index d5ded6c2..ca844c6f 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -91,6 +91,9 @@ Q_LOGGING_CATEGORY(lcQtQuickControlsStyle, "qt.quick.controls.style")
Qt Quick Controls. It is not possible to change the style after the QML
types have been registered.
+ \note QQuickStyle is not supported when using
+ \l {Compile-Time Style Selection}{compile-time style selection}.
+
To create your own custom style, see \l {Creating a Custom Style}. Custom
styles do not need to implement all controls. By default, the styling
system uses the \l {Basic style} as a fallback for controls that a custom
diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp
index f211d4b0..730a8423 100644
--- a/src/quickcontrols2/qquickstyleplugin.cpp
+++ b/src/quickcontrols2/qquickstyleplugin.cpp
@@ -38,9 +38,11 @@
#include "qquickstyle_p.h"
#include "qquickstyleplugin_p.h"
+#include <QtCore/private/qfileselector_p.h>
#include <QtCore/qloggingcategory.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlfile.h>
+#include <QtQml/private/qqmlmetatype_p.h>
#include <QtQuickTemplates2/private/qquicktheme_p_p.h>
QT_BEGIN_NAMESPACE
@@ -60,25 +62,88 @@ 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();
+ 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";
+ QQuickStyle::setStyle(name());
+ styleName = name();
+ }
+
+ // Even if this style plugin isn't for the style set by the user,
+ // we still want to create the theme object, because that function
+ // is also responsible for reading values from qtquickcontrols2.conf.
+ // So, even if a style doesn't have a QQuickTheme, it can still have
+ // values set for (e.g. fonts and palettes) in qtquickcontrols2.conf.
+ const QString effectiveCurrentStyleName = QQuickStylePrivate::effectiveStyleName(styleName);
auto theme = QQuickTheme::instance();
if (!theme) {
- qWarning() << "QtQuick.Controls must be imported before importing" << baseUrl().toString();
- return;
+ qCDebug(lcStylePlugin) << "creating theme";
+ theme = createTheme(effectiveCurrentStyleName);
}
- if (name() != QQuickStyle::name()) {
+ if (name() != effectiveCurrentStyleName) {
qCDebug(lcStylePlugin).nospace() << "theme does not belong to current style ("
- << QQuickStyle::name() << "); not calling initializeTheme()";
+ << effectiveCurrentStyleName << "); not calling initializeTheme()";
return;
}
- qCDebug(lcStylePlugin) << "theme has not been initialized; calling initializeTheme()";
+ qCDebug(lcStylePlugin) << "theme has not yet been initialized; calling initializeTheme()";
initializeTheme(theme);
+
+ if (!styleName.isEmpty())
+ QFileSelectorPrivate::addStatics(QStringList() << styleName);
}
void QQuickStylePlugin::unregisterTypes()
{
qCDebug(lcStylePlugin) << "unregisterTypes called; plugin name is" << name();
+ if (!QQuickThemePrivate::instance)
+ return;
+
+ // Not every style has a plugin - some styles are QML-only. So, we clean this
+ // stuff up when the first style plugin is unregistered rather than when the
+ // plugin for the current style is unregistered.
+ QQuickThemePrivate::instance.reset();
+ QQuickStylePrivate::reset();
+}
+
+/*!
+ \internal
+
+ Responsible for setting the font and palette settings that were specified in the
+ qtquickcontrols2.conf file.
+
+ Style-specific settings (e.g. Variant=Dense) are read in the constructor of the
+ appropriate style plugin (e.g. QtQuickControls2MaterialStylePlugin).
+
+ Implicit style-specific font and palette values are assigned in the relevant theme
+ (e.g. QQuickMaterialTheme).
+*/
+QQuickTheme *QQuickStylePlugin::createTheme(const QString &name)
+{
+ qCDebug(lcStylePlugin) << "creating QQuickTheme instance to be initialized by style-specific theme of" << name;
+
+ QQuickTheme *theme = new QQuickTheme;
+#if QT_CONFIG(settings)
+ QQuickThemePrivate *p = QQuickThemePrivate::get(theme);
+ QSharedPointer<QSettings> settings = QQuickStylePrivate::settings(name);
+ if (settings) {
+ p->defaultFont.reset(QQuickStylePrivate::readFont(settings));
+ // Set the default font as the System scope, because that's what
+ // QQuickControlPrivate::parentFont() uses as its fallback if no
+ // parent item has a font explicitly set. QQuickControlPrivate::parentFont()
+ // is used as the starting point for font inheritance/resolution.
+ // The same goes for palettes below.
+ theme->setFont(QQuickTheme::System, *p->defaultFont);
+
+ p->defaultPalette.reset(QQuickStylePrivate::readPalette(settings));
+ theme->setPalette(QQuickTheme::System, *p->defaultPalette);
+ }
+#endif
+ QQuickThemePrivate::instance.reset(theme);
+ return theme;
}
QT_END_NAMESPACE
diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h
index 1a941aa7..0cc793a2 100644
--- a/src/quickcontrols2/qquickstyleplugin_p.h
+++ b/src/quickcontrols2/qquickstyleplugin_p.h
@@ -70,6 +70,8 @@ public:
void unregisterTypes() override;
private:
+ QQuickTheme *createTheme(const QString &name);
+
Q_DISABLE_COPY(QQuickStylePlugin)
};
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 28d00c2a..d64c4b67 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -30,4 +30,6 @@ SUBDIRS += \
sanity \
snippets \
styleimports \
+ styleimportscompiletimematerial \
+ styleimportscompiletimeqmlonly \
translation
diff --git a/tests/auto/shared/visualtestutil.h b/tests/auto/shared/visualtestutil.h
index cbc0bade..78c625ea 100644
--- a/tests/auto/shared/visualtestutil.h
+++ b/tests/auto/shared/visualtestutil.h
@@ -118,9 +118,14 @@ namespace QQuickVisualTestUtil
class QQuickApplicationHelper
{
public:
- QQuickApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath) :
- component(&engine)
+ QQuickApplicationHelper(QQmlDataTest *testCase, const QString &testFilePath,
+ const QStringList &qmlImportPaths = QStringList())
{
+ for (const auto &path : qmlImportPaths)
+ engine.addImportPath(path);
+
+ QQmlComponent component(&engine);
+
component.loadUrl(testCase->testFileUrl(testFilePath));
QObject *rootObject = component.create();
cleanup.reset(rootObject);
@@ -152,7 +157,6 @@ namespace QQuickVisualTestUtil
}
QQmlEngine engine;
- QQmlComponent component;
QScopedPointer<QObject> cleanup;
QQuickApplicationWindow *appWindow = nullptr;
QQuickWindow *window = nullptr;
diff --git a/tests/auto/styleimports/data/importImagineStyleWithoutControls.qml b/tests/auto/styleimports/data/importImagineStyleWithoutControls.qml
deleted file mode 100644
index cffec326..00000000
--- a/tests/auto/styleimports/data/importImagineStyleWithoutControls.qml
+++ /dev/null
@@ -1,57 +0,0 @@
-/****************************************************************************
-**
-** 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.Imagine
-
-ApplicationWindow {
- title: "Test Application Window"
- width: 400
- height: 400
-}
diff --git a/tests/auto/styleimports/data/importUniversalStyleWithoutControls.qml b/tests/auto/styleimports/data/importUniversalStyleWithoutControls.qml
deleted file mode 100644
index 9ff52d4f..00000000
--- a/tests/auto/styleimports/data/importUniversalStyleWithoutControls.qml
+++ /dev/null
@@ -1,57 +0,0 @@
-/****************************************************************************
-**
-** 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.Universal
-
-ApplicationWindow {
- title: "Test Application Window"
- width: 400
- height: 400
-}
diff --git a/tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml b/tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml
deleted file mode 100644
index 71cb18ee..00000000
--- a/tests/auto/styleimports/data/importWindowsStyleWithoutControls.qml
+++ /dev/null
@@ -1,57 +0,0 @@
-/****************************************************************************
-**
-** 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
deleted file mode 100644
index 5e91c29f..00000000
--- a/tests/auto/styleimports/data/importmacOSStyleWithoutControls.qml
+++ /dev/null
@@ -1,57 +0,0 @@
-/****************************************************************************
-**
-** 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 408f06c3..5e525b0f 100644
--- a/tests/auto/styleimports/tst_styleimports.cpp
+++ b/tests/auto/styleimports/tst_styleimports.cpp
@@ -61,9 +61,6 @@ private slots:
void platformSelectors();
- void importStyleWithoutControls_data();
- void importStyleWithoutControls();
-
void fallbackStyleShouldNotOverwriteTheme_data();
void fallbackStyleShouldNotOverwriteTheme();
};
@@ -208,44 +205,6 @@ void tst_StyleImports::platformSelectors()
#endif
}
-void tst_StyleImports::importStyleWithoutControls_data()
-{
- QTest::addColumn<QString>("style");
-
- const auto builtInStyles = QQuickStylePrivate::builtInStyles();
- for (const auto &styleName : builtInStyles)
- QTest::addRow(qPrintable(styleName)) << styleName;
-}
-
-// Tests that warnings are printed when trying to import a specific style without first importing QtQuick.Controls.
-void tst_StyleImports::importStyleWithoutControls()
-{
- QFETCH(QString, style);
-
- QQmlApplicationEngine engine;
- const QUrl url(testFileUrl(QString::fromLatin1("import%1StyleWithoutControls.qml").arg(style)));
- bool success = false;
-
- // Account for extra warnings for fallback styles.
- QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*Basic"));
- 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("Basic"))
- QTest::ignoreMessage(QtWarningMsg, QRegularExpression("QtQuick.Controls must be imported before importing.*" + style));
-
- QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
- this, [url, &success](QObject *obj, const QUrl &objUrl) {
- if (url == objUrl)
- success = obj;
- }, Qt::QueuedConnection);
-
- engine.load(url);
- // It should load, but with warnings.
- QTRY_VERIFY(success);
-}
-
void tst_StyleImports::fallbackStyleShouldNotOverwriteTheme_data()
{
QTest::addColumn<QString>("style");
diff --git a/tests/auto/styleimportscompiletimematerial/CMakeLists.txt b/tests/auto/styleimportscompiletimematerial/CMakeLists.txt
new file mode 100644
index 00000000..b5910e92
--- /dev/null
+++ b/tests/auto/styleimportscompiletimematerial/CMakeLists.txt
@@ -0,0 +1,62 @@
+# Generated from styleimports.pro.
+
+#####################################################################
+## tst_styleimports Test:
+#####################################################################
+
+# Collect test data
+file(GLOB_RECURSE test_data_glob
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ data/*)
+list(APPEND test_data ${test_data_glob})
+
+qt_add_test(tst_styleimports
+ SOURCES
+ ../shared/qtest_quickcontrols.h
+ ../shared/util.cpp ../shared/util.h
+ ../shared/visualtestutil.cpp ../shared/visualtestutil.h
+ tst_styleimports.cpp
+ DEFINES
+ QQC2_IMPORT_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}/../../../src/imports\\\"
+ PUBLIC_LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ Qt::QmlPrivate
+ Qt::QuickControls2
+ Qt::QuickControls2Private
+ Qt::QuickPrivate
+ Qt::QuickTemplates2Private
+ Qt::TestPrivate
+ TESTDATA ${test_data}
+)
+
+# Resources:
+set(qmake_resourcestyle_resource_files
+ "ResourceStyle/Button.qml"
+ "ResourceStyle/qmldir"
+)
+
+qt_add_resource(tst_styleimports "qmake_resourcestyle"
+ PREFIX
+ "/"
+ FILES
+ ${qmake_resourcestyle_resource_files}
+)
+
+
+#### Keys ignored in scope 1:.:.:styleimports.pro:<TRUE>:
+# OTHER_FILES = "data/*.qml" "data/qmldir" "data/FileSystemStyle/*.qml" "data/FileSystemStyle/qmldir" "data/PlatformStyle/*.qml" "data/PlatformStyle/+linux/*.qml" "data/PlatformStyle/+macos/*.qml" "data/PlatformStyle/+windows/*.qml" "data/PlatformStyle/qmldir"
+
+## Scopes:
+#####################################################################
+
+qt_extend_target(tst_styleimports CONDITION ANDROID OR IOS
+ DEFINES
+ QT_QMLTEST_DATADIR=\\\":/data\\\"
+)
+
+qt_extend_target(tst_styleimports CONDITION NOT ANDROID AND NOT IOS
+ DEFINES
+ QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\"
+)
diff --git a/tests/auto/styleimports/data/importMaterialStyleWithoutControls.qml b/tests/auto/styleimportscompiletimematerial/data/importMaterialStyleWithoutControls.qml
index b195f365..7cb4fd58 100644
--- a/tests/auto/styleimports/data/importMaterialStyleWithoutControls.qml
+++ b/tests/auto/styleimportscompiletimematerial/data/importMaterialStyleWithoutControls.qml
@@ -54,4 +54,11 @@ ApplicationWindow {
title: "Test Application Window"
width: 400
height: 400
+
+ property alias button: button
+
+ Button {
+ id: button
+ text: "Material Button"
+ }
}
diff --git a/tests/auto/styleimportscompiletimematerial/styleimportscompiletimematerial.pro b/tests/auto/styleimportscompiletimematerial/styleimportscompiletimematerial.pro
new file mode 100644
index 00000000..163f6bab
--- /dev/null
+++ b/tests/auto/styleimportscompiletimematerial/styleimportscompiletimematerial.pro
@@ -0,0 +1,15 @@
+CONFIG += testcase
+TARGET = tst_styleimportscompiletimematerial
+SOURCES += tst_styleimportscompiletimematerial.cpp
+
+macos:CONFIG -= app_bundle
+
+QT += testlib core-private gui-private qml-private quick-private quickcontrols2-private quicktemplates2-private
+
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+OTHER_FILES += \
+ data/*.qml
+
diff --git a/tests/auto/styleimportscompiletimematerial/tst_styleimportscompiletimematerial.cpp b/tests/auto/styleimportscompiletimematerial/tst_styleimportscompiletimematerial.cpp
new file mode 100644
index 00000000..c0f88b31
--- /dev/null
+++ b/tests/auto/styleimportscompiletimematerial/tst_styleimportscompiletimematerial.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qregularexpression.h>
+#include <QtTest/qtest.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlapplicationengine.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/private/qqmlmetatype_p.h>
+#include <QtQuick/qquickwindow.h>
+#include <QtQuickControls2/qquickstyle.h>
+#include <QtQuickControls2/private/qquickstyle_p.h>
+#include <QtQuickTemplates2/private/qquickbutton_p.h>
+
+#include "../shared/util.h"
+#include "../shared/visualtestutil.h"
+
+using namespace QQuickVisualTestUtil;
+
+class tst_StyleImportsCompileTimeMaterial : public QQmlDataTest
+{
+ Q_OBJECT
+
+private slots:
+ void importMaterialStyleWithoutControls();
+};
+
+void tst_StyleImportsCompileTimeMaterial::importMaterialStyleWithoutControls()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("importMaterialStyleWithoutControls.qml"));
+ QVERIFY2(helper.ready, helper.failureMessage());
+
+ auto button = helper.window->property("button").value<QQuickButton*>();
+ QVERIFY(button);
+ // The Material style sets a size 14 font for Button.
+ QCOMPARE(button->font().pixelSize(), 14);
+ const QTypeRevision latestControlsRevision = QQmlMetaType::latestModuleVersion(QLatin1String("QtQuick.Controls"));
+ QVERIFY2(!latestControlsRevision.isValid(), "QtQuick.Controls should not be imported when using compile-time style selection");
+}
+
+QTEST_MAIN(tst_StyleImportsCompileTimeMaterial)
+
+#include "tst_styleimportscompiletimematerial.moc"
diff --git a/tests/auto/styleimportscompiletimeqmlonly/CMakeLists.txt b/tests/auto/styleimportscompiletimeqmlonly/CMakeLists.txt
new file mode 100644
index 00000000..b5910e92
--- /dev/null
+++ b/tests/auto/styleimportscompiletimeqmlonly/CMakeLists.txt
@@ -0,0 +1,62 @@
+# Generated from styleimports.pro.
+
+#####################################################################
+## tst_styleimports Test:
+#####################################################################
+
+# Collect test data
+file(GLOB_RECURSE test_data_glob
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ data/*)
+list(APPEND test_data ${test_data_glob})
+
+qt_add_test(tst_styleimports
+ SOURCES
+ ../shared/qtest_quickcontrols.h
+ ../shared/util.cpp ../shared/util.h
+ ../shared/visualtestutil.cpp ../shared/visualtestutil.h
+ tst_styleimports.cpp
+ DEFINES
+ QQC2_IMPORT_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}/../../../src/imports\\\"
+ PUBLIC_LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ Qt::QmlPrivate
+ Qt::QuickControls2
+ Qt::QuickControls2Private
+ Qt::QuickPrivate
+ Qt::QuickTemplates2Private
+ Qt::TestPrivate
+ TESTDATA ${test_data}
+)
+
+# Resources:
+set(qmake_resourcestyle_resource_files
+ "ResourceStyle/Button.qml"
+ "ResourceStyle/qmldir"
+)
+
+qt_add_resource(tst_styleimports "qmake_resourcestyle"
+ PREFIX
+ "/"
+ FILES
+ ${qmake_resourcestyle_resource_files}
+)
+
+
+#### Keys ignored in scope 1:.:.:styleimports.pro:<TRUE>:
+# OTHER_FILES = "data/*.qml" "data/qmldir" "data/FileSystemStyle/*.qml" "data/FileSystemStyle/qmldir" "data/PlatformStyle/*.qml" "data/PlatformStyle/+linux/*.qml" "data/PlatformStyle/+macos/*.qml" "data/PlatformStyle/+windows/*.qml" "data/PlatformStyle/qmldir"
+
+## Scopes:
+#####################################################################
+
+qt_extend_target(tst_styleimports CONDITION ANDROID OR IOS
+ DEFINES
+ QT_QMLTEST_DATADIR=\\\":/data\\\"
+)
+
+qt_extend_target(tst_styleimports CONDITION NOT ANDROID AND NOT IOS
+ DEFINES
+ QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\"
+)
diff --git a/tests/auto/styleimports/data/importFusionStyleWithoutControls.qml b/tests/auto/styleimportscompiletimeqmlonly/data/QmlOnly/Button.qml
index ba61406f..73d94c1c 100644
--- a/tests/auto/styleimports/data/importFusionStyleWithoutControls.qml
+++ b/tests/auto/styleimportscompiletimeqmlonly/data/QmlOnly/Button.qml
@@ -48,10 +48,36 @@
**
****************************************************************************/
-import QtQuick.Controls.Fusion
+import QtQuick
+import QtQuick.Templates as T
-ApplicationWindow {
- title: "Test Application Window"
- width: 400
- height: 400
+T.Button {
+ id: control
+
+ implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
+ implicitContentWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
+ implicitContentHeight + topPadding + bottomPadding)
+
+ padding: 6
+ horizontalPadding: padding + 2
+ spacing: 6
+ font.pixelSize: 8
+
+ contentItem: T.Label {
+ text: control.text
+ font: control.font
+ color: control.checked || control.highlighted ? control.palette.brightText :
+ control.flat && !control.down ? (control.visualFocus ? control.palette.highlight : control.palette.windowText) : control.palette.buttonText
+ verticalAlignment: T.Label.AlignVCenter
+ }
+
+ background: Rectangle {
+ implicitWidth: 100
+ implicitHeight: 40
+ visible: !control.flat || control.down || control.checked || control.highlighted
+ color: "#ccc"
+ border.color: control.palette.highlight
+ border.width: control.visualFocus ? 2 : 0
+ }
}
diff --git a/tests/auto/styleimportscompiletimeqmlonly/data/QmlOnly/qmldir b/tests/auto/styleimportscompiletimeqmlonly/data/QmlOnly/qmldir
new file mode 100644
index 00000000..5e60f095
--- /dev/null
+++ b/tests/auto/styleimportscompiletimeqmlonly/data/QmlOnly/qmldir
@@ -0,0 +1,3 @@
+module QmlOnly
+Button 1.0 Button.qml
+import QtQuick.Controls.Basic
diff --git a/tests/auto/styleimports/data/importBasicStyleWithoutControls.qml b/tests/auto/styleimportscompiletimeqmlonly/data/importQmlOnlyStyleWithoutControls.qml
index 40e02666..027d5636 100644
--- a/tests/auto/styleimports/data/importBasicStyleWithoutControls.qml
+++ b/tests/auto/styleimportscompiletimeqmlonly/data/importQmlOnlyStyleWithoutControls.qml
@@ -48,10 +48,17 @@
**
****************************************************************************/
-import QtQuick.Controls.Basic
+import QmlOnly
ApplicationWindow {
title: "Test Application Window"
width: 400
height: 400
+
+ property alias button: button
+
+ Button {
+ id: button
+ text: "QmlOnly Button"
+ }
}
diff --git a/tests/auto/styleimportscompiletimeqmlonly/styleimportscompiletimeqmlonly.pro b/tests/auto/styleimportscompiletimeqmlonly/styleimportscompiletimeqmlonly.pro
new file mode 100644
index 00000000..3f3189c6
--- /dev/null
+++ b/tests/auto/styleimportscompiletimeqmlonly/styleimportscompiletimeqmlonly.pro
@@ -0,0 +1,17 @@
+CONFIG += testcase
+TARGET = tst_styleimportscompiletimeqmlonly
+SOURCES += tst_styleimportscompiletimeqmlonly.cpp
+
+macos:CONFIG -= app_bundle
+
+QT += testlib core-private gui-private qml-private quick-private quickcontrols2-private quicktemplates2-private
+
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+OTHER_FILES += \
+ data/*.qml \
+ data/QmlOnly/*.qml \
+ data/QmlOnly/qmldir
+
diff --git a/tests/auto/styleimportscompiletimeqmlonly/tst_styleimportscompiletimeqmlonly.cpp b/tests/auto/styleimportscompiletimeqmlonly/tst_styleimportscompiletimeqmlonly.cpp
new file mode 100644
index 00000000..7fd41ed9
--- /dev/null
+++ b/tests/auto/styleimportscompiletimeqmlonly/tst_styleimportscompiletimeqmlonly.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qregularexpression.h>
+#include <QtTest/qtest.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlapplicationengine.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQuick/qquickwindow.h>
+#include <QtQuickControls2/qquickstyle.h>
+#include <QtQuickControls2/private/qquickstyle_p.h>
+#include <QtQuickTemplates2/private/qquickbutton_p.h>
+
+#include "../shared/util.h"
+#include "../shared/visualtestutil.h"
+
+using namespace QQuickVisualTestUtil;
+
+class tst_StyleImportsCompileTimeQmlOnly : public QQmlDataTest
+{
+ Q_OBJECT
+
+private slots:
+ void importQmlOnlyStyleWithoutControls();
+};
+
+void tst_StyleImportsCompileTimeQmlOnly::importQmlOnlyStyleWithoutControls()
+{
+ QQuickApplicationHelper helper(this,
+ QLatin1String("importQmlOnlyStyleWithoutControls.qml"), QStringList() << dataDirectory());
+ QVERIFY2(helper.ready, helper.failureMessage());
+
+ auto button = helper.window->property("button").value<QQuickButton*>();
+ QVERIFY(button);
+ QCOMPARE(button->font().pixelSize(), 8);
+}
+
+QTEST_MAIN(tst_StyleImportsCompileTimeQmlOnly)
+
+#include "tst_styleimportscompiletimeqmlonly.moc"