diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-28 16:00:04 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-11-30 13:47:19 +0000 |
commit | 5efd4b6a61498f0668d7367d620275367894140e (patch) | |
tree | c85fcbe0a56630d01e463842d3b86bf1d62952f1 /src | |
parent | f6d2a9dd20b3661bea13b73e09c4f0285c1cd67a (diff) |
Allow specifying a relative style path in qtquickcontrols2.conf
The style path is resolved relative to the location of config file.
Even though qtquickcontrols2.conf is normally located in the root of
resources, Quick Designer uses QT_QUICK_CONTROLS_CONF to set a custom
location for the preview, where the standard config location is not
feasible.
This patch extends the config and style lookup further by allowing
to specify a relative path to a custom style for the Quick Designer
preview.
Change-Id: Iad9c459421eefbf7a5bcbedfea59f5f16a1d3a39
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quickcontrols2/qquickstyle.cpp | 29 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyle_p.h | 1 | ||||
-rw-r--r-- | src/quickcontrols2/qquickstyleattached.cpp | 15 |
3 files changed, 32 insertions, 13 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp index d7143be7..3ad7c074 100644 --- a/src/quickcontrols2/qquickstyle.cpp +++ b/src/quickcontrols2/qquickstyle.cpp @@ -183,6 +183,15 @@ struct QQuickStyleSpec setFallbackStyle(settings->value(QStringLiteral("FallbackStyle")).toString(), ":/qtquickcontrols2.conf"); } } + + // resolve a path relative to the config + QString configPath = QFileInfo(resolveConfigFilePath()).path(); + QString stylePath = findStyle(configPath, style); + if (!stylePath.isEmpty()) { + style = stylePath; + resolved = true; + } + custom = style.contains(QLatin1Char('/')); if (baseUrl.isValid()) { @@ -221,11 +230,26 @@ struct QQuickStyleSpec fallbackMethod.clear(); } + QString resolveConfigFilePath() + { + if (configFilePath.isEmpty()) { + configFilePath = QFile::decodeName(qgetenv("QT_QUICK_CONTROLS_CONF")); + if (!QFile::exists(configFilePath)) { + if (!configFilePath.isEmpty()) + qWarning("QT_QUICK_CONTROLS_CONF=%s: No such file", qPrintable(configFilePath)); + + configFilePath = QStringLiteral(":/qtquickcontrols2.conf"); + } + } + return configFilePath; + } + bool custom; bool resolved; QString style; QString fallbackStyle; QByteArray fallbackMethod; + QString configFilePath; }; Q_GLOBAL_STATIC(QQuickStyleSpec, styleSpec) @@ -262,6 +286,11 @@ void QQuickStylePrivate::reset() styleSpec()->reset(); } +QString QQuickStylePrivate::configFilePath() +{ + return styleSpec()->resolveConfigFilePath(); +} + /*! Returns the name of the application style. diff --git a/src/quickcontrols2/qquickstyle_p.h b/src/quickcontrols2/qquickstyle_p.h index cfe87fbb..65f48d95 100644 --- a/src/quickcontrols2/qquickstyle_p.h +++ b/src/quickcontrols2/qquickstyle_p.h @@ -60,6 +60,7 @@ public: static bool isCustomStyle(); static void init(const QUrl &baseUrl); static void reset(); + static QString configFilePath(); }; QT_END_NAMESPACE diff --git a/src/quickcontrols2/qquickstyleattached.cpp b/src/quickcontrols2/qquickstyleattached.cpp index 2ef07fd6..d1f27ff3 100644 --- a/src/quickcontrols2/qquickstyleattached.cpp +++ b/src/quickcontrols2/qquickstyleattached.cpp @@ -35,6 +35,7 @@ ****************************************************************************/ #include "qquickstyleattached_p.h" +#include "qquickstyle_p.h" #include <QtCore/qfile.h> #include <QtCore/qsettings.h> @@ -167,18 +168,6 @@ static QList<QQuickStyleAttached *> findChildStyles(const QMetaObject *type, QOb return children; } -static QString resolveConfigFile() -{ - QString filePath = QFile::decodeName(qgetenv("QT_QUICK_CONTROLS_CONF")); - if (!QFile::exists(filePath)) { - if (!filePath.isEmpty()) - qWarning("QT_QUICK_CONTROLS_CONF=%s: No such file", qPrintable(filePath)); - - filePath = QStringLiteral(":/qtquickcontrols2.conf"); - } - return filePath; -} - QQuickStyleAttached::QQuickStyleAttached(QObject *parent) : QObject(parent) { QQuickItem *item = qobject_cast<QQuickItem *>(parent); @@ -208,7 +197,7 @@ QQuickStyleAttached::~QQuickStyleAttached() QSharedPointer<QSettings> QQuickStyleAttached::settings(const QString &group) { #ifndef QT_NO_SETTINGS - static const QString filePath = resolveConfigFile(); + const QString filePath = QQuickStylePrivate::configFilePath(); if (QFile::exists(filePath)) { QFileSelector selector; QSettings *settings = new QSettings(selector.select(filePath), QSettings::IniFormat); |