aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-28 16:00:04 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-15 10:48:53 +0000
commitb1e9db69064fb7b30cdc3d9321c81684b2f56090 (patch)
tree40b2948c69ee57fa897b38bb7e6a8de78a2da510
parentcce0aadcd7a15f026c265b23b6e9dbe3310b70b1 (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. This is a cherry-pick of 5efd4b6a61498f0668d7367d620275367894140e, which fixes the style lookup so that QTBUG-57618 gets resolved. Change-Id: I7b656c42cb6aca0914ad20c94c7b527bea74cb16 Task-number: QTBUG-57618 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quickcontrols2/qquickstyle.cpp29
-rw-r--r--src/quickcontrols2/qquickstyle_p.h1
-rw-r--r--src/quickcontrols2/qquickstyleattached.cpp15
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);