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/qqmlfileselector.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/qqmlfileselector.cpp')
-rw-r--r-- | src/qml/qml/qqmlfileselector.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/qml/qml/qqmlfileselector.cpp b/src/qml/qml/qqmlfileselector.cpp index 396d500eac..1ea2b23153 100644 --- a/src/qml/qml/qqmlfileselector.cpp +++ b/src/qml/qml/qqmlfileselector.cpp @@ -42,6 +42,7 @@ #include <qobjectdefs.h> #include "qqmlfileselector.h" #include "qqmlfileselector_p.h" +#include "qqmlengine_p.h" #include <QDebug> QT_BEGIN_NAMESPACE @@ -105,7 +106,7 @@ QQmlFileSelector::QQmlFileSelector(QQmlEngine* engine, QObject* parent) Q_D(QQmlFileSelector); d->engine = engine; interceptorInstances()->insert(d->myInstance.data(), this); - d->engine->setUrlInterceptor(d->myInstance.data()); + d->engine->addUrlInterceptor(d->myInstance.data()); } /*! @@ -115,7 +116,7 @@ QQmlFileSelector::~QQmlFileSelector() { Q_D(QQmlFileSelector); if (d->engine && QQmlFileSelector::get(d->engine) == this) { - d->engine->setUrlInterceptor(nullptr); + d->engine->removeUrlInterceptor(d->myInstance.data()); d->engine = nullptr; } interceptorInstances()->remove(d->myInstance.data()); @@ -185,9 +186,11 @@ void QQmlFileSelector::setExtraSelectors(const QStringList &strings) QQmlFileSelector* QQmlFileSelector::get(QQmlEngine* engine) { //Since I think we still can't use dynamic_cast inside Qt... - QQmlAbstractUrlInterceptor* current = engine->urlInterceptor(); - if (current && interceptorInstances()->contains(current)) - return interceptorInstances()->value(current); + const QQmlEnginePrivate *enginePrivate = QQmlEnginePrivate::get(engine); + for (QQmlAbstractUrlInterceptor *current : enginePrivate->urlInterceptors) { + if (interceptorInstances()->contains(current)) + return interceptorInstances()->value(current); + } return nullptr; } |