aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorMatthew Vogt <matthew.vogt@nokia.com>2012-03-26 16:39:00 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-29 00:36:49 +0200
commite4baefacff3e04ea3b599c5279e883d75d2ad489 (patch)
treedc78ce14db08c0aa771ddff9df8c23da8b8919ba /src/qml/qml
parent5de103291d8159a236cabcc689caade265de1bd5 (diff)
Re-order imports statements to import nested imports later
Re-order the imports for a script by increasing order of URI length. This ensures that an import of the type 'import X.Y' is processed after the import of 'import X' which contains the type definitions for the namespace X.Y. Task-number: QTBUG-24369 Change-Id: I1b06e9d114a97c9f47279f8f33383a27e0efb4bb Reviewed-by: Chris Adams <christopher.adams@nokia.com> Reviewed-by: Michael Brasser <michael.brasser@nokia.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmlimport.cpp36
-rw-r--r--src/qml/qml/qqmlscript.cpp5
-rw-r--r--src/qml/qml/qqmlscript_p.h5
3 files changed, 28 insertions, 18 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index 1224efdaac..be870cad4c 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -545,27 +545,27 @@ QString QQmlImportsPrivate::add(const QQmlDirComponents &qmldircomponentsnetwork
}
}
- // TODO: Should this search be omitted if found == true?
-
- // step 2: search for extension with encoded version major
- foreach (const QString &p, database->fileImportPath) {
- dir = p+Slash+url;
+ if (!found) {
+ // step 2: search for extension with encoded version major
+ foreach (const QString &p, database->fileImportPath) {
+ dir = p+Slash+url;
- QFileInfo fi(dir+QString(QLatin1String(".%1")).arg(vmaj)+QLatin1String("/qmldir"));
- const QString absoluteFilePath = fi.absoluteFilePath();
+ QFileInfo fi(dir+QString(QLatin1String(".%1")).arg(vmaj)+QLatin1String("/qmldir"));
+ const QString absoluteFilePath = fi.absoluteFilePath();
- if (fi.isFile()) {
- found = true;
+ if (fi.isFile()) {
+ found = true;
- const QString absolutePath = fi.absolutePath();
- if (absolutePath.at(0) == QLatin1Char(':'))
- url = QLatin1String("qrc://") + absolutePath.mid(1);
- else
- url = QUrl::fromLocalFile(fi.absolutePath()).toString();
- uri = resolvedUri(dir, database);
- if (!importExtension(absoluteFilePath, uri, database, &qmldircomponents, &qmldirscripts, errors))
- return QString();
- break;
+ const QString absolutePath = fi.absolutePath();
+ if (absolutePath.at(0) == QLatin1Char(':'))
+ url = QLatin1String("qrc://") + absolutePath.mid(1);
+ else
+ url = QUrl::fromLocalFile(fi.absolutePath()).toString();
+ uri = resolvedUri(dir, database);
+ if (!importExtension(absoluteFilePath, uri, database, &qmldircomponents, &qmldirscripts, errors))
+ return QString();
+ break;
+ }
}
}
diff --git a/src/qml/qml/qqmlscript.cpp b/src/qml/qml/qqmlscript.cpp
index 8e22e488ed..b1bb5ed866 100644
--- a/src/qml/qml/qqmlscript.cpp
+++ b/src/qml/qml/qqmlscript.cpp
@@ -1340,6 +1340,11 @@ bool QQmlScript::Parser::parse(const QByteArray &qmldata, const QUrl &url,
_errors[ii].setUrl(url);
}
+ if (_errors.isEmpty()) {
+ // Sort the imports into desired order
+ qStableSort(_imports.begin(), _imports.end());
+ }
+
return _errors.isEmpty();
}
diff --git a/src/qml/qml/qqmlscript_p.h b/src/qml/qml/qqmlscript_p.h
index ddf4c9a392..debe894376 100644
--- a/src/qml/qml/qqmlscript_p.h
+++ b/src/qml/qml/qqmlscript_p.h
@@ -121,6 +121,11 @@ public:
void extractVersion(int *maj, int *min) const;
QQmlScript::LocationSpan location;
+
+ bool operator<(const Import& other) const {
+ // Shorter URIs first, so 'import X' is before 'import X.Y'
+ return (uri.length() < other.uri.length());
+ }
};
class Object;