on xenial help sign in
clean up import paths
commitc927ff6797b343cb6cede75c135adc2bc4993fac authorMichał Sawicz <michal.sawicz@canonical.com> dateFri 28 Jun 2013, 11:22 (13 years ago) parentad5368c
2 files changed+13−12
main.cpp+7−8 paths.h.in+6−4
main.cpp+7−8
@@ -39,10 +39,10 @@ void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
3939 // don't duplicate
4040 const QString& path = paths[i];
4141 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
42− if (iter == importPathList.end())
43− importPathList.prepend(path);
42+ if (iter == importPathList.end()) {
43+ engine->addImportPath(path);
44+ }
4445 }
45− engine->setImportPathList(importPathList);
4646}
4747
4848/* When you append and import path to the list of import paths it will be the *last*
@@ -54,10 +54,10 @@ void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
5454 Q_FOREACH(const QString& path, paths) {
5555 // don't duplicate
5656 QStringList::iterator iter = qFind(importPathList.begin(), importPathList.end(), path);
57− if (iter == importPathList.end())
57+ if (iter == importPathList.end()) {
5858 importPathList.append(path);
59+ }
5960 }
60− importPathList.append(paths);
6161 engine->setImportPathList(importPathList);
6262}
6363
@@ -134,9 +134,8 @@ int main(int argc, char** argv)
134134 QObject::connect(view->engine(), SIGNAL(quit()), qApp, SLOT(quit()));
135135
136136 QUrl source("Shell.qml");
137− prependImportPaths(view->engine(), QStringList() << ::shellAppDirectory());
138− prependImportPaths(view->engine(), ::shellImportPaths());
139− appendImportPaths(view->engine(), QStringList() << ::fakePluginsImportPath());
137+ prependImportPaths(view->engine(), ::overrideImportPaths());
138+ appendImportPaths(view->engine(), ::fallbackImportPaths());
140139 view->setSource(source);
141140 view->setColor("transparent");
142141
paths.h.in+6−4
@@ -46,7 +46,7 @@ inline QString shellAppDirectory() {
4646 }
4747}
4848
49−inline QStringList shellImportPaths() {
49+inline QStringList overrideImportPaths() {
5050 QStringList paths;
5151 if (isRunningInstalled()) {
5252 paths << QString("@CMAKE_INSTALL_PREFIX@/@SHELL_PRIVATE_LIBDIR@/qml");
@@ -56,12 +56,14 @@ inline QStringList shellImportPaths() {
5656 return paths;
5757}
5858
59−inline QString fakePluginsImportPath() {
59+inline QStringList fallbackImportPaths() {
60+ QStringList paths;
6061 if (isRunningInstalled()) {
61− return QString("@CMAKE_INSTALL_PREFIX@/@SHELL_PRIVATE_LIBDIR@/qml/mocks");
62+ paths << QString("@CMAKE_INSTALL_PREFIX@/@SHELL_PRIVATE_LIBDIR@/qml/mocks");
6263 } else {
63− return QString("@CMAKE_BINARY_DIR@/tests/mocks");
64+ paths << QString("@CMAKE_BINARY_DIR@/tests/mocks");
6465 }
66+ return paths;
6567}
6668
6769inline QString sourceDirectory() {