on xenial help sign in
Changed shellImportPath to return a list of paths.
a6fea5cNick Dedekind
main.cpp+26−6
@@ -31,13 +31,33 @@
31#include "MouseTouchAdaptor.h"
31#include "MouseTouchAdaptor.h"
32
32
33namespace {
33namespace {
34+
35+void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
36+{
37+ QStringList importPathList = engine->importPathList();
38+ for (int i = paths.count() -1; i >= 0; i--) {
39+ // don't duplicate
40+ const QString& path = paths[i];
41+ QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
42+ if (iter == importPathList.end())
43+ importPathList.prepend(path);
44+ }
45+ engine->setImportPathList(importPathList);
46+}
47+
34/* When you append and import path to the list of import paths it will be the *last*
48/* When you append and import path to the list of import paths it will be the *last*
35 place where Qt will search for QML modules.
49 place where Qt will search for QML modules.
36 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
50 The usual QQmlEngine::addImportPath() actually prepends the given path.*/
37−void appendImportPath(QQmlEngine *engine, const QString &path)
51+void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
38{
52{
39 QStringList importPathList = engine->importPathList();
53 QStringList importPathList = engine->importPathList();
54+ Q_FOREACH(const QString& path, paths) {
55+ // don't duplicate
56+ QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
57+ if (iter == importPathList.end())
40− importPathList.append(path);
58+ importPathList.append(path);
59+ }
60+ importPathList.append(paths);
41 engine->setImportPathList(importPathList);
61 engine->setImportPathList(importPathList);
42}
62}
43
63
@@ -88,7 +108,7 @@ int main(int argc, char** argv)
88 QQuickView* view = new QQuickView();
108 QQuickView* view = new QQuickView();
89 view->setResizeMode(QQuickView::SizeRootObjectToView);
109 view->setResizeMode(QQuickView::SizeRootObjectToView);
90 view->setTitle("Qml Phone Shell");
110 view->setTitle("Qml Phone Shell");
91− view->engine()->setBaseUrl(QUrl::fromLocalFile(shellAppDirectory()));
111+ view->engine()->setBaseUrl(QUrl::fromLocalFile(::shellAppDirectory()));
92 if (args.contains(QLatin1String("-frameless"))) {
112 if (args.contains(QLatin1String("-frameless"))) {
93 view->setFlags(Qt::FramelessWindowHint);
113 view->setFlags(Qt::FramelessWindowHint);
94 }
114 }
@@ -114,9 +134,9 @@ int main(int argc, char** argv)
114 QObject::connect(view->engine(), SIGNAL(quit()), qApp, SLOT(quit()));
134 QObject::connect(view->engine(), SIGNAL(quit()), qApp, SLOT(quit()));
115
135
116 QUrl source("Shell.qml");
136 QUrl source("Shell.qml");
117− view->engine()->addImportPath(shellAppDirectory());
137+ prependImportPaths(view->engine(), QStringList() << ::shellAppDirectory());
118− view->engine()->addImportPath(shellImportPath());
138+ prependImportPaths(view->engine(), ::shellImportPaths());
119− appendImportPath(view->engine(), fakePluginsImportPath());
139+ appendImportPaths(view->engine(), QStringList() << ::fakePluginsImportPath());
120 view->setSource(source);
140 view->setSource(source);
121 view->setColor("transparent");
141 view->setColor("transparent");
122
142
paths.h.in+10−3
@@ -17,6 +17,9 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
18 */
19
19
20+#ifndef PATHS_H
21+#define PATHS_H
22+
20// Qt
23// Qt
21#include <QtCore/QCoreApplication>
24#include <QtCore/QCoreApplication>
22#include <QtCore/QDir>
25#include <QtCore/QDir>
@@ -43,12 +46,14 @@ inline QString shellAppDirectory() {
43 }
46 }
44}
47}
45
48
46−inline QString shellImportPath() {
49+inline QStringList shellImportPaths() {
50+ QStringList paths;
47 if (isRunningInstalled()) {
51 if (isRunningInstalled()) {
48− return QString("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/plugins");
52+ paths << QString("@CMAKE_INSTALL_PREFIX@/@SHELL_APP_DIR@/plugins");
49 } else {
53 } else {
50− return QString("@CMAKE_BINARY_DIR@/plugins/");
54+ paths << QString("@CMAKE_BINARY_DIR@/plugins");
51 }
55 }
56+ return paths;
52}
57}
53
58
54inline QString fakePluginsImportPath() {
59inline QString fakePluginsImportPath() {
@@ -62,3 +67,5 @@ inline QString fakePluginsImportPath() {
62inline QString sourceDirectory() {
67inline QString sourceDirectory() {
63 return QString("@CMAKE_SOURCE_DIR@/");
68 return QString("@CMAKE_SOURCE_DIR@/");
64}
69}
70+
71+#endif