summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/parser/qdeclarativejs.g4
-rw-r--r--src/declarative/qml/parser/qdeclarativejsparser.cpp4
-rw-r--r--src/declarative/qml/qdeclarativecompositetypemanager.cpp10
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp39
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h3
-rw-r--r--src/declarative/qml/qdeclarativemetatype.cpp28
-rw-r--r--src/declarative/qml/qdeclarativemetatype_p.h2
-rw-r--r--tests/auto/declarative/qdeclarativedom/data/import/Bar.qml (renamed from tests/auto/declarative/qdeclarativedom/data/importdir/Bar.qml)0
-rw-r--r--tests/auto/declarative/qdeclarativedom/data/importlib/sublib/Foo.qml (renamed from tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir/Foo.qml)0
-rw-r--r--tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir1
-rw-r--r--tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp3
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.errors.txt1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.qml3
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/importNonExist.errors.txt1
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/data/importNonExist.qml5
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp2
16 files changed, 95 insertions, 11 deletions
diff --git a/src/declarative/qml/parser/qdeclarativejs.g b/src/declarative/qml/parser/qdeclarativejs.g
index 493ad25..0256c52 100644
--- a/src/declarative/qml/parser/qdeclarativejs.g
+++ b/src/declarative/qml/parser/qdeclarativejs.g
@@ -665,7 +665,9 @@ case $rule_number: {
sym(1).Node = node;
- if (! node) {
+ if (node) {
+ node->importToken = loc(1);
+ } else {
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, loc(1),
QLatin1String("Expected a qualified name id or a string literal")));
diff --git a/src/declarative/qml/parser/qdeclarativejsparser.cpp b/src/declarative/qml/parser/qdeclarativejsparser.cpp
index c86e047..9205ef4 100644
--- a/src/declarative/qml/parser/qdeclarativejsparser.cpp
+++ b/src/declarative/qml/parser/qdeclarativejsparser.cpp
@@ -284,7 +284,9 @@ case 20: {
sym(1).Node = node;
- if (! node) {
+ if (node) {
+ node->importToken = loc(1);
+ } else {
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Error, loc(1),
QLatin1String("Expected a qualified name id or a string literal")));
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
index c883805..c59e5e2 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp
+++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
@@ -570,12 +570,15 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
}
}
+ QString errorString;
if (!QDeclarativeEnginePrivate::get(engine)->
- addToImport(&unit->imports, qmldircomponentsnetwork, imp.uri, imp.qualifier, vmaj, vmin, imp.type))
+ addToImport(&unit->imports, qmldircomponentsnetwork, imp.uri, imp.qualifier, vmaj, vmin, imp.type, &errorString))
{
QDeclarativeError error;
error.setUrl(unit->imports.baseUrl());
- error.setDescription(tr("Import %1 unavailable").arg(imp.uri));
+ error.setDescription(errorString);
+ error.setLine(imp.location.start.line);
+ error.setColumn(imp.location.start.column);
unit->status = QDeclarativeCompositeTypeData::Error;
unit->errorType = QDeclarativeCompositeTypeData::GeneralError;
unit->errors << error;
@@ -605,7 +608,8 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
QLatin1String("."),
QString(),
-1, -1,
- QDeclarativeScriptParser::Import::File);
+ QDeclarativeScriptParser::Import::File,
+ 0); // error ignored (just means no fallback)
}
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index c49c464..d4872e2 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -1517,7 +1517,7 @@ public:
- bool add(const QUrl& base, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri_arg, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, QDeclarativeEngine *engine)
+ bool add(const QUrl& base, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri_arg, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, QDeclarativeEngine *engine, QString *errorString)
{
QDeclarativeDirComponents qmldircomponents = qmldircomponentsnetwork;
QString uri = uri_arg;
@@ -1576,12 +1576,31 @@ public:
}
}
+ if (!found) {
+ found = QDeclarativeMetaType::isModule(uri.toUtf8(), vmaj, vmin);
+ if (!found) {
+ if (errorString) {
+ bool anyversion = QDeclarativeMetaType::isModule(uri.toUtf8(), 0, 0);
+ if (anyversion)
+ *errorString = QDeclarativeEngine::tr("module \"%1\" version %2.%3 is not installed").arg(uri_arg).arg(vmaj).arg(vmin);
+ else
+ *errorString = QDeclarativeEngine::tr("module \"%1\" is not installed").arg(uri_arg);
+ }
+ return false;
+ }
+ }
} else {
if (importType == QDeclarativeScriptParser::Import::File && qmldircomponents.isEmpty()) {
QUrl importUrl = base.resolved(QUrl(uri + QLatin1String("/qmldir")));
QString localFileOrQrc = toLocalFileOrQrc(importUrl);
if (!localFileOrQrc.isEmpty()) {
+ QString dir = toLocalFileOrQrc(base.resolved(QUrl(uri)));
+ if (dir.isEmpty() || !QDir().exists(dir)) {
+ if (errorString)
+ *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri_arg);
+ return false; // local import dirs must exist
+ }
uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), engine);
qmldircomponents = importExtension(localFileOrQrc,
uri,
@@ -1589,6 +1608,20 @@ public:
if (uri.endsWith(QLatin1Char('/')))
uri.chop(1);
+ } else {
+ if (prefix.isEmpty()) {
+ // directory must at least exist for valid import
+ QString localFileOrQrc = toLocalFileOrQrc(base.resolved(QUrl(uri)));
+ if (localFileOrQrc.isEmpty() || !QDir().exists(localFileOrQrc)) {
+ if (errorString) {
+ if (localFileOrQrc.isEmpty())
+ *errorString = QDeclarativeEngine::tr("import \"%1\" has no qmldir and no namespace").arg(uri);
+ else
+ *errorString = QDeclarativeEngine::tr("\"%1\": no such directory").arg(uri);
+ }
+ return false;
+ }
+ }
}
}
@@ -1962,12 +1995,12 @@ QString QDeclarativeEnginePrivate::resolvePlugin(const QDir &dir, const QString
The base URL must already have been set with Import::setBaseUrl().
*/
-bool QDeclarativeEnginePrivate::addToImport(Imports* imports, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType) const
+bool QDeclarativeEnginePrivate::addToImport(Imports* imports, const QDeclarativeDirComponents &qmldircomponentsnetwork, const QString& uri, const QString& prefix, int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType, QString *errorString) const
{
QDeclarativeEngine *engine = QDeclarativeEnginePrivate::get(const_cast<QDeclarativeEnginePrivate *>(this));
if (qmlImportTrace())
qDebug().nospace() << "QDeclarativeEngine::addToImport " << imports << " " << uri << " " << vmaj << '.' << vmin << " " << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File") << " as " << prefix;
- bool ok = imports->d->add(imports->d->base,qmldircomponentsnetwork, uri,prefix,vmaj,vmin,importType, engine);
+ bool ok = imports->d->add(imports->d->base,qmldircomponentsnetwork, uri,prefix,vmaj,vmin,importType, engine, errorString);
return ok;
}
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 6532d30..06b5027 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -283,7 +283,8 @@ public:
bool addToImport(Imports*, const QDeclarativeDirComponents &qmldircomponentsnetwork,
const QString& uri, const QString& prefix, int vmaj, int vmin,
- QDeclarativeScriptParser::Import::Type importType) const;
+ QDeclarativeScriptParser::Import::Type importType,
+ QString *errorString) const;
bool resolveType(const Imports&, const QByteArray& type,
QDeclarativeType** type_return, QUrl* url_return,
int *version_major, int *version_minor,
diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp
index b32e575..c512d97 100644
--- a/src/declarative/qml/qdeclarativemetatype.cpp
+++ b/src/declarative/qml/qdeclarativemetatype.cpp
@@ -98,6 +98,13 @@ struct QDeclarativeMetaTypeData
typedef QHash<int, QDeclarativeMetaType::StringConverter> StringConverters;
StringConverters stringConverters;
+ struct ModuleInfo {
+ ModuleInfo(int maj, int min) : vmajor(maj), vminor(min) {}
+ int vmajor, vminor;
+ };
+ typedef QHash<QByteArray, ModuleInfo> ModuleInfoHash;
+ ModuleInfoHash modules;
+
QBitArray objects;
QBitArray interfaces;
QBitArray lists;
@@ -441,9 +448,30 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t
data->objects.setBit(type.typeId, true);
if (type.listId) data->lists.setBit(type.listId, true);
+ if (type.uri) {
+ QByteArray mod(type.uri);
+ QDeclarativeMetaTypeData::ModuleInfoHash::Iterator it = data->modules.find(mod);
+ if (it == data->modules.end()
+ || ((*it).vmajor < type.versionMajor || ((*it).vmajor == type.versionMajor && (*it).vminor < type.versionMinor))) {
+ data->modules.insert(mod, QDeclarativeMetaTypeData::ModuleInfo(type.versionMajor,type.versionMinor));
+ }
+ }
+
return index;
}
+/*
+ Have any types been registered for \a module with at least versionMajor.versionMinor.
+*/
+bool QDeclarativeMetaType::isModule(const QByteArray &module, int versionMajor, int versionMinor)
+{
+ QDeclarativeMetaTypeData *data = metaTypeData();
+ QDeclarativeMetaTypeData::ModuleInfoHash::Iterator it = data->modules.find(module);
+ return it != data->modules.end()
+ && ((*it).vmajor > versionMajor ||
+ ((*it).vmajor == versionMajor && (*it).vminor >= versionMinor));
+}
+
QObject *QDeclarativeMetaType::toQObject(const QVariant &v, bool *ok)
{
if (!isQObject(v.userType())) {
diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h
index 1a36f10..e70b4bf 100644
--- a/src/declarative/qml/qdeclarativemetatype_p.h
+++ b/src/declarative/qml/qdeclarativemetatype_p.h
@@ -97,6 +97,8 @@ public:
typedef QVariant (*StringConverter)(const QString &);
static void registerCustomStringConverter(int, StringConverter);
static StringConverter customStringConverter(int);
+
+ static bool isModule(const QByteArray &module, int versionMajor, int versionMinor);
};
class QDeclarativeTypePrivate;
diff --git a/tests/auto/declarative/qdeclarativedom/data/importdir/Bar.qml b/tests/auto/declarative/qdeclarativedom/data/import/Bar.qml
index 2d1a4a3..2d1a4a3 100644
--- a/tests/auto/declarative/qdeclarativedom/data/importdir/Bar.qml
+++ b/tests/auto/declarative/qdeclarativedom/data/import/Bar.qml
diff --git a/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir/Foo.qml b/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/Foo.qml
index 2d1a4a3..2d1a4a3 100644
--- a/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir/Foo.qml
+++ b/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/Foo.qml
diff --git a/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir b/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir
new file mode 100644
index 0000000..5bdd17b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativedom/data/importlib/sublib/qmldir
@@ -0,0 +1 @@
+Foo Foo.qml
diff --git a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp
index 6cd0bdb..adea384 100644
--- a/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp
+++ b/tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp
@@ -340,9 +340,8 @@ void tst_qdeclarativedom::loadImports()
"Item {}";
QDeclarativeEngine engine;
- engine.addImportPath(SRCDIR "/data");
QDeclarativeDomDocument document;
- QVERIFY(document.load(&engine, qml));
+ QVERIFY(document.load(&engine, qml, QUrl::fromLocalFile(SRCDIR "/data/dummy.qml")));
QCOMPARE(document.imports().size(), 5);
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.errors.txt
new file mode 100644
index 0000000..413f096
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.errors.txt
@@ -0,0 +1 @@
+1:1:module "Test" version 2.0 is not installed
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.qml b/tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.qml
new file mode 100644
index 0000000..c4a0d38
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/importNewerVersion.qml
@@ -0,0 +1,3 @@
+import Test 2.0
+
+MyTypeObject { }
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNonExist.errors.txt b/tests/auto/declarative/qdeclarativelanguage/data/importNonExist.errors.txt
new file mode 100644
index 0000000..1baf05c
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/importNonExist.errors.txt
@@ -0,0 +1 @@
+2:1:"will-not-be-found": no such directory
diff --git a/tests/auto/declarative/qdeclarativelanguage/data/importNonExist.qml b/tests/auto/declarative/qdeclarativelanguage/data/importNonExist.qml
new file mode 100644
index 0000000..ec6aa2b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelanguage/data/importNonExist.qml
@@ -0,0 +1,5 @@
+// imports...
+import "will-not-be-found"
+import Qt 4.6
+
+Rectangle { }
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index 9188d72..42426a2 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -264,6 +264,8 @@ void tst_qdeclarativelanguage::errors_data()
QTest::newRow("importNamespaceConflict") << "importNamespaceConflict.qml" << "importNamespaceConflict.errors.txt" << false;
QTest::newRow("importVersionMissing (builtin)") << "importVersionMissingBuiltIn.qml" << "importVersionMissingBuiltIn.errors.txt" << false;
QTest::newRow("importVersionMissing (installed)") << "importVersionMissingInstalled.qml" << "importVersionMissingInstalled.errors.txt" << false;
+ QTest::newRow("importNonExist (installed)") << "importNonExist.qml" << "importNonExist.errors.txt" << false;
+ QTest::newRow("importNewerVersion (installed)") << "importNewerVersion.qml" << "importNewerVersion.errors.txt" << false;
QTest::newRow("invalidImportID") << "invalidImportID.qml" << "invalidImportID.errors.txt" << false;
QTest::newRow("signal.1") << "signal.1.qml" << "signal.1.errors.txt" << false;