diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-02-07 16:22:53 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-17 14:44:26 +0100 |
commit | f4937a21b61bf2f214d175d77c432c68f25ead21 (patch) | |
tree | a9753103192cf6310913ed3127bf48d80aed8462 /src/qml/qml/qqmltypeloader.cpp | |
parent | 1eb20d70619cc896fc283bd6605b257a8750c518 (diff) |
Allow multiple URL interceptors per engine
We may want to have, for example, a QQmlFileSelector and a
component-specific interceptor that chooses a theme or similar.
Also, make the API public. We want to propose this as alternative to
dynamically registering QML files via qmlRegisterType(QUrl, ...).
Change-Id: I4a535d3ea556da6710fde816579ec188b3f57099
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmltypeloader.cpp')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 75dc9d15a5..c8e5054f87 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -625,13 +625,15 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo // We haven't yet resolved this import m_unresolvedImports << import; - QQmlAbstractUrlInterceptor *interceptor = typeLoader()->engine()->urlInterceptor(); + const QQmlEngine *engine = typeLoader()->engine(); + const bool hasInterceptors + = !(QQmlEnginePrivate::get(engine)->urlInterceptors.isEmpty()); // Query any network import paths for this library. // Interceptor might redirect local paths. QStringList remotePathList = importDatabase->importPathList( - interceptor ? QQmlImportDatabase::LocalOrRemote - : QQmlImportDatabase::Remote); + hasInterceptors ? QQmlImportDatabase::LocalOrRemote + : QQmlImportDatabase::Remote); if (!remotePathList.isEmpty()) { // Add this library and request the possible locations for it if (!m_importCache.addLibraryImport( @@ -644,8 +646,8 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths( import->uri, remotePathList, import->version); for (const QString &qmldirPath : qmlDirPaths) { - if (interceptor) { - QUrl url = interceptor->intercept( + if (hasInterceptors) { + QUrl url = engine->interceptUrl( QQmlImports::urlFromLocalFileOrQrcOrUrl(qmldirPath), QQmlAbstractUrlInterceptor::QmldirFile); if (!QQmlFile::isLocalFile(url) |