From 32810acaa191ba00be5aac5d771c23b87628292c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 6 Oct 2016 00:11:25 +0200 Subject: Let specifying the fallback style for custom styles For example, you can call QQuickStyle::setStyle(":/mycontrols") and QQuickStyle::setFallbackStyle("Material") to select a custom style so that the missing files will fallback to the Material style. Notice that the Material and Universal styles do not contain all files. For example, the non-visual Control.qml, Container.qml are not duplicated. For these, we must fallback to the Default style that is guaranteed to contain them all. [ChangeLog][Controls] Added support for specifying the fallback style for custom styles via :/qtquickcontrols2.conf, QT_QUICK_CONTROLS_FALLBACK_STYLE or QQuickStyle::setFallbackStyle(). Change-Id: I00be1c8c6aaca875ef851c90d018e9b5e2f501b7 Reviewed-by: Mitch Curtis --- tests/auto/qquickstyleselector/data/Control.qml | 2 + .../data/FallbackStyle/Button.qml | 2 + .../data/FallbackStyle/Label.qml | 2 + tests/auto/qquickstyleselector/data/Label.qml | 2 + .../tst_qquickstyleselector.cpp | 75 ++++++++++++++++++++-- 5 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 tests/auto/qquickstyleselector/data/Control.qml create mode 100644 tests/auto/qquickstyleselector/data/FallbackStyle/Button.qml create mode 100644 tests/auto/qquickstyleselector/data/FallbackStyle/Label.qml create mode 100644 tests/auto/qquickstyleselector/data/Label.qml (limited to 'tests/auto/qquickstyleselector') diff --git a/tests/auto/qquickstyleselector/data/Control.qml b/tests/auto/qquickstyleselector/data/Control.qml new file mode 100644 index 00000000..697662f6 --- /dev/null +++ b/tests/auto/qquickstyleselector/data/Control.qml @@ -0,0 +1,2 @@ +import QtQuick.Templates 2.1 as T +T.Control { } diff --git a/tests/auto/qquickstyleselector/data/FallbackStyle/Button.qml b/tests/auto/qquickstyleselector/data/FallbackStyle/Button.qml new file mode 100644 index 00000000..ee17c230 --- /dev/null +++ b/tests/auto/qquickstyleselector/data/FallbackStyle/Button.qml @@ -0,0 +1,2 @@ +import QtQuick.Templates 2.1 as T +T.Button { } diff --git a/tests/auto/qquickstyleselector/data/FallbackStyle/Label.qml b/tests/auto/qquickstyleselector/data/FallbackStyle/Label.qml new file mode 100644 index 00000000..8879d93f --- /dev/null +++ b/tests/auto/qquickstyleselector/data/FallbackStyle/Label.qml @@ -0,0 +1,2 @@ +import QtQuick.Templates 2.1 as T +T.Label { } diff --git a/tests/auto/qquickstyleselector/data/Label.qml b/tests/auto/qquickstyleselector/data/Label.qml new file mode 100644 index 00000000..8879d93f --- /dev/null +++ b/tests/auto/qquickstyleselector/data/Label.qml @@ -0,0 +1,2 @@ +import QtQuick.Templates 2.1 as T +T.Label { } diff --git a/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp b/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp index 6c2aebe4..1e7d7add 100644 --- a/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp +++ b/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include "../shared/util.h" @@ -44,24 +45,82 @@ class tst_QQuickStyleSelector : public QQmlDataTest Q_OBJECT private slots: + void initTestCase(); + void select_data(); void select(); }; +void tst_QQuickStyleSelector::initTestCase() +{ + QQmlDataTest::initTestCase(); + QQuickStylePrivate::init(dataDirectoryUrl()); +} + void tst_QQuickStyleSelector::select_data() { QTest::addColumn("file"); QTest::addColumn("style"); QTest::addColumn("path"); + QTest::addColumn("fallback"); QTest::addColumn("expected"); - QTest::newRow("empty") << "Button.qml" << "" << dataDirectory() << testFileUrl("Button.qml").toString(); - QTest::newRow("no such dir") << "Button.qml" << "Foo" << dataDirectory() << testFileUrl("Button.qml").toString(); - QTest::newRow("no such file") << "Foo.qml" << "FileSystemStyle" << dataDirectory() << testFileUrl("Foo.qml").toString(); - QTest::newRow("relative/path/to/FileSystemStyle") << "Button.qml" << "FileSystemStyle" << "data" << testFileUrl("FileSystemStyle/Button.qml").toString(); - QTest::newRow("/absolute/path/to/FileSystemStyle") << "Button.qml" << "FileSystemStyle" << dataDirectory() << testFileUrl("FileSystemStyle/Button.qml").toString(); - QTest::newRow(":/ResourceStyle") << "Button.qml" << "ResourceStyle" << ":/" << "qrc:/ResourceStyle/Button.qml"; - QTest::newRow("qrc:/ResourceStyle") << "Button.qml" << "ResourceStyle" << "qrc:/" << "qrc:/ResourceStyle/Button.qml"; + // Control.qml exists only in the default style + QTest::newRow("control") << "Control.qml" << "" << "data" << "" << testFileUrl("Control.qml").toString(); + QTest::newRow("/control") << "Control.qml" << "" << dataDirectory() << "" << testFileUrl("Control.qml").toString(); + QTest::newRow("fs/control") << "Control.qml" << "FileSystemStyle" << "data" << "" << testFileUrl("Control.qml").toString(); + QTest::newRow("/fs/control") << "Control.qml" << "FileSystemStyle" << dataDirectory() << "" << testFileUrl("Control.qml").toString(); + QTest::newRow(":/control") << "Control.qml" << "ResourceStyle" << ":/" << "" << testFileUrl("Control.qml").toString(); + QTest::newRow("qrc:/control") << "Control.qml" << "ResourceStyle" << "qrc:/" << "" << testFileUrl("Control.qml").toString(); + QTest::newRow("nosuch/control") << "Control.qml" << "NoSuchStyle" << "data" << "" << testFileUrl("Control.qml").toString(); + QTest::newRow("/nosuch/control") << "Control.qml" << "NoSuchStyle" << dataDirectory() << "" << testFileUrl("Control.qml").toString(); + + QTest::newRow("control->base") << "Control.qml" << "" << "data" << "FallbackStyle" << testFileUrl("Control.qml").toString(); + QTest::newRow("/control->base") << "Control.qml" << "" << dataDirectory() << "FallbackStyle" << testFileUrl("Control.qml").toString(); + QTest::newRow("fs/control->base") << "Control.qml" << "FileSystemStyle" << "data" << "FallbackStyle" << testFileUrl("Control.qml").toString(); + QTest::newRow("/fs/control->base") << "Control.qml" << "FileSystemStyle" << dataDirectory() << "FallbackStyle" << testFileUrl("Control.qml").toString(); + QTest::newRow(":/control->base") << "Control.qml" << "ResourceStyle" << ":/" << "FallbackStyle" << testFileUrl("Control.qml").toString(); + QTest::newRow("qrc:/control->base") << "Control.qml" << "ResourceStyle" << "qrc:/" << "FallbackStyle" << testFileUrl("Control.qml").toString(); + QTest::newRow("nosuch/control->base") << "Control.qml" << "NoSuchStyle" << "data" << "FallbackStyle" << testFileUrl("Control.qml").toString(); + QTest::newRow("/nosuch/control->base") << "Control.qml" << "NoSuchStyle" << dataDirectory() << "FallbackStyle" << testFileUrl("Control.qml").toString(); + + // Label.qml exists in the default and fallback styles + QTest::newRow("label") << "Label.qml" << "" << "data" << "" << testFileUrl("Label.qml").toString(); + QTest::newRow("/label") << "Label.qml" << "" << dataDirectory() << "" << testFileUrl("Label.qml").toString(); + QTest::newRow("fs/label") << "Label.qml" << "FileSystemStyle" << "data" << "" << testFileUrl("Label.qml").toString(); + QTest::newRow("/fs/label") << "Label.qml" << "FileSystemStyle" << dataDirectory() << "" << testFileUrl("Label.qml").toString(); + QTest::newRow(":/label") << "Label.qml" << "ResourceStyle" << ":/" << "" << testFileUrl("Label.qml").toString(); + QTest::newRow("qrc:/label") << "Label.qml" << "ResourceStyle" << "qrc:/" << "" << testFileUrl("Label.qml").toString(); + QTest::newRow("nosuch/label") << "Label.qml" << "NoSuchStyle" << "data" << "" << testFileUrl("Label.qml").toString(); + QTest::newRow("/nosuch/label") << "Label.qml" << "NoSuchStyle" << dataDirectory() << "" << testFileUrl("Label.qml").toString(); + + QTest::newRow("label->base") << "Label.qml" << "" << "data" << "FallbackStyle" << testFileUrl("FallbackStyle/Label.qml").toString(); + QTest::newRow("/label->base") << "Label.qml" << "" << dataDirectory() << "FallbackStyle" << testFileUrl("Label.qml").toString(); + QTest::newRow("fs/label->base") << "Label.qml" << "FileSystemStyle" << "data" << "FallbackStyle" << testFileUrl("FallbackStyle/Label.qml").toString(); + QTest::newRow("/fs/label->base") << "Label.qml" << "FileSystemStyle" << dataDirectory() << "FallbackStyle" << testFileUrl("FallbackStyle/Label.qml").toString(); + QTest::newRow(":/label->base") << "Label.qml" << "ResourceStyle" << ":/" << "FallbackStyle" << testFileUrl("FallbackStyle/Label.qml").toString(); + QTest::newRow("qrc:/label->base") << "Label.qml" << "ResourceStyle" << "qrc:/" << "FallbackStyle" << testFileUrl("FallbackStyle/Label.qml").toString(); + QTest::newRow("nosuch/label->base") << "Label.qml" << "NoSuchStyle" << "data" << "FallbackStyle" << testFileUrl("FallbackStyle/Label.qml").toString(); + QTest::newRow("/nosuch/label->base") << "Label.qml" << "NoSuchStyle" << dataDirectory() << "FallbackStyle" << testFileUrl("FallbackStyle/Label.qml").toString(); + + // Button.qml exists in all styles including the fs and qrc styles + QTest::newRow("button") << "Button.qml" << "" << "data" << "" << testFileUrl("Button.qml").toString(); + QTest::newRow("/button") << "Button.qml" << "" << dataDirectory() << "" << testFileUrl("Button.qml").toString(); + QTest::newRow("fs/button") << "Button.qml" << "FileSystemStyle" << "data" << "" << testFileUrl("FileSystemStyle/Button.qml").toString(); + QTest::newRow("/fs/button") << "Button.qml" << "FileSystemStyle" << dataDirectory() << "" << testFileUrl("FileSystemStyle/Button.qml").toString(); + QTest::newRow(":/button") << "Button.qml" << "ResourceStyle" << ":/" << "" << "qrc:/ResourceStyle/Button.qml"; + QTest::newRow("qrc:/button") << "Button.qml" << "ResourceStyle" << "qrc:/" << "" << "qrc:/ResourceStyle/Button.qml"; + QTest::newRow("nosuch/button") << "Button.qml" << "NoSuchStyle" << "data" << "" << testFileUrl("Button.qml").toString(); + QTest::newRow("/nosuch/button") << "Button.qml" << "NoSuchStyle" << dataDirectory() << "" << testFileUrl("Button.qml").toString(); + + QTest::newRow("button->base") << "Button.qml" << "" << "data" << "FallbackStyle" << testFileUrl("FallbackStyle/Button.qml").toString(); + QTest::newRow("/button->base") << "Button.qml" << "" << dataDirectory() << "FallbackStyle" << testFileUrl("Button.qml").toString(); + QTest::newRow("fs/button->base") << "Button.qml" << "FileSystemStyle" << "data" << "FallbackStyle" << testFileUrl("FileSystemStyle/Button.qml").toString(); + QTest::newRow("/fs/button->base") << "Button.qml" << "FileSystemStyle" << dataDirectory() << "FallbackStyle" << testFileUrl("FileSystemStyle/Button.qml").toString(); + QTest::newRow(":/button->base") << "Button.qml" << "ResourceStyle" << ":/" << "FallbackStyle" << "qrc:/ResourceStyle/Button.qml"; + QTest::newRow("qrc:/button->base") << "Button.qml" << "ResourceStyle" << "qrc:/" << "FallbackStyle" << "qrc:/ResourceStyle/Button.qml"; + QTest::newRow("nosuch/button->base") << "Button.qml" << "NoSuchStyle" << "data" << "FallbackStyle" << testFileUrl("FallbackStyle/Button.qml").toString(); + QTest::newRow("/nosuch/button->base") << "Button.qml" << "NoSuchStyle" << dataDirectory() << "FallbackStyle" << testFileUrl("FallbackStyle/Button.qml").toString(); } void tst_QQuickStyleSelector::select() @@ -69,9 +128,11 @@ void tst_QQuickStyleSelector::select() QFETCH(QString, file); QFETCH(QString, style); QFETCH(QString, path); + QFETCH(QString, fallback); QFETCH(QString, expected); QQuickStyle::setStyle(QDir(path).filePath(style)); + QQuickStyle::setFallbackStyle(fallback); QQuickStyleSelector selector; selector.setBaseUrl(dataDirectoryUrl()); -- cgit v1.2.3