diff options
author | David Faure <david.faure@kdab.com> | 2016-06-18 15:21:24 +0200 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2016-07-06 17:20:28 +0000 |
commit | 0ea4a2cd207540c6936c6cf16bc5b371d6bcd09d (patch) | |
tree | ce738f1f7cd0696229d0454b64891ed27b19b0d0 /src/controls | |
parent | 535f520685c2af471fd5d8d83da95f4321f171bb (diff) | |
download | qtquickcontrols-0ea4a2cd207540c6936c6cf16bc5b371d6bcd09d.tar.gz |
Find custom styles stored in qrc.
The unittest was showing that it was looking in
<CURRENTDIR>/qrc:/qt-project.org/imports/QtQuick/Controls/Styles
which makes no sense.
In addition, the code was only listing the directory where
the default style is found. When the custom style is elsewhere,
it needs to be looked up in addition.
Change-Id: I93eddab73672c575cd92037e1d0b366cf17540ef
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'src/controls')
-rw-r--r-- | src/controls/Private/qquickcontrolsettings.cpp | 38 | ||||
-rw-r--r-- | src/controls/Private/qquickcontrolsettings_p.h | 1 |
2 files changed, 26 insertions, 13 deletions
diff --git a/src/controls/Private/qquickcontrolsettings.cpp b/src/controls/Private/qquickcontrolsettings.cpp index dfab577e..1965738a 100644 --- a/src/controls/Private/qquickcontrolsettings.cpp +++ b/src/controls/Private/qquickcontrolsettings.cpp @@ -42,6 +42,7 @@ #include <qcoreapplication.h> #include <qdebug.h> #include <qqmlengine.h> +#include <qfileinfo.h> #include <qlibrary.h> #include <qdir.h> #include <QTouchDevice> @@ -154,16 +155,21 @@ static QString relativeStyleImportPath(QQmlEngine *engine, const QString &styleN QString path; #ifndef QT_STATIC bool found = false; - const auto importPathList = engine->importPathList(); - for (const QString &import : importPathList) { - QDir dir(import + QStringLiteral("/QtQuick/Controls/Styles")); - if (dir.exists(styleName)) { - found = true; - path = dir.absolutePath(); - break; + const auto importPathList = engine->importPathList(); // ideally we'd call QQmlImportDatabase::importPathList(Local) here, but it's not exported + for (QString import : importPathList) { + bool localPath = QFileInfo(import).isAbsolute(); + if (import.startsWith(QLatin1String("qrc:/"), Qt::CaseInsensitive)) { + import = QLatin1Char(':') + import.mid(4); + localPath = true; + } + if (localPath) { + QDir dir(import + QStringLiteral("/QtQuick/Controls/Styles")); + if (dir.exists(styleName)) { + found = true; + path = dir.absolutePath(); + break; + } } - if (found) - break; } if (!found) path = ":/QtQuick/Controls/Styles"; @@ -194,6 +200,7 @@ static QString styleImportPath(QQmlEngine *engine, const QString &styleName) } QQuickControlSettings1::QQuickControlSettings1(QQmlEngine *engine) + : m_engine(engine) { // First, register all style paths in the default style location. QDir dir; @@ -223,10 +230,14 @@ QQuickControlSettings1::QQuickControlSettings1(QQmlEngine *engine) if (m_styleMap.contains(m_name)) { m_path = m_styleMap.value(m_name).m_styleDirPath; } else { - QString unknownStyle = m_name; - m_name = defaultStyle; m_path = m_styleMap.value(defaultStyle).m_styleDirPath; - qWarning() << "WARNING: Cannot find style" << unknownStyle << "- fallback:" << styleFilePath(); + // Maybe the requested style is not next to the default style, but elsewhere in the import path + findStyle(engine, m_name); + if (!m_styleMap.contains(m_name)) { + QString unknownStyle = m_name; + m_name = defaultStyle; + qWarning() << "WARNING: Cannot find style" << unknownStyle << "- fallback:" << styleFilePath(); + } } // Can't really do anything about this failing here, so don't bother checking... @@ -278,7 +289,8 @@ void QQuickControlSettings1::findStyle(QQmlEngine *engine, const QString &styleN QDir dir; dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); dir.setPath(path); - dir.cd(styleName); + if (!dir.cd(styleName)) + return; StyleData styleData; diff --git a/src/controls/Private/qquickcontrolsettings_p.h b/src/controls/Private/qquickcontrolsettings_p.h index aa3e4b2d..bfa44f2f 100644 --- a/src/controls/Private/qquickcontrolsettings_p.h +++ b/src/controls/Private/qquickcontrolsettings_p.h @@ -106,6 +106,7 @@ private: QString m_name; QString m_path; QHash<QString, StyleData> m_styleMap; + QQmlEngine *m_engine; }; QT_END_NAMESPACE |