aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2/qquickstyle.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-09-02 11:51:58 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-02 13:09:03 +0000
commit470c222196d4d1d21d1d80b550f632c030e9b651 (patch)
treee35db0eaaa6a1377ee5231f67234288ae9bce01e /src/quickcontrols2/qquickstyle.cpp
parent58326f2bc3bceafc0054e790832e0a77db340606 (diff)
Fix style name casing
When QQuickStyle looks up the appropriate folder where the specified style exists, it also fixes up the casing of the style name to match what is on the file system. For example, "material" becomes "Material". Since 54480f3, QtQuickControls2Plugin initializes the default style path so QQuickStyle no longer has to create a temporary QQmlEngine to be able to lookup styles in one of the import paths. It still needs to fixup the casing of the style name to ensure that "-style material" and QT_QUICK_CONTROLS_STYLE=material work. Change-Id: If35b870bb335e024b94fb328a927a5550b51cba1 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quickcontrols2/qquickstyle.cpp')
-rw-r--r--src/quickcontrols2/qquickstyle.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index bee837e9..ca5beafe 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -109,6 +109,24 @@ struct QQuickStyleSpec
resolve();
}
+ static QString findStyle(const QString &path, const QString &name)
+ {
+ QDir dir(path);
+ if (!dir.exists())
+ return QString();
+
+ if (name.isEmpty())
+ return dir.absolutePath() + QLatin1Char('/');
+
+ const QStringList entries = dir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
+ for (const QString &entry : entries) {
+ if (entry.compare(name, Qt::CaseInsensitive) == 0)
+ return dir.absoluteFilePath(entry);
+ }
+
+ return QString();
+ }
+
void resolve(const QUrl &baseUrl = QUrl())
{
if (style.isEmpty())
@@ -122,10 +140,12 @@ struct QQuickStyleSpec
}
if (baseUrl.isValid()) {
- if (style.isEmpty())
- style = baseUrl.toString(QUrl::StripTrailingSlash) + QLatin1Char('/');
- else if (!style.contains(QLatin1Char('/')))
- style = baseUrl.toString(QUrl::StripTrailingSlash) + QLatin1Char('/') + style;
+ QString path = QQmlFile::urlToLocalFileOrQrc(baseUrl);
+ QString stylePath = findStyle(path, style);
+ if (!stylePath.isEmpty()) {
+ style = stylePath;
+ resolved = true;
+ }
}
if (QGuiApplication::instance()) {
@@ -134,24 +154,12 @@ struct QQuickStyleSpec
const QStringList importPaths = QQmlEngine().importPathList();
for (const QString &importPath : importPaths) {
- QDir importDir(importPath);
- if (importDir.cd(targetPath)) {
- if (style.isEmpty()) {
- style = importDir.absolutePath() + QLatin1Char('/');
- resolved = true;
- break;
- }
- const QStringList entries = importDir.entryList(QStringList(), QDir::Dirs | QDir::NoDotAndDotDot);
- for (const QString &entry : entries) {
- if (entry.compare(style, Qt::CaseInsensitive) == 0) {
- style = importDir.absoluteFilePath(entry);
- resolved = true;
- break;
- }
- }
- }
- if (resolved)
+ QString stylePath = findStyle(importPath + QLatin1Char('/') + targetPath, style);
+ if (!stylePath.isEmpty()) {
+ style = stylePath;
+ resolved = true;
break;
+ }
}
}
resolved = true;