aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-04-23 19:34:15 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-04-25 07:19:42 +0000
commitf2ede1a01237c0ff0285716359a8b57a6676a94d (patch)
treedf970a6cae126a6698706370232e878c595c1f14
parent99fa43b3708d6615e17d0cc5561aca78a9c72d1a (diff)
QQuickStyleSelector: fix relative path handling
This makes it possible to pass a relative path to the style: ./myapp -style relative/path/to/my/style To make the tests pass, includes a fix to avoid double slashes in selected URLs. Change-Id: I1b366eb7793523dd0f1058236661cedaa1216f3d Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--.gitignore1
-rw-r--r--src/quickcontrols2/qquickstyleselector.cpp8
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qquickstyleselector/ResourceStyle/Button.qml2
-rw-r--r--tests/auto/qquickstyleselector/data/Button.qml2
-rw-r--r--tests/auto/qquickstyleselector/data/FileSystemStyle/Button.qml2
-rw-r--r--tests/auto/qquickstyleselector/qquickstyleselector.pro19
-rw-r--r--tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp83
8 files changed, 116 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 92052b5d..7d6784f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@
/tests/auto/popup/tst_popup
/tests/auto/pressandhold/tst_pressandhold
/tests/auto/qquickstyle/tst_qquickstyle
+/tests/auto/qquickstyleselector/tst_qquickstyleselector
/tests/auto/sanity/tst_sanity
/tests/auto/snippets/tst_snippets
/tests/auto/styles/tst_styles
diff --git a/src/quickcontrols2/qquickstyleselector.cpp b/src/quickcontrols2/qquickstyleselector.cpp
index cd89ba95..93249192 100644
--- a/src/quickcontrols2/qquickstyleselector.cpp
+++ b/src/quickcontrols2/qquickstyleselector.cpp
@@ -144,11 +144,15 @@ QString QQuickStyleSelector::select(const QString &fileName) const
const QString selectedPath = selectionHelper(stylePath, fileName, allSelectors(false));
if (selectedPath.startsWith(QLatin1Char(':')))
return QLatin1String("qrc") + selectedPath;
- return QUrl::fromLocalFile(selectedPath).toString();
+ return QUrl::fromLocalFile(QFileInfo(selectedPath).absoluteFilePath()).toString();
}
}
- QUrl url(d->baseUrl.toString() + QLatin1Char('/') + fileName);
+ QString base = d->baseUrl.toString();
+ if (!base.isEmpty() && !base.endsWith(QLatin1Char('/')))
+ base += QLatin1Char('/');
+
+ QUrl url(base + fileName);
if (isLocalScheme(url.scheme())) {
QString equivalentPath = QLatin1Char(':') + url.path();
QString selectedPath = d->select(equivalentPath);
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index e370ed68..bf608c17 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -10,6 +10,7 @@ SUBDIRS += \
popup \
pressandhold \
qquickstyle \
+ qquickstyleselector \
sanity \
snippets \
styles \
diff --git a/tests/auto/qquickstyleselector/ResourceStyle/Button.qml b/tests/auto/qquickstyleselector/ResourceStyle/Button.qml
new file mode 100644
index 00000000..5b08222c
--- /dev/null
+++ b/tests/auto/qquickstyleselector/ResourceStyle/Button.qml
@@ -0,0 +1,2 @@
+import QtQuick.Templates 2.0 as T
+T.Button { }
diff --git a/tests/auto/qquickstyleselector/data/Button.qml b/tests/auto/qquickstyleselector/data/Button.qml
new file mode 100644
index 00000000..5b08222c
--- /dev/null
+++ b/tests/auto/qquickstyleselector/data/Button.qml
@@ -0,0 +1,2 @@
+import QtQuick.Templates 2.0 as T
+T.Button { }
diff --git a/tests/auto/qquickstyleselector/data/FileSystemStyle/Button.qml b/tests/auto/qquickstyleselector/data/FileSystemStyle/Button.qml
new file mode 100644
index 00000000..5b08222c
--- /dev/null
+++ b/tests/auto/qquickstyleselector/data/FileSystemStyle/Button.qml
@@ -0,0 +1,2 @@
+import QtQuick.Templates 2.0 as T
+T.Button { }
diff --git a/tests/auto/qquickstyleselector/qquickstyleselector.pro b/tests/auto/qquickstyleselector/qquickstyleselector.pro
new file mode 100644
index 00000000..c56e5732
--- /dev/null
+++ b/tests/auto/qquickstyleselector/qquickstyleselector.pro
@@ -0,0 +1,19 @@
+CONFIG += testcase
+TARGET = tst_qquickstyleselector
+SOURCES += tst_qquickstyleselector.cpp
+
+osx:CONFIG -= app_bundle
+
+QT += core-private gui-private qml-private quick-private quickcontrols2-private testlib
+
+include (../shared/util.pri)
+
+resourcestyle.prefix = /
+resourcestyle.files += $$PWD/ResourceStyle/Button.qml
+RESOURCES += resourcestyle
+
+TESTDATA = data/*
+
+OTHER_FILES += \
+ data/*
+
diff --git a/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp b/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp
new file mode 100644
index 00000000..6c2aebe4
--- /dev/null
+++ b/tests/auto/qquickstyleselector/tst_qquickstyleselector.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/qtest.h>
+#include <QtQuickControls2/qquickstyle.h>
+#include <QtQuickControls2/private/qquickstyleselector_p.h>
+#include "../shared/util.h"
+
+class tst_QQuickStyleSelector : public QQmlDataTest
+{
+ Q_OBJECT
+
+private slots:
+ void select_data();
+ void select();
+};
+
+void tst_QQuickStyleSelector::select_data()
+{
+ QTest::addColumn<QString>("file");
+ QTest::addColumn<QString>("style");
+ QTest::addColumn<QString>("path");
+ QTest::addColumn<QString>("expected");
+
+ QTest::newRow("empty") << "Button.qml" << "" << dataDirectory() << testFileUrl("Button.qml").toString();
+ QTest::newRow("no such dir") << "Button.qml" << "Foo" << dataDirectory() << testFileUrl("Button.qml").toString();
+ QTest::newRow("no such file") << "Foo.qml" << "FileSystemStyle" << dataDirectory() << testFileUrl("Foo.qml").toString();
+ QTest::newRow("relative/path/to/FileSystemStyle") << "Button.qml" << "FileSystemStyle" << "data" << testFileUrl("FileSystemStyle/Button.qml").toString();
+ QTest::newRow("/absolute/path/to/FileSystemStyle") << "Button.qml" << "FileSystemStyle" << dataDirectory() << testFileUrl("FileSystemStyle/Button.qml").toString();
+ QTest::newRow(":/ResourceStyle") << "Button.qml" << "ResourceStyle" << ":/" << "qrc:/ResourceStyle/Button.qml";
+ QTest::newRow("qrc:/ResourceStyle") << "Button.qml" << "ResourceStyle" << "qrc:/" << "qrc:/ResourceStyle/Button.qml";
+}
+
+void tst_QQuickStyleSelector::select()
+{
+ QFETCH(QString, file);
+ QFETCH(QString, style);
+ QFETCH(QString, path);
+ QFETCH(QString, expected);
+
+ QQuickStyle::setStyle(QDir(path).filePath(style));
+
+ QQuickStyleSelector selector;
+ selector.setBaseUrl(dataDirectoryUrl());
+ QCOMPARE(selector.select(file), expected);
+}
+
+QTEST_MAIN(tst_QQuickStyleSelector)
+
+#include "tst_qquickstyleselector.moc"