aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlimport.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-02-07 16:22:53 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-03-17 14:44:26 +0100
commitf4937a21b61bf2f214d175d77c432c68f25ead21 (patch)
treea9753103192cf6310913ed3127bf48d80aed8462 /src/qml/qml/qqmlimport.cpp
parent1eb20d70619cc896fc283bd6605b257a8750c518 (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/qqmlimport.cpp')
-rw-r--r--src/qml/qml/qqmlimport.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index 7f8728f364..43a9435f83 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -1381,20 +1381,21 @@ QQmlImports::LocalQmldirResult QQmlImportsPrivate::locateLocalQmldir(
}
}
- QQmlTypeLoader &typeLoader = QQmlEnginePrivate::get(database->engine)->typeLoader;
+ QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(database->engine);
+ QQmlTypeLoader &typeLoader = enginePrivate->typeLoader;
+ const bool hasInterceptors = !enginePrivate->urlInterceptors.isEmpty();
// Interceptor might redirect remote files to local ones.
- QQmlAbstractUrlInterceptor *interceptor = typeLoader.engine()->urlInterceptor();
QStringList localImportPaths = database->importPathList(
- interceptor ? QQmlImportDatabase::LocalOrRemote : QQmlImportDatabase::Local);
+ hasInterceptors ? QQmlImportDatabase::LocalOrRemote : QQmlImportDatabase::Local);
// Search local import paths for a matching version
const QStringList qmlDirPaths = QQmlImports::completeQmldirPaths(
uri, localImportPaths, version);
bool pathTurnedRemote = false;
for (QString qmldirPath : qmlDirPaths) {
- if (interceptor) {
- const QUrl intercepted = interceptor->intercept(
+ if (hasInterceptors) {
+ const QUrl intercepted = database->engine->interceptUrl(
QQmlImports::urlFromLocalFileOrQrcOrUrl(qmldirPath),
QQmlAbstractUrlInterceptor::QmldirFile);
qmldirPath = QQmlFile::urlToLocalFileOrQrc(intercepted);
@@ -1616,10 +1617,8 @@ bool QQmlImportsPrivate::addFileImport(const QString& uri, const QString &prefix
QString qmldirUrl = resolveLocalUrl(base, importUri + (importUri.endsWith(Slash)
? String_qmldir
: Slash_qmldir));
- if (QQmlAbstractUrlInterceptor *interceptor = typeLoader->engine()->urlInterceptor()) {
- qmldirUrl = interceptor->intercept(QUrl(qmldirUrl),
- QQmlAbstractUrlInterceptor::QmldirFile).toString();
- }
+ qmldirUrl = typeLoader->engine()->interceptUrl(
+ QUrl(qmldirUrl), QQmlAbstractUrlInterceptor::QmldirFile).toString();
QString qmldirIdentifier;
if (QQmlFile::isLocalFile(qmldirUrl)) {