diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-08-29 09:45:59 +0300 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-09-04 14:16:54 +0000 |
commit | 3bd2541f84be5200a54c7565074ea22992397c79 (patch) | |
tree | 6d29532cdcf10a59cd133129ad31bf06f584b812 /src | |
parent | ffd680a132db99f1fa1e9ebb75c844c491afa83b (diff) | |
download | qtlocation-3bd2541f84be5200a54c7565074ea22992397c79.tar.gz |
Allow injecting the qml engine into geoservice plugins
With this geoservice plugins can register Image Providers.
Change-Id: Ie2380d658758d2eba376035b4d0b5d5121cfcde2
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp | 1 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceprovider.cpp | 27 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceprovider.h | 2 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceprovider_p.h | 4 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceproviderfactory.cpp | 13 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceproviderfactory.h | 14 |
6 files changed, 53 insertions, 8 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp b/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp index 09309bcd..b594d2dc 100644 --- a/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp +++ b/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp @@ -146,6 +146,7 @@ void QDeclarativeGeoServiceProvider::tryAttach() return; sharedProvider_ = new QGeoServiceProvider(name_, parameterMap()); + sharedProvider_->setQmlEngine(qmlEngine(this)); sharedProvider_->setLocale(locales_.at(0)); sharedProvider_->setAllowExperimental(experimental_); diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp index 2d8151ad..11b1c28d 100644 --- a/src/location/maps/qgeoserviceprovider.cpp +++ b/src/location/maps/qgeoserviceprovider.cpp @@ -572,6 +572,11 @@ void QGeoServiceProvider::setAllowExperimental(bool allow) d_ptr->loadMeta(); } +void QGeoServiceProvider::setQmlEngine(QQmlEngine *engine) +{ + d_ptr->qmlEngine = engine; +} + /*! Sets the parameters used to construct individual manager classes for this service provider to \a parameters. @@ -660,7 +665,7 @@ void QGeoServiceProviderPrivate::unload() delete navigationManager; navigationManager = nullptr; - factory = factoryV2 = nullptr; + factory = factoryV2 = factoryV3 = nullptr; error = QGeoServiceProvider::NoError; errorString = QLatin1String(""); metaData = QJsonObject(); @@ -690,7 +695,7 @@ void QGeoServiceProviderPrivate::filterParameterMap() void QGeoServiceProviderPrivate::loadMeta() { - factory = factoryV2 = nullptr; + factory = factoryV2 = factoryV3 = nullptr; metaData = QJsonObject(); metaData.insert(QStringLiteral("index"), -1); error = QGeoServiceProvider::NotSupportedError; @@ -731,7 +736,7 @@ void QGeoServiceProviderPrivate::loadPlugin(const QVariantMap ¶meters) if (int(metaData.value(QStringLiteral("index")).toDouble()) < 0) { error = QGeoServiceProvider::NotSupportedError; errorString = QString(QLatin1String("The geoservices provider is not supported.")); - factory = factoryV2 = nullptr; + factory = factoryV2 = factoryV3 = nullptr; return; } @@ -742,11 +747,17 @@ void QGeoServiceProviderPrivate::loadPlugin(const QVariantMap ¶meters) // load the actual plugin QObject *instance = loader()->instance(idx); - factoryV2 = qobject_cast<QGeoServiceProviderFactoryV2 *>(instance); - if (!factoryV2) - factory = qobject_cast<QGeoServiceProviderFactory *>(instance); - else - factory = factoryV2; + factoryV3 = qobject_cast<QGeoServiceProviderFactoryV3 *>(instance); + if (!factoryV3) { + factoryV2 = qobject_cast<QGeoServiceProviderFactoryV2 *>(instance); + if (!factoryV2) + factory = qobject_cast<QGeoServiceProviderFactory *>(instance); + else + factory = factoryV2; + } else { + factory = factoryV2 = factoryV3; + factoryV3->setQmlEngine(qmlEngine); + } } QHash<QString, QJsonObject> QGeoServiceProviderPrivate::plugins(bool reload) diff --git a/src/location/maps/qgeoserviceprovider.h b/src/location/maps/qgeoserviceprovider.h index 640e9843..8e594977 100644 --- a/src/location/maps/qgeoserviceprovider.h +++ b/src/location/maps/qgeoserviceprovider.h @@ -57,6 +57,7 @@ class QGeoRoutingManagerEngine; class QPlaceManagerEngine; class QNavigationManagerEngine; class QGeoServiceProviderPrivate; +class QQmlEngine; class Q_LOCATION_EXPORT QGeoServiceProvider : public QObject { @@ -162,6 +163,7 @@ public: void setParameters(const QVariantMap ¶meters); void setLocale(const QLocale &locale); void setAllowExperimental(bool allow); + void setQmlEngine(QQmlEngine *engine); private: QGeoServiceProviderPrivate *d_ptr; diff --git a/src/location/maps/qgeoserviceprovider_p.h b/src/location/maps/qgeoserviceprovider_p.h index 11b86bad..c6b03ce5 100644 --- a/src/location/maps/qgeoserviceprovider_p.h +++ b/src/location/maps/qgeoserviceprovider_p.h @@ -63,6 +63,8 @@ class QGeoMappingManager; class QGeoServiceProviderFactory; class QGeoServiceProviderFactoryV2; +class QGeoServiceProviderFactoryV3; +class QQmlEngine; class QGeoServiceProviderPrivate { @@ -84,6 +86,7 @@ public: QGeoServiceProviderFactory *factory; QGeoServiceProviderFactoryV2 *factoryV2 = nullptr; + QGeoServiceProviderFactoryV3 *factoryV3 = nullptr; QJsonObject metaData; QVariantMap parameterMap; @@ -96,6 +99,7 @@ public: QGeoMappingManager *mappingManager; QPlaceManager *placeManager; QNavigationManager *navigationManager = nullptr; + QQmlEngine *qmlEngine = nullptr; QGeoServiceProvider::Error geocodeError; QGeoServiceProvider::Error routingError; diff --git a/src/location/maps/qgeoserviceproviderfactory.cpp b/src/location/maps/qgeoserviceproviderfactory.cpp index 44ed3535..65a88710 100644 --- a/src/location/maps/qgeoserviceproviderfactory.cpp +++ b/src/location/maps/qgeoserviceproviderfactory.cpp @@ -207,4 +207,17 @@ QNavigationManagerEngine *QGeoServiceProviderFactoryV2::createNavigationManagerE return 0; } +/*! + Notify the plugin when the qml engine is ready. In this moment the plugins can use it + to register Image Providers. + + The default implementation does nothing. + \since 5.12 +*/ +void QGeoServiceProviderFactoryV3::setQmlEngine(QQmlEngine *engine) +{ + Q_UNUSED(engine) +} + QT_END_NAMESPACE + diff --git a/src/location/maps/qgeoserviceproviderfactory.h b/src/location/maps/qgeoserviceproviderfactory.h index 1eb93a18..8b3b0389 100644 --- a/src/location/maps/qgeoserviceproviderfactory.h +++ b/src/location/maps/qgeoserviceproviderfactory.h @@ -44,6 +44,7 @@ #include <QtCore/QString> QT_BEGIN_NAMESPACE +class QQmlEngine; class Q_LOCATION_EXPORT QGeoServiceProviderFactory { @@ -82,6 +83,19 @@ public: Q_DECLARE_INTERFACE(QGeoServiceProviderFactoryV2, "org.qt-project.qt.geoservice.serviceproviderfactoryV2/5.0") +class Q_LOCATION_EXPORT QGeoServiceProviderFactoryV3 : public QGeoServiceProviderFactoryV2 +{ +public: + virtual ~QGeoServiceProviderFactoryV3() {} + + virtual void setQmlEngine(QQmlEngine * engine); +}; + +// Although not actually used for constructing a specialized loader, this is required for +// casting a QObject * into QGeoServiceProviderFactoryV3 * +Q_DECLARE_INTERFACE(QGeoServiceProviderFactoryV3, + "org.qt-project.qt.geoservice.serviceproviderfactoryV3/5.0") + QT_END_NAMESPACE #endif |