summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp88
-rw-r--r--src/declarative/qml/qdeclarativeengine.h4
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h1
-rw-r--r--tools/qml/main.cpp11
4 files changed, 45 insertions, 59 deletions
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 5335b8c..abac086 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -178,10 +178,16 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
#endif
foreach (const QString &path, QString::fromLatin1(envImportPath).split(pathSep, QString::SkipEmptyParts)) {
QString canonicalPath = QDir(path).canonicalPath();
- if (!canonicalPath.isEmpty() && !environmentImportPath.contains(canonicalPath))
- environmentImportPath.append(canonicalPath);
+ if (!canonicalPath.isEmpty() && !fileImportPath.contains(canonicalPath))
+ fileImportPath.append(canonicalPath);
}
}
+#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
+ QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath);
+ if (!builtinPath.isEmpty())
+ fileImportPath += builtinPath;
+#endif
+
}
QUrl QDeclarativeScriptEngine::resolvedUrl(QScriptContext *context, const QUrl& url)
@@ -1495,29 +1501,7 @@ public:
if (dir.endsWith(QLatin1Char('/')) || dir.endsWith(QLatin1Char('\\')))
dir.chop(1);
- QStringList paths;
-
-// if (!base.isEmpty()) {
-// QString baseDir = QFileInfo(toLocalFileOrQrc(base)).path();
-// paths += baseDir;
-// }
-
- QString applicationDirPath = QCoreApplication::applicationDirPath();
- if (!applicationDirPath.isEmpty())
- paths += applicationDirPath;
-
- paths += QDeclarativeEnginePrivate::get(engine)->environmentImportPath;
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
- QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath);
-#else
- QString builtinPath;
-#endif
- if (!builtinPath.isEmpty())
- paths += builtinPath;
-
- // add fileImportPath last, this is *not* search order.
- paths += QDeclarativeEnginePrivate::get(engine)->fileImportPath;
-
+ QStringList paths = QDeclarativeEnginePrivate::get(engine)->fileImportPath;
qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents.
QString stableRelativePath = dir;
@@ -1557,28 +1541,8 @@ public:
QString dir;
- // user import paths
- QStringList paths;
- // base..
-// QString localFileOrQrc = toLocalFileOrQrc(base);
-// QString localFileOrQrcPath = QFileInfo(localFileOrQrc).path();
-// paths += localFileOrQrcPath;
- paths += QDeclarativeEnginePrivate::get(engine)->fileImportPath;
-
- QString applicationDirPath = QCoreApplication::applicationDirPath();
- if (!applicationDirPath.isEmpty())
- paths += applicationDirPath;
-
- paths += QDeclarativeEnginePrivate::get(engine)->environmentImportPath;
-#if (QT_VERSION >= QT_VERSION_CHECK(4,7,0))
- QString builtinPath = QLibraryInfo::location(QLibraryInfo::ImportsPath);
-#else
- QString builtinPath;
-#endif
- if (!builtinPath.isEmpty())
- paths += builtinPath;
-
- foreach (const QString &p, paths) {
+ foreach (const QString &p,
+ QDeclarativeEnginePrivate::get(engine)->fileImportPath) {
dir = p+QLatin1Char('/')+url;
QFileInfo fi(dir+QLatin1String("/qmldir"));
@@ -1810,7 +1774,9 @@ QUrl QDeclarativeEnginePrivate::Imports::baseUrl() const
Adds \a path as a directory where installed QML components are
defined in a URL-based directory structure.
- \sa importPathList()
+ The newly added \a path will be first in the importPathList().
+
+ \sa setImportPathList()
*/
void QDeclarativeEngine::addImportPath(const QString& path)
{
@@ -1822,7 +1788,7 @@ void QDeclarativeEngine::addImportPath(const QString& path)
/*!
- Returns the list of directories with the engine searches for
+ Returns the list of directories where the engine searches for
installed modules.
For example, if \c /opt/MyApp/lib/imports is in the path, then QML that
@@ -1831,13 +1797,10 @@ void QDeclarativeEngine::addImportPath(const QString& path)
provided by that module. A \c qmldir file is required for defining the
type version mapping and possibly declarative extensions plugins.
- In addition to this list,
- the engine searches in the directory containing the
- application executable (QCoreApplication::applicationDirPath()),
- then the paths specified in the \c QML_IMPORT_PATH environment variable, then the
- builtin \c ImportsPath from QLibraryInfo.
+ By default, the list contains the paths specified in the \c QML_IMPORT_PATH environment
+ variable, then the builtin \c ImportsPath from QLibraryInfo.
- \sa addImportPath()
+ \sa addImportPath() setImportPathList()
*/
QStringList QDeclarativeEngine::importPathList() const
{
@@ -1846,6 +1809,21 @@ QStringList QDeclarativeEngine::importPathList() const
}
/*!
+ Sets the list of directories where the engine searches for
+ installed modules.
+
+ By default, the list contains the paths specified in the \c QML_IMPORT_PATH environment
+ variable, then the builtin \c ImportsPath from QLibraryInfo.
+
+ \sa importPathList() addImportPath()
+ */
+void QDeclarativeEngine::setImportPathList(const QStringList &paths)
+{
+ Q_D(QDeclarativeEngine);
+ d->fileImportPath = paths;
+}
+
+/*!
Imports the extension named \a fileName from the \a uri provided.
Returns true if the extension was successfully imported.
*/
diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h
index a24962e..b861c1b 100644
--- a/src/declarative/qml/qdeclarativeengine.h
+++ b/src/declarative/qml/qdeclarativeengine.h
@@ -77,8 +77,10 @@ public:
void clearComponentCache();
- void addImportPath(const QString& dir);
QStringList importPathList() const;
+ void setImportPathList(const QStringList &paths);
+ void addImportPath(const QString& dir);
+
bool importExtension(const QString &fileName, const QString &uri);
void setNetworkAccessManagerFactory(QDeclarativeNetworkAccessManagerFactory *);
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 84bf061..5aff30d 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -272,7 +272,6 @@ public:
};
- QStringList environmentImportPath;
QSet<QString> initializedPlugins;
QString resolvePlugin(const QDir &dir, const QString &baseName,
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index a4de339..8062e8e 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -41,6 +41,7 @@
#include "qdeclarative.h"
#include "qmlruntime.h"
+#include "qdeclarativeengine.h"
#include <QWidget>
#include <QDir>
#include <QApplication>
@@ -100,7 +101,8 @@ void usage()
qWarning(" -dragthreshold <size> .................... set mouse drag threshold size");
qWarning(" -netcache <size> ......................... set disk cache to size bytes");
qWarning(" -translation <translationfile> ........... set the language to run in");
- qWarning(" -L <directory> ........................... prepend to the library search path");
+ qWarning(" -L <directory> ........................... prepend to the library search path,");
+ qWarning(" display path if <directory> is empty");
qWarning(" -opengl .................................. use a QGLWidget for the viewport");
qWarning(" -script <path> ........................... set the script to use");
qWarning(" -scriptopts <options>|help ............... set the script options to use");
@@ -238,7 +240,12 @@ int main(int argc, char ** argv)
} else if (arg == "-qmlbrowser") {
useNativeFileBrowser = false;
} else if (arg == "-L") {
- if (lastArg) usage();
+ if (lastArg) {
+ QDeclarativeEngine tmpEngine;
+ QString paths = tmpEngine.importPathList().join(QLatin1String(":"));
+ fprintf(stderr, "Current search path: %s\n", paths.toLocal8Bit().constData());
+ return 0;
+ }
libraries << QString(argv[++i]);
} else if (arg == "-script") {
if (lastArg) usage();