Commit Graph

11 Commits

Author SHA1 Message Date
Mitch Curtis 501bc44bb0 Use qmlRegisterModuleImport() to register styles
This patch completes the cumulative work done in previous patches.

- Uses qmlRegisterModuleImport() to register styles. This has some
  added requirements:
  - Each style must now be a QML module -- that is, it must have a
    qmldir file.
  - As a result of the above, the module must be available within the
    QML import path in order to be found.
  - The various forms of accepted style names have been reduced down to
    one ("Material", "MyStyle", etc). See below for an explanation of
    why.
  - The following API in QQuickStyle is removed:
    addStylePath(), availableStyles(), path(), stylePathList(). These
    no longer make sense now that we reuse the existing QML import
    system.
- Adds the tst_qquickstyleselector auto test back as "styleimports".

qmlRegisterModuleImport() vs resolvedUrl()

    Previously we would use QQuickStyleSelector to select individual
    QML files based on which style was set. We'd do this once when
    QtQuick.Controls was first imported.

    With Qt 6, and the requirement that each style be a proper QML
    module, qmlRegisterModuleImport() was introduced. This allows us
    to "link" one import with another. For an example of what this
    looks like in practice, suppose the style was set to "MyStyle",
    and the fallback to "Material". The "QtQuick.Controls" import
    will be linked to "MyStyle", "MyStyle" to
    "QtQuick.Controls.Material", and as a final fallback (for controls
    like Action which only the Default style implements),
    "QtQuick.Controls.Material" to "QtQuick.Controls.Default".
    This is the same behavior as in Qt 5 (see qquickstyleselector.cpp):

    // 1) requested style (e.g. "MyStyle", included in d->selectors)
    // 2) fallback style (e.g. "Material", included in d->selectors)
    // 3) default style (empty selector, not in d->selectors)

    This is a necessary step to enable compilation of QML to C++.

Reducing the set of accepted style names

    The problem

    In QtQuickControls2Plugin() we need to call
    QQuickStylePrivate::init(baseUrl()) in order to detect if the style
    is a custom style in QQuickStyleSpec::resolve() (by checking if the
    style path starts with the base URL). In Qt 5, init() is called in
    QtQuickControls2Plugin::registerTypes(), but in Qt 6 that's too
    late, because we need to call qmlRegisterModuleImport() in the
    constructor. qmlRegisterModuleImport() itself requires the style to
    have already been set in order to create the correct import URI
    ("QtQuick.Controls.X" for built-in styles, "MyCustomStyle" for
    custom styles).

    The solution

    By reducing the valid forms for style names down to one:

    ./myapp -style MyStyle

    we solve the problem of needing baseUrl() to determine if the
    style is a custom style or not, but needing to call it too early
    (since we now call qmlRegisterModuleImport() in
    QtQuickControls2Plugin(), which itself requires the style to have
    already been set). baseUrl() can't have been set before the
    constructor is finished.

    All of the various forms for _setting_ a style are still valid;
    environment variables, qtquickcontrols2.conf, etc.

[ChangeLog][Important Behavior Changes] Custom styles must now have
a qmldir that lists the files that the style implements. For example,
for a style that only implements Button:
---
module MyStyle
Button 1.0 Button.qml
---
In addition, there is now only one valid, case-sensitive form for style
names: "Material", "MyStyle", etc.
These changes are done to help enable the compilation of QML code to
C++, as well as improve tooling capabilities.

[ChangeLog][Important Behavior Changes] The following API was removed:
- QQuickStyle::addStylePath()
- QQuickStyle::availableStyles()
- QQuickStyle::path()
- QQuickStyle::stylePathList()
- QT_QUICK_CONTROLS_STYLE_PATH
This API is no longer necessary and/or able to be provided now that
styles are treated as regular QML modules.

Task-number: QTBUG-82922
Change-Id: I3b281131903c7c3c1cf0616eb7486a872dccd730
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-08-26 11:46:07 +02:00
Mitch Curtis f2e06ce60a Replace testbench with newer "style testbench"
The style testbench was developed to provide a way for designers to
test out their Imagine style assets, but since it is now more
feature-rich than the old testbench, it seems like a good idea to
replace it.

The tool is described in README.md.

Change-Id: I9abec1bc294fd176e2255e067af280b378961551
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
2017-09-25 12:03:29 +00:00
J-P Nurmi 51240b75cc Update license headers to silence qtqa/tst_license warnings
Sync with the qtbase/header.XXX. The license headers were matching
qtbase/header.XXX-OLD, which makes qtqa/tst_license flood warnings:

   Old license being used for foo.qdoc

Change-Id: I199bf303a2d648e0d5f7bc01cb0814a5f945eeff
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2017-02-24 13:04:52 +00:00
J-P Nurmi 00a062649b Welcome to 2017
Change-Id: If68cff4efacc7dc5719c8b8e61937e85e9076870
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2017-01-09 17:29:40 +00:00
Mitch Curtis 4d2bd6929a testbench: rename main.qml to testbench.qml
This is one less main.qml to search through.

Change-Id: I2d0a8a56a779a6d6acac579d44c641dea318fb3d
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
2016-10-26 11:38:12 +00:00
J-P Nurmi 7e7d6d6c73 Rename env vars (QT_LABS_CONTROLS_XXX -> QT_QUICK_CONTROLS_XXX)
Change-Id: Ie903d3491b03d4ec05dd28462a19ee464331d2a2
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
2016-04-22 06:28:58 +00:00
J-P Nurmi 5f215fcdd3 testbench: fix the comment about use qputenv()
Refer to qputenv() instead of qsetenv(), and remove the mention of
QT_QUICK_FILE_SELECTORS that is no longer supported.

Change-Id: Ifada695afb1815e3b709d147250d297915550c16
Task-number: QTBUG-49891
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
2015-12-15 12:14:14 +00:00
J-P Nurmi 6fe4cb2e47 testbench: add support for slow motion animations
Useful for debugging animations. Usage:

    ./testbench -slow

Change-Id: Ic509c8da428dd08eddc9f445f942e3362bad9004
Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
2015-11-26 17:26:11 +00:00
Mitch Curtis 62287bed3e Scale testbench automatically
Change-Id: Ie362fa22b3280733783e7ec2293a98e737717257
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
2015-11-13 10:33:35 +00:00
Mitch Curtis 72f3a5a095 Update testbench
Move some things around. Also, begin to set all themes in
main.qml. There will be at least two unused themes instantiated,
but it doesn't matter, as it's just a manual test.

Change-Id: Icd8b24d3db3068e05b35de5ce55b4d418a530e5e
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
2015-10-30 15:41:22 +00:00
Mitch Curtis 8e1df766cf Add testbench as a manual test
This allows us to see every state for each control, and will help
with collaboration with designers.

Change-Id: I5589b05ef3abf768d26f14bbd85aa674107d956b
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
2015-10-21 13:36:36 +00:00