aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-03-17 09:54:04 +0100
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-03-17 09:54:04 +0100
commitf52b95a96cc8f36f766635f9ddb6c95fa6b3c934 (patch)
tree0a74d23575ae74e93a7b2dedb7a03827c42e8266 /src/quickcontrols2
parent2bd4f5cd587e258227c69b3124757d7b8e019c9f (diff)
parent7da5842647f75fd990f69f400f75d9b090e39306 (diff)
Merge remote-tracking branch 'origin/dev' into wip/cmake
Diffstat (limited to 'src/quickcontrols2')
-rw-r--r--src/quickcontrols2/qquickstyle.cpp47
-rw-r--r--src/quickcontrols2/qquickstyleplugin.cpp10
-rw-r--r--src/quickcontrols2/qquickstyleplugin_p.h1
-rw-r--r--src/quickcontrols2/qquickstyleselector.cpp12
-rw-r--r--src/quickcontrols2/qquicktumblerview.cpp2
5 files changed, 62 insertions, 10 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index 408a0de3..e1cf4bfe 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -43,6 +43,7 @@
#include <QtCore/qsettings.h>
#include <QtCore/qfileselector.h>
#include <QtCore/qlibraryinfo.h>
+#include <QtCore/qloggingcategory.h>
#include <QtCore/qmetaobject.h>
#include <QtGui/qcolor.h>
#include <QtGui/qfont.h>
@@ -57,6 +58,8 @@
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcQtQuickControlsStyle, "qt.quick.controls.style")
+
/*!
\class QQuickStyle
\brief The QQuickStyle class allows configuring the application style.
@@ -110,7 +113,7 @@ static QStringList envPathList(const QByteArray &var)
QStringList paths;
if (Q_UNLIKELY(!qEnvironmentVariableIsEmpty(var))) {
const QByteArray value = qgetenv(var);
- paths += QString::fromLocal8Bit(value).split(QDir::listSeparator(), QString::SkipEmptyParts);
+ paths += QString::fromLocal8Bit(value).split(QDir::listSeparator(), Qt::SkipEmptyParts);
}
return paths;
}
@@ -119,8 +122,14 @@ static QStringList defaultImportPathList()
{
QStringList importPaths;
importPaths.reserve(3);
-#ifndef QT_STATIC
+#ifdef Q_OS_ANDROID
+ // androiddeployqt puts the QML files inside a resource file and they are not
+ // showing up in the Qml2ImportsPath as a result
+ importPaths += QStringLiteral(":/android_rcc_bundle/qml");
+#else
+# ifndef QT_STATIC
importPaths += QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
+# endif
#endif
importPaths += envPathList("QML2_IMPORT_PATH");
importPaths += QStringLiteral(":/qt-project.org/imports");
@@ -182,6 +191,8 @@ struct QQuickStyleSpec
void resolve(const QUrl &baseUrl = QUrl())
{
+ qCDebug(lcQtQuickControlsStyle) << "resolving style with baseUrl" << baseUrl;
+
if (style.isEmpty())
style = QGuiApplicationPrivate::styleOverride;
if (style.isEmpty())
@@ -234,6 +245,15 @@ struct QQuickStyleSpec
}
resolved = true;
}
+
+ qCDebug(lcQtQuickControlsStyle).nospace() << "done resolving:"
+ << "\n custom=" << custom
+ << "\n resolved=" << resolved
+ << "\n style=" << style
+ << "\n fallbackStyle=" << fallbackStyle
+ << "\n fallbackMethod=" << fallbackMethod
+ << "\n configFilePath=" << configFilePath
+ << "\n customStylePaths=" << customStylePaths;
}
void reset()
@@ -260,12 +280,19 @@ struct QQuickStyleSpec
return configFilePath;
}
+ // Is this a custom style defined by the user and not "built-in" style?
bool custom;
+ // Did we manage to find a valid style path?
bool resolved;
+ // The full path to the style.
QString style;
+ // The built-in style to use if the requested style cannot be found.
QString fallbackStyle;
+ // A description of the way in which fallbackStyle was set, used in e.g. warning messages shown to the user.
QByteArray fallbackMethod;
+ // The path to the qtquickcontrols2.conf file.
QString configFilePath;
+ // An extra list of directories where we search for available styles before any other directories.
QStringList customStylePaths;
};
@@ -341,7 +368,7 @@ QStringList QQuickStylePrivate::stylePaths(bool resolve)
} else {
// Fast/simpler path for systems where something other than : is used as
// the list separator (such as ';').
- const QStringList customPaths = value.split(listSeparator, QString::SkipEmptyParts);
+ const QStringList customPaths = value.split(listSeparator, Qt::SkipEmptyParts);
paths += customPaths;
}
}
@@ -379,7 +406,13 @@ void QQuickStylePrivate::init(const QUrl &baseUrl)
spec->resolve(baseUrl);
if (!spec->fallbackStyle.isEmpty()) {
- QString fallbackStyle = spec->findStyle(QQmlFile::urlToLocalFileOrQrc(baseUrl), spec->fallbackStyle);
+ QString fallbackStyle;
+ const QStringList stylePaths = QQuickStylePrivate::stylePaths();
+ for (const QString &path : stylePaths) {
+ fallbackStyle = spec->findStyle(path, spec->fallbackStyle);
+ if (!fallbackStyle.isEmpty())
+ break;
+ }
if (fallbackStyle.isEmpty()) {
if (spec->fallbackStyle.compare(QStringLiteral("Default")) != 0) {
qWarning() << "ERROR: unable to locate fallback style" << spec->fallbackStyle;
@@ -543,7 +576,9 @@ QString QQuickStyle::path()
*/
void QQuickStyle::setStyle(const QString &style)
{
- if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), 2, 0)) {
+ qCDebug(lcQtQuickControlsStyle) << "setStyle called with" << style;
+
+ if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), QTypeRevision::fromVersion(2, 0))) {
qWarning() << "ERROR: QQuickStyle::setStyle() must be called before loading QML that imports Qt Quick Controls 2.";
return;
}
@@ -567,7 +602,7 @@ void QQuickStyle::setStyle(const QString &style)
*/
void QQuickStyle::setFallbackStyle(const QString &style)
{
- if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), 2, 0)) {
+ if (QQmlMetaType::isModule(QStringLiteral("QtQuick.Controls"), QTypeRevision::fromVersion(2, 0))) {
qWarning() << "ERROR: QQuickStyle::setFallbackStyle() must be called before loading QML that imports Qt Quick Controls 2.";
return;
}
diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp
index 553a6cad..c35c8735 100644
--- a/src/quickcontrols2/qquickstyleplugin.cpp
+++ b/src/quickcontrols2/qquickstyleplugin.cpp
@@ -63,7 +63,15 @@ QString QQuickStylePlugin::name() const
void QQuickStylePlugin::initializeTheme(QQuickTheme *theme)
{
- Q_UNUSED(theme);
+ Q_UNUSED(theme)
+}
+
+void QQuickStylePlugin::unregisterTypes()
+{
+ Q_D(QQuickStylePlugin);
+ // Destroy the selector so that it is recreated in resolvedUrl() and
+ // any new style that has been set at runtime will be accounted for when selecting QML files.
+ d->selector.reset();
}
QUrl QQuickStylePlugin::resolvedUrl(const QString &fileName) const
diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h
index 6b89926c..67103e12 100644
--- a/src/quickcontrols2/qquickstyleplugin_p.h
+++ b/src/quickcontrols2/qquickstyleplugin_p.h
@@ -66,6 +66,7 @@ public:
virtual QString name() const;
virtual void initializeTheme(QQuickTheme *theme);
+ virtual void unregisterTypes() override;
QUrl resolvedUrl(const QString &fileName) const;
diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp
index d11a95bd..72e7af66 100644
--- a/src/quickcontrols2/qquickstyleselector.cpp
+++ b/src/quickcontrols2/qquickstyleselector.cpp
@@ -48,7 +48,9 @@
QT_BEGIN_NAMESPACE
-Q_LOGGING_CATEGORY(lcQtQuickControlsStyle, "qt.quick.controls.style")
+Q_LOGGING_CATEGORY(lcStyleSelectorSelect, "qt.quick.controls.styleSelector.select")
+Q_LOGGING_CATEGORY(lcStyleSelectorSetPaths, "qt.quick.controls.styleSelector.setPaths")
+Q_LOGGING_CATEGORY(lcStyleSelectorAddSelector, "qt.quick.controls.styleSelector.addSelector")
static QString ensureSlash(const QString &path)
{
@@ -112,6 +114,9 @@ void QQuickStyleSelector::addSelector(const QString &selector)
return;
d->selectors += selector;
+
+ qCDebug(lcStyleSelectorSetPaths).nospace() << "added selector " << selector
+ << "; full list is now: " << d->selectors;
}
QStringList QQuickStyleSelector::paths() const
@@ -123,6 +128,7 @@ QStringList QQuickStyleSelector::paths() const
void QQuickStyleSelector::setPaths(const QStringList &paths)
{
Q_D(QQuickStyleSelector);
+ qCDebug(lcStyleSelectorSetPaths) << "setting paths to" << paths;
d->paths = paths;
}
@@ -133,7 +139,7 @@ QUrl QQuickStyleSelector::select(const QString &fileName) const
// 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)
- qCDebug(lcQtQuickControlsStyle) << "selecting" << fileName << "from" << d->paths << "with selectors" << d->selectors;
+ qCDebug(lcStyleSelectorSelect) << "selecting" << fileName << "from" << d->paths << "with selectors" << d->selectors;
int to = d->selectors.count() - 1;
if (d->selectors.isEmpty() || !d->selectors.first().isEmpty())
@@ -145,7 +151,7 @@ QUrl QQuickStyleSelector::select(const QString &fileName) const
for (const QString &path : d->paths) {
const QUrl selectedUrl = d->select(ensureSlash(path) + selector + QLatin1Char('/') + fileName);
if (selectedUrl.isValid()) {
- qCDebug(lcQtQuickControlsStyle) << "==>" << selectedUrl << "from" << path << "with selector" << selector;
+ qCDebug(lcStyleSelectorSelect) << "==>" << selectedUrl << "from" << path << "with selector" << selector;
return selectedUrl;
}
}
diff --git a/src/quickcontrols2/qquicktumblerview.cpp b/src/quickcontrols2/qquicktumblerview.cpp
index 4a64ad7f..eaa58032 100644
--- a/src/quickcontrols2/qquicktumblerview.cpp
+++ b/src/quickcontrols2/qquicktumblerview.cpp
@@ -316,3 +316,5 @@ QQuickItem *QQuickTumblerView::view()
}
QT_END_NAMESPACE
+
+#include "moc_qquicktumblerview_p.cpp"