diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-12 20:47:41 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-17 13:09:50 +0200 |
commit | 140634d2029bfcffd77b16175906082bd03d2d0c (patch) | |
tree | 1803d693e778dfcd50b10720a2f57b2bbb3da71a /src/qml/qml | |
parent | d2c6ac8d5eaa1d4b53b647f01c53d821bbba4665 (diff) |
Add support for implicit module imports
This allows a module to make another module import with the same minor
version and in the same qualified namespace. This will be used to make
import QtQuick 2.5 implicitly import QtQml 2.5, to maintain compatibility.
It used to be implemented by means of calling C++ type registration functions
directly.
Change-Id: I64c7bfe25d75b9a45f5d44a10d035fc2f86d30ca
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 21 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloaderqmldircontent.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloaderqmldircontent_p.h | 1 |
4 files changed, 29 insertions, 0 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index a1bf9e9201..3a18bbf7c9 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -517,6 +517,9 @@ bool QQmlTypeLoader::Blob::updateQmldir(const QQmlRefPointer<QQmlQmldirData> &da if (!m_importCache.updateQmldirContent(typeLoader()->importDatabase(), import->uri, import->qualifier, qmldirIdentifier, qmldirUrl, errors)) return false; + if (!loadImportDependencies(import, qmldirIdentifier, errors)) + return false; + import->priority = data->priority(this); // Release this reference at destruction @@ -573,6 +576,9 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo import->minorVersion, qmldirFilePath, qmldirUrl, false, errors)) return false; + if (!loadImportDependencies(import, qmldirFilePath, errors)) + return false; + if (!import->qualifier.isEmpty()) { // Does this library contain any qualified scripts? QUrl libraryUrl(qmldirUrl); @@ -677,6 +683,21 @@ void QQmlTypeLoader::Blob::dependencyComplete(QQmlDataBlob *blob) } } +bool QQmlTypeLoader::Blob::loadImportDependencies(PendingImportPtr currentImport, const QString &qmldirUri, QList<QQmlError> *errors) +{ + const QQmlTypeLoaderQmldirContent qmldir = typeLoader()->qmldirContent(qmldirUri); + for (const QString &implicitImports: qmldir.imports()) { + auto dependencyImport = std::make_shared<PendingImport>(); + dependencyImport->uri = implicitImports; + dependencyImport->qualifier = currentImport->qualifier; + dependencyImport->majorVersion = currentImport->majorVersion; + dependencyImport->minorVersion = currentImport->minorVersion; + if (!addImport(dependencyImport, errors)) + return false; + } + return true; +} + bool QQmlTypeLoader::Blob::isDebugging() const { return typeLoader()->engine()->handle()->debugger() != nullptr; diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index f8cec700a5..612d6777ed 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -122,6 +122,8 @@ public: void dependencyComplete(QQmlDataBlob *) override; + bool loadImportDependencies(PendingImportPtr currentImport, const QString &qmldirUri, QList<QQmlError> *errors); + protected: virtual QString stringAt(int) const { return QString(); } diff --git a/src/qml/qml/qqmltypeloaderqmldircontent.cpp b/src/qml/qml/qqmltypeloaderqmldircontent.cpp index 4aaa60f496..238af9b710 100644 --- a/src/qml/qml/qqmltypeloaderqmldircontent.cpp +++ b/src/qml/qml/qqmltypeloaderqmldircontent.cpp @@ -102,6 +102,11 @@ QQmlDirPlugins QQmlTypeLoaderQmldirContent::plugins() const return m_parser.plugins(); } +QStringList QQmlTypeLoaderQmldirContent::imports() const +{ + return m_parser.imports(); +} + QString QQmlTypeLoaderQmldirContent::pluginLocation() const { return m_location; diff --git a/src/qml/qml/qqmltypeloaderqmldircontent_p.h b/src/qml/qml/qqmltypeloaderqmldircontent_p.h index 9e0a80cea8..698643c7ec 100644 --- a/src/qml/qml/qqmltypeloaderqmldircontent_p.h +++ b/src/qml/qml/qqmltypeloaderqmldircontent_p.h @@ -78,6 +78,7 @@ public: QQmlDirComponents components() const; QQmlDirScripts scripts() const; QQmlDirPlugins plugins() const; + QStringList imports() const; QString pluginLocation() const; |