diff options
-rw-r--r-- | src/quickcontrols2/qquickstyle.cpp | 83 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyle.h | 1 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyle_p.h | 3 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyleselector.cpp | 63 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyleselector_p_p.h | 5 | ||||
-rw-r--r-- | tests/auto/qquickstyle/qquickstyle.pro | 1 | ||||
-rw-r--r-- | tests/auto/qquickstyle/tst_qquickstyle.cpp | 27 | ||||
-rw-r--r-- | tests/auto/qquickstyleselector/data/Control.qml | 2 | ||||
-rw-r--r-- | tests/auto/qquickstyleselector/data/FallbackStyle/Button.qml | 2 | ||||
-rw-r--r-- | tests/auto/qquickstyleselector/data/FallbackStyle/Label.qml | 2 | ||||
-rw-r--r-- | tests/auto/qquickstyleselector/data/Label.qml | 2 | ||||
-rw-r--r-- | tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp | 75 |
12 files changed, 235 insertions, 31 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index 489eee15..7bd183a0 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -85,7 +85,7 @@ QT_BEGIN_NAMESPACE struct QQuickStyleSpec { - QQuickStyleSpec() : resolved(false) { } + QQuickStyleSpec() : custom(false), resolved(false) { } QString name() { @@ -111,6 +111,12 @@ struct QQuickStyleSpec resolve(); } + void setFallbackStyle(const QString &fallback, const QByteArray &method) + { + fallbackStyle = fallback; + fallbackMethod = method; + } + static QString findStyle(const QString &path, const QString &name) { QDir dir(path); @@ -135,11 +141,18 @@ struct QQuickStyleSpec style = QGuiApplicationPrivate::styleOverride; if (style.isEmpty()) style = QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_STYLE")); - if (style.isEmpty()) { + if (fallbackStyle.isEmpty()) + setFallbackStyle(QString::fromLatin1(qgetenv("QT_QUICK_CONTROLS_FALLBACK_STYLE")), "QT_QUICK_CONTROLS_FALLBACK_STYLE"); + if (style.isEmpty() || fallbackStyle.isEmpty()) { QSharedPointer<QSettings> settings = QQuickStyleAttached::settings(QStringLiteral("Controls")); - if (settings) - style = settings->value(QStringLiteral("Style")).toString(); + if (settings) { + if (style.isEmpty()) + style = settings->value(QStringLiteral("Style")).toString(); + if (fallbackStyle.isEmpty()) + setFallbackStyle(settings->value(QStringLiteral("FallbackStyle")).toString(), ":/qtquickcontrols2.conf"); + } } + custom = style.contains(QLatin1Char('/')); if (baseUrl.isValid()) { QString path = QQmlFile::urlToLocalFileOrQrc(baseUrl); @@ -151,7 +164,7 @@ struct QQuickStyleSpec } if (QGuiApplication::instance()) { - if (!style.contains(QLatin1Char('/'))) { + if (!custom) { const QString targetPath = QStringLiteral("QtQuick/Controls.2"); const QStringList importPaths = QQmlEngine().importPathList(); @@ -168,15 +181,54 @@ struct QQuickStyleSpec } } + void reset() + { + custom = false; + resolved = false; + style.clear(); + fallbackStyle.clear(); + fallbackMethod.clear(); + } + + bool custom; bool resolved; QString style; + QString fallbackStyle; + QByteArray fallbackMethod; }; Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) +QString QQuickStylePrivate::fallbackStyle() +{ + return styleSpec()->fallbackStyle; +} + +bool QQuickStylePrivate::isCustomStyle() +{ + return styleSpec()->custom; +} + void QQuickStylePrivate::init(const QUrl &baseUrl) { - styleSpec()->resolve(baseUrl); + QQuickStyleSpec *spec = styleSpec(); + spec->resolve(baseUrl); + + if (!spec->fallbackStyle.isEmpty()) { + QString fallbackStyle = spec->findStyle(baseUrl.toLocalFile(), spec->fallbackStyle); + if (fallbackStyle.isEmpty()) { + if (spec->fallbackStyle.compare(QStringLiteral("Default")) != 0) { + qWarning() << "ERROR: unable to locate fallback style" << spec->fallbackStyle; + qInfo().nospace().noquote() << spec->fallbackMethod << ": the fallback style must be the name of one of the built-in Qt Quick Controls 2 styles."; + } + spec->fallbackStyle.clear(); + } + } +} + +void QQuickStylePrivate::reset() +{ + styleSpec()->reset(); } /*! @@ -220,4 +272,23 @@ void QQuickStyle::setStyle(const QString &style) styleSpec()->setStyle(style); } +/*! + \since 5.9 + Sets the application fallback style to \a style. + + \note The fallback style must be the name of one of the built-in Qt Quick Controls 2 styles, e.g. "Material". + + \note The style must be configured \b before loading QML that imports Qt Quick Controls 2. + It is not possible to change the style after the QML types have been registered. +*/ +void QQuickStyle::setFallbackStyle(const QString &style) +{ + if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), 2, 0)) { + qWarning() << "ERROR: QQuickStyle::setFallbackStyle() must be called before loading QML that imports Qt Quick Controls 2."; + return; + } + + styleSpec()->setFallbackStyle(style, "QQuickStyle::setFallbackStyle()"); +} + QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyle.h b/src/quickcontrols2/qquickstyle.h index 4476a29a..d2e7faf1 100644 --- a/src/quickcontrols2/qquickstyle.h +++ b/src/quickcontrols2/qquickstyle.h @@ -49,6 +49,7 @@ public: static QString name(); static QString path(); static void setStyle(const QString &style); + static void setFallbackStyle(const QString &style); }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index 594e71c8..cfe87fbb 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -56,7 +56,10 @@ QT_BEGIN_NAMESPACE class Q_QUICKCONTROLS2_PRIVATE_EXPORT QQuickStylePrivate { public: + static QString fallbackStyle(); + static bool isCustomStyle(); static void init(const QUrl &baseUrl); + static void reset(); }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp index 866280a7..8dbbc064 100644 --- a/src/quickcontrols2/qquickstyleselector.cpp +++ b/src/quickcontrols2/qquickstyleselector.cpp @@ -35,12 +35,14 @@ #include "qquickstyleselector_p.h" #include "qquickstyleselector_p_p.h" #include "qquickstyle.h" +#include "qquickstyle_p.h" #include <QtCore/qdir.h> #include <QtCore/qfile.h> #include <QtCore/qfileinfo.h> #include <QtCore/qsysinfo.h> #include <QtCore/qlocale.h> +#include <QtQml/qqmlfile.h> #include <QtCore/private/qfileselector_p.h> #include <QtGui/private/qguiapplication_p.h> @@ -56,6 +58,13 @@ static bool isLocalScheme(const QString &scheme) return local; } +static QString ensureSlash(const QString &path) +{ + if (path.endsWith(QLatin1Char('/'))) + return path; + return path + QLatin1Char('/'); +} + static QStringList allSelectors(const QString &style = QString()) { static const QStringList platformSelectors = QFileSelectorPrivate::platformSelectors(); @@ -75,17 +84,34 @@ QString QQuickStyleSelectorPrivate::select(const QString &filePath) const const QString path = fi.path(); const QString ret = QFileSelectorPrivate::selectionHelper(path.isEmpty() ? QString() : path + QLatin1Char('/'), - fi.fileName(), allSelectors(style), QChar()); + fi.fileName(), allSelectors(styleName), QChar()); if (!ret.isEmpty()) return ret; return filePath; } +QString QQuickStyleSelectorPrivate::trySelect(const QString &filePath, const QString &fallback) const +{ + QFileInfo fi(filePath); + if (!fi.exists()) + return fallback; + + // the path contains the name of the custom/fallback style, so exclude it from + // the selectors. the rest of the selectors (os, locale) are still valid, though. + const QString path = fi.path(); + const QString selectedPath = QFileSelectorPrivate::selectionHelper(path.isEmpty() ? QString() : path + QLatin1Char('/'), + fi.fileName(), allSelectors(), QChar()); + if (selectedPath.startsWith(QLatin1Char(':'))) + return QLatin1String("qrc") + selectedPath; + return QUrl::fromLocalFile(QFileInfo(selectedPath).absoluteFilePath()).toString(); +} + QQuickStyleSelector::QQuickStyleSelector() : d_ptr(new QQuickStyleSelectorPrivate) { Q_D(QQuickStyleSelector); - d->style = QQuickStyle::name(); + d->styleName = QQuickStyle::name(); + d->stylePath = QQuickStyle::path(); } QQuickStyleSelector::~QQuickStyleSelector() @@ -102,29 +128,32 @@ void QQuickStyleSelector::setBaseUrl(const QUrl &url) { Q_D(QQuickStyleSelector); d->baseUrl = url; + d->basePath = QQmlFile::urlToLocalFileOrQrc(url.toString(QUrl::StripTrailingSlash) + QLatin1Char('/')); } QString QQuickStyleSelector::select(const QString &fileName) const { Q_D(const QQuickStyleSelector); - const QString overridePath = QQuickStyle::path(); - if (!overridePath.isEmpty()) { - const QString stylePath = overridePath + d->style + QLatin1Char('/'); - if (QFile::exists(stylePath + fileName)) { - // the style name is included to the path, so exclude it from the selectors. - // the rest of the selectors (os, locale) are still valid, though. - const QString selectedPath = QFileSelectorPrivate::selectionHelper(stylePath, fileName, allSelectors(), QChar()); - if (selectedPath.startsWith(QLatin1Char(':'))) - return QLatin1String("qrc") + selectedPath; - return QUrl::fromLocalFile(QFileInfo(selectedPath).absoluteFilePath()).toString(); - } + + // 1) try selecting from a custom style path, for example ":/mystyle" + if (QQuickStylePrivate::isCustomStyle()) { + // NOTE: this path may contain a subset of controls + const QString selectedPath = d->trySelect(ensureSlash(d->stylePath) + d->styleName + QLatin1Char('/') + fileName); + if (!selectedPath.isEmpty()) + return selectedPath; } - QString base = d->baseUrl.toString(); - if (!base.isEmpty() && !base.endsWith(QLatin1Char('/'))) - base += QLatin1Char('/'); + // 2) try selecting from the fallback style path, for example QT_INSTALL_QML/QtQuick/Controls.2/Material + const QString fallbackStyle = QQuickStylePrivate::fallbackStyle(); + if (!fallbackStyle.isEmpty()) { + // NOTE: this path may also contain a subset of controls + const QString selectedPath = d->trySelect(ensureSlash(d->basePath) + fallbackStyle + QLatin1Char('/') + fileName); + if (!selectedPath.isEmpty()) + return selectedPath; + } - QUrl url(base + fileName); + // 3) fallback to the default style that is guaranteed to contain all controls + QUrl url(ensureSlash(d->baseUrl.toString()) + fileName); if (isLocalScheme(url.scheme())) { QString equivalentPath = QLatin1Char(':') + url.path(); QString selectedPath = d->select(equivalentPath); diff --git a/src/quickcontrols2/qquickstyleselector_p_p.h b/src/quickcontrols2/qquickstyleselector_p_p.h index cc3f0a58..4ff28d5d 100644 --- a/src/quickcontrols2/qquickstyleselector_p_p.h +++ b/src/quickcontrols2/qquickstyleselector_p_p.h @@ -54,9 +54,12 @@ class QQuickStyleSelectorPrivate { public: QString select(const QString &filePath) const; + QString trySelect(const QString &filePath, const QString &fallback = QString()) const; QUrl baseUrl; - QString style; + QString basePath; + QString styleName; + QString stylePath; }; QT_END_NAMESPACE diff --git a/tests/auto/qquickstyle/qquickstyle.pro b/tests/auto/qquickstyle/qquickstyle.pro index b6173c1b..5514685a 100644 --- a/tests/auto/qquickstyle/qquickstyle.pro +++ b/tests/auto/qquickstyle/qquickstyle.pro @@ -5,3 +5,4 @@ SOURCES += tst_qquickstyle.cpp osx:CONFIG -= app_bundle QT += quickcontrols2 testlib +QT_PRIVATE += core-private gui-private quickcontrols2-private diff --git a/tests/auto/qquickstyle/tst_qquickstyle.cpp b/tests/auto/qquickstyle/tst_qquickstyle.cpp index 11ff58e7..15edc67b 100644 --- a/tests/auto/qquickstyle/tst_qquickstyle.cpp +++ b/tests/auto/qquickstyle/tst_qquickstyle.cpp @@ -38,15 +38,28 @@ #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> #include <QtQuickControls2/qquickstyle.h> +#include <QtQuickControls2/private/qquickstyle_p.h> +#include <QtGui/private/qguiapplication_p.h> class tst_QQuickStyle : public QObject { Q_OBJECT private slots: + void init(); void lookup(); + void commandLineArgument(); + void environmentVariables(); }; +void tst_QQuickStyle::init() +{ + QQuickStylePrivate::reset(); + QGuiApplicationPrivate::styleOverride.clear(); + qunsetenv("QT_QUICK_CONTROLS_STYLE"); + qunsetenv("QT_QUICK_CONTROLS_FALLBACK_STYLE"); +} + void tst_QQuickStyle::lookup() { QVERIFY(QQuickStyle::name().isEmpty()); @@ -67,6 +80,20 @@ void tst_QQuickStyle::lookup() QVERIFY(!QQuickStyle::path().isEmpty()); } +void tst_QQuickStyle::commandLineArgument() +{ + QGuiApplicationPrivate::styleOverride = "CmdLineArgStyle"; + QCOMPARE(QQuickStyle::name(), QString("CmdLineArgStyle")); +} + +void tst_QQuickStyle::environmentVariables() +{ + qputenv("QT_QUICK_CONTROLS_STYLE", "EnvVarStyle"); + qputenv("QT_QUICK_CONTROLS_FALLBACK_STYLE", "EnvVarFallbackStyle"); + QCOMPARE(QQuickStyle::name(), QString("EnvVarStyle")); + QCOMPARE(QQuickStylePrivate::fallbackStyle(), QString("EnvVarFallbackStyle")); +} + QTEST_MAIN(tst_QQuickStyle) #include "tst_qquickstyle.moc" 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 <QtTest/qtest.h> #include <QtQuickControls2/qquickstyle.h> +#include <QtQuickControls2/private/qquickstyle_p.h> #include <QtQuickControls2/private/qquickstyleselector_p.h> #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<QString>("file"); QTest::addColumn<QString>("style"); QTest::addColumn<QString>("path"); + QTest::addColumn<QString>("fallback"); QTest::addColumn<QString>("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()); |