summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2010-03-17 11:39:47 (GMT)
committermae <qt-info@nokia.com>2010-03-17 11:41:08 (GMT)
commit144e450292b4d33e72223626e4146f8e9efb8c9b (patch)
tree32aad3da1f5ffa757e5d76aeb94f468d0b05c941
parentd54b11fef6403693de09277a645c9666f8eea6a2 (diff)
downloadQt-144e450292b4d33e72223626e4146f8e9efb8c9b.zip
Qt-144e450292b4d33e72223626e4146f8e9efb8c9b.tar.gz
Qt-144e450292b4d33e72223626e4146f8e9efb8c9b.tar.bz2
Add an implicit import "." to types loaded from a local url
This triggers the loading of the qmldir and the import of native types from available plugins. The change puts native types on par with types defined in qml files.
-rw-r--r--src/declarative/qml/qdeclarativecompositetypemanager.cpp31
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp1
2 files changed, 28 insertions, 4 deletions
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
index e2a6e0c..5f80000 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp
+++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
@@ -315,12 +315,17 @@ void QDeclarativeCompositeTypeManager::resourceReplyFinished()
reply->deleteLater();
}
+// XXX this beyonds in QUrl::toLocalFile()
+// WARNING, there is a copy of this function in qdeclarativeengine.cpp
static QString toLocalFileOrQrc(const QUrl& url)
{
- QString r = url.toLocalFile();
- if (r.isEmpty() && url.scheme() == QLatin1String("qrc"))
- r = QLatin1Char(':') + url.path();
- return r;
+ if (url.scheme() == QLatin1String("qrc")) {
+ if (url.authority().isEmpty())
+ return QLatin1Char(':') + url.path();
+ qWarning() << "Invalid url:" << url.toString() << "authority" << url.authority() << "not known.";
+ return QString();
+ }
+ return url.toLocalFile();
}
void QDeclarativeCompositeTypeManager::loadResource(QDeclarativeCompositeTypeResource *resource)
@@ -505,6 +510,24 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
int waiting = 0;
+
+ /*
+ For local urls, add an implicit import "." to the beginning of a file. This will trigger
+ the loading of the qmldir and the import of any native types from available plugins.
+ */
+ QUrl baseUrl = unit->imports.baseUrl();
+ if (!toLocalFileOrQrc(baseUrl).isEmpty()) {
+ QDeclarativeEnginePrivate::get(engine)->
+ addToImport(&unit->imports,
+ QString(),
+ QLatin1String("."),
+ QString(),
+ -1, -1,
+ QDeclarativeScriptParser::Import::File);
+
+ }
+
+
foreach (QDeclarativeScriptParser::Import imp, unit->data.imports()) {
QString qmldircontentnetwork;
if (imp.type == QDeclarativeScriptParser::Import::File && imp.qualifier.isEmpty()) {
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 7c21ab8..f4eeff4 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -1342,6 +1342,7 @@ QVariant QDeclarativeScriptClass::toVariant(QDeclarativeEngine *engine, const QS
}
// XXX this beyonds in QUrl::toLocalFile()
+// WARNING, there is a copy of this function in qdeclarativecompositetypemanager.cpp
static QString toLocalFileOrQrc(const QUrl& url)
{
if (url.scheme() == QLatin1String("qrc")) {