summaryrefslogtreecommitdiff
path: root/src/location/maps
diff options
context:
space:
mode:
authorAlex Wilson <alex.wilson@nokia.com>2012-02-28 13:05:02 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-05 04:22:24 +0100
commit0287bfee05840511c12100f06f9142e3e2b8f7d5 (patch)
treef5386e27a4b012877d37ab0b99dfc1d5a08705c5 /src/location/maps
parentc1d56bdae90f79d466769aa7a357d78a4f2ca6c7 (diff)
downloadqtlocation-0287bfee05840511c12100f06f9142e3e2b8f7d5.tar.gz
New plugin API changes, centralized geoservice feature detection
This change adapts geoservice plugins to use the new Qt5 plugin API, performing boolean feature detection all through the JSON blobs rather than methods on factories or managers. As a result of this centralisation, it was also necessary to rework the QML API for the Plugin element a little. Some additional changes were made to the declarative places plugin to prevent it crashing due to plugins becoming available later than they did previously. Task-number: QTBUG-24331 Change-Id: I26149987344b67091480449103ab1712c869b2a5 Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'src/location/maps')
-rw-r--r--src/location/maps/qgeocodingmanager.cpp19
-rw-r--r--src/location/maps/qgeocodingmanager.h3
-rw-r--r--src/location/maps/qgeocodingmanagerengine.cpp45
-rw-r--r--src/location/maps/qgeocodingmanagerengine.h8
-rw-r--r--src/location/maps/qgeocodingmanagerengine_p.h3
-rw-r--r--src/location/maps/qgeoroutingmanager.cpp24
-rw-r--r--src/location/maps/qgeoroutingmanager.h3
-rw-r--r--src/location/maps/qgeoroutingmanagerengine.cpp65
-rw-r--r--src/location/maps/qgeoroutingmanagerengine.h6
-rw-r--r--src/location/maps/qgeoroutingmanagerengine_p.h3
-rw-r--r--src/location/maps/qgeoserviceprovider.cpp335
-rw-r--r--src/location/maps/qgeoserviceprovider.h77
-rw-r--r--src/location/maps/qgeoserviceprovider_p.h21
-rw-r--r--src/location/maps/qgeoserviceproviderfactory.cpp19
-rw-r--r--src/location/maps/qgeoserviceproviderfactory.h12
15 files changed, 363 insertions, 280 deletions
diff --git a/src/location/maps/qgeocodingmanager.cpp b/src/location/maps/qgeocodingmanager.cpp
index bb44c98e..cb4bc3f7 100644
--- a/src/location/maps/qgeocodingmanager.cpp
+++ b/src/location/maps/qgeocodingmanager.cpp
@@ -271,25 +271,6 @@ QGeocodeReply* QGeocodingManager::geocode(const QString &address,
}
/*!
- Returns whether this manager supports geocoding.
-*/
-bool QGeocodingManager::supportsGeocoding() const
-{
-// if (!d_ptr->engine)
-// return false;
-
- return d_ptr->engine->supportsGeocoding();
-}
-
-/*!
- Returns whether this manager supports reverse geocoding.
-*/
-bool QGeocodingManager::supportsReverseGeocoding() const
-{
- return d_ptr->engine->supportsReverseGeocoding();
-}
-
-/*!
Sets the locale to be used by this manager to \a locale.
If this geocoding manager supports returning the results
diff --git a/src/location/maps/qgeocodingmanager.h b/src/location/maps/qgeocodingmanager.h
index da85132d..b3a9c339 100644
--- a/src/location/maps/qgeocodingmanager.h
+++ b/src/location/maps/qgeocodingmanager.h
@@ -79,9 +79,6 @@ public:
QGeocodeReply* reverseGeocode(const QGeoCoordinate &coordinate,
const QGeoBoundingArea &bounds = QGeoBoundingArea());
- bool supportsGeocoding() const;
- bool supportsReverseGeocoding() const;
-
void setLocale(const QLocale &locale);
QLocale locale() const;
diff --git a/src/location/maps/qgeocodingmanagerengine.cpp b/src/location/maps/qgeocodingmanagerengine.cpp
index 5d9412e2..b4478e29 100644
--- a/src/location/maps/qgeocodingmanagerengine.cpp
+++ b/src/location/maps/qgeocodingmanagerengine.cpp
@@ -272,46 +272,6 @@ QGeocodeReply* QGeocodingManagerEngine::geocode(const QString &address,
}
/*!
- Sets whether geocoding is supported by this engine to \a supported.
-
- It is important that subclasses use this method to ensure that the engine
- reports its capabilities correctly. If this function is not used the
- engine will report that it does not support geocoding.
-*/
-void QGeocodingManagerEngine::setSupportsGeocoding(bool supported)
-{
- d_ptr->supportsGeocoding = supported;
-}
-
-/*!
- Returns whether this engine supports geocoding.
-*/
-bool QGeocodingManagerEngine::supportsGeocoding() const
-{
- return d_ptr->supportsGeocoding;
-}
-
-/*!
- Sets whether reverse geocoding is supported by this engine to \a supported.
-
- It is important that subclasses use this method to ensure that the engine
- reports its capabilities correctly. If this function is not used the
- engine will report that it does not support reverse geocoding.
-*/
-void QGeocodingManagerEngine::setSupportsReverseGeocoding(bool supported)
-{
- d_ptr->supportsReverseGeocoding = supported;
-}
-
-/*!
- Returns whether this engine supports reverse geocoding.
-*/
-bool QGeocodingManagerEngine::supportsReverseGeocoding() const
-{
- return d_ptr->supportsReverseGeocoding;
-}
-
-/*!
Sets the locale to be used by this manager to \a locale.
If this geocoding manager supports returning the results
@@ -367,9 +327,8 @@ QLocale QGeocodingManagerEngine::locale() const
*******************************************************************************/
QGeocodingManagerEnginePrivate::QGeocodingManagerEnginePrivate()
- : managerVersion(-1),
- supportsGeocoding(false),
- supportsReverseGeocoding(false) {}
+ : managerVersion(-1)
+{}
QGeocodingManagerEnginePrivate::~QGeocodingManagerEnginePrivate()
{
diff --git a/src/location/maps/qgeocodingmanagerengine.h b/src/location/maps/qgeocodingmanagerengine.h
index 49069dd5..d4a4451f 100644
--- a/src/location/maps/qgeocodingmanagerengine.h
+++ b/src/location/maps/qgeocodingmanagerengine.h
@@ -77,10 +77,6 @@ public:
const QGeoBoundingArea &bounds);
-
- bool supportsGeocoding() const;
- bool supportsReverseGeocoding() const;
-
void setLocale(const QLocale &locale);
QLocale locale() const;
@@ -88,10 +84,6 @@ Q_SIGNALS:
void finished(QGeocodeReply* reply);
void error(QGeocodeReply* reply, QGeocodeReply::Error error, QString errorString = QString());
-protected:
- void setSupportsGeocoding(bool supported);
- void setSupportsReverseGeocoding(bool supported);
-
private:
void setManagerName(const QString &managerName);
void setManagerVersion(int managerVersion);
diff --git a/src/location/maps/qgeocodingmanagerengine_p.h b/src/location/maps/qgeocodingmanagerengine_p.h
index 647f9cd9..ec531365 100644
--- a/src/location/maps/qgeocodingmanagerengine_p.h
+++ b/src/location/maps/qgeocodingmanagerengine_p.h
@@ -69,9 +69,6 @@ public:
QString managerName;
int managerVersion;
- bool supportsGeocoding;
- bool supportsReverseGeocoding;
-
QLocale locale;
private:
diff --git a/src/location/maps/qgeoroutingmanager.cpp b/src/location/maps/qgeoroutingmanager.cpp
index ebd4712b..6d5e5acc 100644
--- a/src/location/maps/qgeoroutingmanager.cpp
+++ b/src/location/maps/qgeoroutingmanager.cpp
@@ -273,30 +273,6 @@ QGeoRouteReply* QGeoRoutingManager::updateRoute(const QGeoRoute &route, const QG
}
/*!
- Returns whether this manager supports updating routes.
-*/
-bool QGeoRoutingManager::supportsRouteUpdates() const
-{
- return d_ptr->engine->supportsRouteUpdates();
-}
-
-/*!
- Returns whether this manager supports request for alternative routes.
-*/
-bool QGeoRoutingManager::supportsAlternativeRoutes() const
-{
- return d_ptr->engine->supportsAlternativeRoutes();
-}
-
-/*!
- Returns whether this engine supports the exclusion of areas from routes.
-*/
-bool QGeoRoutingManager::supportsExcludeAreas() const
-{
- return d_ptr->engine->supportsExcludeAreas();
-}
-
-/*!
Returns the travel modes supported by this manager.
*/
QGeoRouteRequest::TravelModes QGeoRoutingManager::supportedTravelModes() const
diff --git a/src/location/maps/qgeoroutingmanager.h b/src/location/maps/qgeoroutingmanager.h
index dd882cac..c9131ac4 100644
--- a/src/location/maps/qgeoroutingmanager.h
+++ b/src/location/maps/qgeoroutingmanager.h
@@ -71,9 +71,6 @@ public:
QGeoRouteReply* calculateRoute(const QGeoRouteRequest& request);
QGeoRouteReply* updateRoute(const QGeoRoute &route, const QGeoCoordinate &position);
- bool supportsRouteUpdates() const;
- bool supportsAlternativeRoutes() const;
- bool supportsExcludeAreas() const;
QGeoRouteRequest::TravelModes supportedTravelModes() const;
QGeoRouteRequest::FeatureTypes supportedFeatureTypes() const;
QGeoRouteRequest::FeatureWeights supportedFeatureWeights() const;
diff --git a/src/location/maps/qgeoroutingmanagerengine.cpp b/src/location/maps/qgeoroutingmanagerengine.cpp
index bc6ae5f7..d6f64e2c 100644
--- a/src/location/maps/qgeoroutingmanagerengine.cpp
+++ b/src/location/maps/qgeoroutingmanagerengine.cpp
@@ -208,66 +208,6 @@ QGeoRouteReply* QGeoRoutingManagerEngine::updateRoute(const QGeoRoute &route, co
}
/*!
- Sets whether this engine supports updating routes to \a supported.
-
- It is important that subclasses use this method to ensure that the engine
- reports its capabilities correctly. If this function is not used the
- engine will report that it does not support updating routes.
-*/
-void QGeoRoutingManagerEngine::setSupportsRouteUpdates(bool supported)
-{
- d_ptr->supportsRouteUpdates = supported;
-}
-
-/*!
- Returns whether this engine supports updating routes.
-*/
-bool QGeoRoutingManagerEngine::supportsRouteUpdates() const
-{
- return d_ptr->supportsRouteUpdates;
-}
-
-/*!
- Sets whether this engine supports request for alternative routes to \a supported.
-
- It is important that subclasses use this method to ensure that the engine
- reports its capabilities correctly. If this function is not used the
- engine will report that it does not support alternative routes.
-*/
-void QGeoRoutingManagerEngine::setSupportsAlternativeRoutes(bool supported)
-{
- d_ptr->supportsAlternativeRoutes = supported;
-}
-
-/*!
- Returns whether this engine supports request for alternative routes.
-*/
-bool QGeoRoutingManagerEngine::supportsAlternativeRoutes() const
-{
- return d_ptr->supportsAlternativeRoutes;
-}
-
-/*!
- Sets whether this engine supports request for excluding areas from routes to \a supported.
-
- It is important that subclasses use this method to ensure that the engine
- reports its capabilities correctly. If this function is not used the
- engine will report that it does not support excluding areas.
-*/
-void QGeoRoutingManagerEngine::setSupportsExcludeAreas(bool supported)
-{
- d_ptr->supportsExcludeAreas = supported;
-}
-
-/*!
- Returns whether this engine supports the exclusion of areas from routes.
-*/
-bool QGeoRoutingManagerEngine::supportsExcludeAreas() const
-{
- return d_ptr->supportsExcludeAreas;
-}
-
-/*!
Sets the travel modes supported by this engine to \a travelModes.
It is important that subclasses use this method to ensure that the engine
@@ -451,10 +391,7 @@ Use deleteLater() instead.
*******************************************************************************/
QGeoRoutingManagerEnginePrivate::QGeoRoutingManagerEnginePrivate()
- : managerVersion(-1),
- supportsRouteUpdates(false),
- supportsAlternativeRoutes(false),
- supportsExcludeAreas(false)
+ : managerVersion(-1)
{
}
diff --git a/src/location/maps/qgeoroutingmanagerengine.h b/src/location/maps/qgeoroutingmanagerengine.h
index c943a82b..3ddf863f 100644
--- a/src/location/maps/qgeoroutingmanagerengine.h
+++ b/src/location/maps/qgeoroutingmanagerengine.h
@@ -71,9 +71,6 @@ public:
virtual QGeoRouteReply* calculateRoute(const QGeoRouteRequest& request) = 0;
virtual QGeoRouteReply* updateRoute(const QGeoRoute &route, const QGeoCoordinate &position);
- bool supportsRouteUpdates() const;
- bool supportsAlternativeRoutes() const;
- bool supportsExcludeAreas() const;
QGeoRouteRequest::TravelModes supportedTravelModes() const;
QGeoRouteRequest::FeatureTypes supportedFeatureTypes() const;
QGeoRouteRequest::FeatureWeights supportedFeatureWeights() const;
@@ -89,9 +86,6 @@ Q_SIGNALS:
void error(QGeoRouteReply* reply, QGeoRouteReply::Error error, QString errorString = QString());
protected:
- void setSupportsRouteUpdates(bool supported);
- void setSupportsAlternativeRoutes(bool supported);
- void setSupportsExcludeAreas(bool supported);
void setSupportedTravelModes(QGeoRouteRequest::TravelModes travelModes);
void setSupportedFeatureTypes(QGeoRouteRequest::FeatureTypes featureTypes);
void setSupportedFeatureWeights(QGeoRouteRequest::FeatureWeights featureWeights);
diff --git a/src/location/maps/qgeoroutingmanagerengine_p.h b/src/location/maps/qgeoroutingmanagerengine_p.h
index d4dda277..c114589e 100644
--- a/src/location/maps/qgeoroutingmanagerengine_p.h
+++ b/src/location/maps/qgeoroutingmanagerengine_p.h
@@ -69,9 +69,6 @@ public:
QString managerName;
int managerVersion;
- bool supportsRouteUpdates;
- bool supportsAlternativeRoutes;
- bool supportsExcludeAreas;
QGeoRouteRequest::TravelModes supportedTravelModes;
QGeoRouteRequest::FeatureTypes supportedFeatureTypes;
QGeoRouteRequest::FeatureWeights supportedFeatureWeights;
diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp
index 55678b2c..aad4138d 100644
--- a/src/location/maps/qgeoserviceprovider.cpp
+++ b/src/location/maps/qgeoserviceprovider.cpp
@@ -62,15 +62,19 @@
#include <QStringList>
#include <QCoreApplication>
#include <QObject>
+#include <QMetaObject>
+#include <QMetaEnum>
#include <QProcess>
#include <QEventLoop>
+#include <QString>
#include <QtCore/private/qfactoryloader_p.h>
QT_BEGIN_NAMESPACE
#ifndef QT_NO_LIBRARY
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
- (QT_GEOSERVICE_BACKEND_INTERFACE, QLatin1String("/geoservices")))
+ ("org.qt-project.qt.geoservice.serviceproviderfactory/5.0",
+ QLatin1String("/geoservices")))
#endif
/*!
@@ -144,11 +148,13 @@ QStringList QGeoServiceProvider::availableServiceProviders()
If no plugin matching \a providerName was able to be loaded then error()
and errorString() will provide details about why this is the case.
*/
-QGeoServiceProvider::QGeoServiceProvider(const QString &providerName, const QMap<QString, QVariant> &parameters)
+QGeoServiceProvider::QGeoServiceProvider(const QString &providerName, const QMap<QString, QVariant> &parameters, bool experimental)
: d_ptr(new QGeoServiceProviderPrivate())
{
- d_ptr->loadPlugin(providerName, parameters);
+ d_ptr->experimental = experimental;
d_ptr->parameterMap = parameters;
+ d_ptr->providerName = providerName;
+ d_ptr->loadMeta();
}
/*!
@@ -159,6 +165,90 @@ QGeoServiceProvider::~QGeoServiceProvider()
delete d_ptr;
}
+QGeoServiceProvider::RoutingFeatures QGeoServiceProvider::routingFeatures() const
+{
+ const QMetaObject *mo = QGeoServiceProvider::metaObject();
+ const QMetaEnum en = mo->enumerator(
+ mo->indexOfEnumerator("RoutingFeatures"));
+
+ RoutingFeatures ret = NoRoutingFeatures;
+ if (d_ptr->metaData.contains(QStringLiteral("Features"))
+ && d_ptr->metaData.value(QStringLiteral("Features")).isArray()) {
+ QJsonArray features = d_ptr->metaData.value(QStringLiteral("Features")).toArray();
+ foreach (QJsonValue v, features) {
+ int val = en.keyToValue(v.toString().toAscii().constData());
+ if (v.isString() && val != -1) {
+ ret |= RoutingFeature(val);
+ }
+ }
+ }
+
+ return ret;
+}
+
+QGeoServiceProvider::GeocodingFeatures QGeoServiceProvider::geocodingFeatures() const
+{
+ const QMetaObject *mo = QGeoServiceProvider::metaObject();
+ const QMetaEnum en = mo->enumerator(
+ mo->indexOfEnumerator("GeocodingFeatures"));
+
+ GeocodingFeatures ret = NoGeocodingFeatures;
+ if (d_ptr->metaData.contains(QStringLiteral("Features"))
+ && d_ptr->metaData.value(QStringLiteral("Features")).isArray()) {
+ QJsonArray features = d_ptr->metaData.value(QStringLiteral("Features")).toArray();
+ foreach (QJsonValue v, features) {
+ int val = en.keyToValue(v.toString().toAscii().constData());
+ if (v.isString() && val != -1) {
+ ret |= GeocodingFeature(val);
+ }
+ }
+ }
+
+ return ret;
+}
+
+QGeoServiceProvider::MappingFeatures QGeoServiceProvider::mappingFeatures() const
+{
+ const QMetaObject *mo = QGeoServiceProvider::metaObject();
+ const QMetaEnum en = mo->enumerator(
+ mo->indexOfEnumerator("MappingFeatures"));
+
+ MappingFeatures ret = NoMappingFeatures;
+ if (d_ptr->metaData.contains(QStringLiteral("Features"))
+ && d_ptr->metaData.value(QStringLiteral("Features")).isArray()) {
+ QJsonArray features = d_ptr->metaData.value(QStringLiteral("Features")).toArray();
+ foreach (QJsonValue v, features) {
+ int val = en.keyToValue(v.toString().toAscii().constData());
+ if (v.isString() && val != -1) {
+ ret |= MappingFeature(val);
+ }
+ }
+ }
+
+ return ret;
+}
+
+QGeoServiceProvider::PlacesFeatures QGeoServiceProvider::placesFeatures() const
+{
+ const QMetaObject *mo = QGeoServiceProvider::metaObject();
+ const QMetaEnum en = mo->enumerator(
+ mo->indexOfEnumerator("PlacesFeatures"));
+
+ PlacesFeatures ret = NoPlacesFeatures;
+ if (d_ptr->metaData.contains(QStringLiteral("Features"))
+ && d_ptr->metaData.value(QStringLiteral("Features")).isArray()) {
+ QJsonArray features = d_ptr->metaData.value(QStringLiteral("Features")).toArray();
+ foreach (QJsonValue v, features) {
+ int val = en.keyToValue(v.toString().toAscii().constData());
+ if (v.isString() && val != -1) {
+ ret |= PlacesFeature(val);
+ }
+ }
+ }
+
+ return ret;
+}
+
/*!
Returns the QGeocodingManager made available by the service
provider.
@@ -182,7 +272,10 @@ QGeoServiceProvider::~QGeoServiceProvider()
*/
QGeocodingManager* QGeoServiceProvider::geocodingManager() const
{
- if (!d_ptr->factory || (d_ptr->geocodeError != QGeoServiceProvider::NoError))
+ if (!d_ptr->factory)
+ d_ptr->loadPlugin(d_ptr->parameterMap);
+
+ if (!d_ptr->factory || d_ptr->geocodeError != QGeoServiceProvider::NoError)
return 0;
if (!d_ptr->geocodingManager) {
@@ -190,8 +283,10 @@ QGeocodingManager* QGeoServiceProvider::geocodingManager() const
&(d_ptr->geocodeError),
&(d_ptr->geocodeErrorString));
if (engine) {
- engine->setManagerName(d_ptr->factory->providerName());
- engine->setManagerVersion(d_ptr->factory->providerVersion());
+ engine->setManagerName(
+ d_ptr->metaData.value(QStringLiteral("Provider")).toString());
+ engine->setManagerVersion(
+ int(d_ptr->metaData.value(QStringLiteral("Version")).toDouble()));
d_ptr->geocodingManager = new QGeocodingManager(engine);
} else {
d_ptr->geocodeError = QGeoServiceProvider::NotSupportedError;
@@ -205,6 +300,9 @@ QGeocodingManager* QGeoServiceProvider::geocodingManager() const
d_ptr->error = d_ptr->geocodeError;
d_ptr->errorString = d_ptr->geocodeErrorString;
}
+
+ if (d_ptr->geocodingManager && d_ptr->localeSet)
+ d_ptr->geocodingManager->setLocale(d_ptr->locale);
}
if (d_ptr->geocodingManager) {
@@ -237,6 +335,9 @@ QGeocodingManager* QGeoServiceProvider::geocodingManager() const
*/
QGeoMappingManager* QGeoServiceProvider::mappingManager() const
{
+ if (!d_ptr->factory)
+ d_ptr->loadPlugin(d_ptr->parameterMap);
+
if (!d_ptr->factory || (d_ptr->mappingError != QGeoServiceProvider::NoError))
return 0;
@@ -246,8 +347,10 @@ QGeoMappingManager* QGeoServiceProvider::mappingManager() const
&(d_ptr->mappingErrorString));
if (engine) {
- engine->setManagerName(d_ptr->factory->providerName());
- engine->setManagerVersion(d_ptr->factory->providerVersion());
+ engine->setManagerName(
+ d_ptr->metaData.value(QStringLiteral("Provider")).toString());
+ engine->setManagerVersion(
+ int(d_ptr->metaData.value(QStringLiteral("Version")).toDouble()));
d_ptr->mappingManager = new QGeoMappingManager(engine);
} else {
d_ptr->mappingError = QGeoServiceProvider::NotSupportedError;
@@ -261,6 +364,9 @@ QGeoMappingManager* QGeoServiceProvider::mappingManager() const
d_ptr->error = d_ptr->mappingError;
d_ptr->errorString = d_ptr->mappingErrorString;
}
+
+ if (d_ptr->mappingManager && d_ptr->localeSet)
+ d_ptr->mappingManager->setLocale(d_ptr->locale);
}
if (d_ptr->mappingManager) {
@@ -293,6 +399,9 @@ QGeoMappingManager* QGeoServiceProvider::mappingManager() const
*/
QGeoRoutingManager* QGeoServiceProvider::routingManager() const
{
+ if (!d_ptr->factory)
+ d_ptr->loadPlugin(d_ptr->parameterMap);
+
if (!d_ptr->factory || (d_ptr->routingError != QGeoServiceProvider::NoError))
return 0;
@@ -302,8 +411,10 @@ QGeoRoutingManager* QGeoServiceProvider::routingManager() const
&(d_ptr->routingErrorString));
if (engine) {
- engine->setManagerName(d_ptr->factory->providerName());
- engine->setManagerVersion(d_ptr->factory->providerVersion());
+ engine->setManagerName(
+ d_ptr->metaData.value(QStringLiteral("Provider")).toString());
+ engine->setManagerVersion(
+ int(d_ptr->metaData.value(QStringLiteral("Version")).toDouble()));
d_ptr->routingManager = new QGeoRoutingManager(engine);
} else {
d_ptr->routingError = QGeoServiceProvider::NotSupportedError;
@@ -317,6 +428,9 @@ QGeoRoutingManager* QGeoServiceProvider::routingManager() const
d_ptr->error = d_ptr->routingError;
d_ptr->errorString = d_ptr->routingErrorString;
}
+
+ if (d_ptr->routingManager && d_ptr->localeSet)
+ d_ptr->routingManager->setLocale(d_ptr->locale);
}
if (d_ptr->routingManager) {
@@ -348,6 +462,9 @@ QGeoRoutingManager* QGeoServiceProvider::routingManager() const
*/
QPlaceManager *QGeoServiceProvider::placeManager() const
{
+ if (!d_ptr->factory)
+ d_ptr->loadPlugin(d_ptr->parameterMap);
+
if (!d_ptr->factory || (d_ptr->placeError != QGeoServiceProvider::NoError))
return 0;
@@ -357,8 +474,10 @@ QPlaceManager *QGeoServiceProvider::placeManager() const
&(d_ptr->placeErrorString));
if (engine) {
- engine->setManagerName(d_ptr->factory->providerName());
- engine->setManagerVersion(d_ptr->factory->providerVersion());
+ engine->setManagerName(
+ d_ptr->metaData.value(QStringLiteral("Provider")).toString());
+ engine->setManagerVersion(
+ int(d_ptr->metaData.value(QStringLiteral("Version")).toDouble()));
d_ptr->placeManager = new QPlaceManager(engine);
engine->d_ptr->manager = d_ptr->placeManager;
@@ -374,6 +493,9 @@ QPlaceManager *QGeoServiceProvider::placeManager() const
d_ptr->error = d_ptr->placeError;
d_ptr->errorString = d_ptr->placeErrorString;
}
+
+ if (d_ptr->placeManager && d_ptr->localeSet)
+ d_ptr->placeManager->setLocale(d_ptr->locale);
}
if (d_ptr->placeManager) {
@@ -402,11 +524,62 @@ QString QGeoServiceProvider::errorString() const
return d_ptr->errorString;
}
+/*!
+ Sets whether experimental plugins are considered when locating the
+ correct plugin library for this service provider.
+
+ \bold{Important:} this will destroy any existing managers held by this
+ service provider instance. You should be sure not to attempt to use any
+ pointers that you have previously retrieved after calling this method.
+*/
+void QGeoServiceProvider::setAllowExperimental(bool allow)
+{
+ d_ptr->experimental = allow;
+ d_ptr->unload();
+ d_ptr->loadMeta();
+}
+
+/*!
+ Sets the parameters used to construct individual manager classes for
+ this service provider.
+
+ \bold{Important:} this will destroy any existing managers held by this
+ service provider instance. You should be sure not to attempt to use any
+ pointers that you have previously retrieved after calling this method.
+*/
+void QGeoServiceProvider::setParameters(const QMap<QString, QVariant> &parameters)
+{
+ d_ptr->parameterMap = parameters;
+ d_ptr->unload();
+ d_ptr->loadMeta();
+}
+
+/*!
+ Sets the locale used by this service provider. If the relevant features
+ (see LocalizedMappingFeature etc), this will change the languages, units
+ and other locale-specific attributes of the provider's data.
+*/
+void QGeoServiceProvider::setLocale(const QLocale &locale)
+{
+ d_ptr->locale = locale;
+ d_ptr->localeSet = true;
+
+ if (d_ptr->geocodingManager)
+ d_ptr->geocodingManager->setLocale(locale);
+ if (d_ptr->routingManager)
+ d_ptr->routingManager->setLocale(locale);
+ if (d_ptr->mappingManager)
+ d_ptr->mappingManager->setLocale(locale);
+ if (d_ptr->placeManager)
+ d_ptr->placeManager->setLocale(locale);
+}
+
/*******************************************************************************
*******************************************************************************/
QGeoServiceProviderPrivate::QGeoServiceProviderPrivate()
: factory(0),
+ experimental(false),
geocodingManager(0),
routingManager(0),
mappingManager(0),
@@ -415,7 +588,11 @@ QGeoServiceProviderPrivate::QGeoServiceProviderPrivate()
routingError(QGeoServiceProvider::NoError),
mappingError(QGeoServiceProvider::NoError),
placeError(QGeoServiceProvider::NoError),
- error(QGeoServiceProvider::NoError) {}
+ error(QGeoServiceProvider::NoError),
+ localeSet(false)
+{
+ metaData.insert(QStringLiteral("index"), -1);
+}
QGeoServiceProviderPrivate::~QGeoServiceProviderPrivate()
{
@@ -432,93 +609,117 @@ QGeoServiceProviderPrivate::~QGeoServiceProviderPrivate()
delete placeManager;
}
-void QGeoServiceProviderPrivate::loadPlugin(const QString &providerName, const QMap<QString, QVariant> &parameters)
+void QGeoServiceProviderPrivate::unload()
{
- Q_UNUSED(parameters)
+ if (geocodingManager) {
+ delete geocodingManager;
+ geocodingManager = 0;
+ }
- if (!QGeoServiceProviderPrivate::plugins().keys().contains(providerName)) {
- error = QGeoServiceProvider::NotSupportedError;
- errorString = QString(QLatin1String("The geoservices provider %1 is not supported.")).arg(providerName);
- factory = 0;
- return;
+ if (routingManager) {
+ delete routingManager;
+ routingManager = 0;
}
- factory = 0;
+ if (mappingManager) {
+ delete mappingManager;
+ mappingManager = 0;
+ }
+ if (placeManager) {
+ delete placeManager;
+ placeManager = 0;
+ }
+
+ factory = 0;
error = QGeoServiceProvider::NoError;
errorString = QLatin1String("");
+ metaData = QJsonObject();
+ metaData.insert(QStringLiteral("index"), -1);
+}
- QList<QGeoServiceProviderFactory*> candidates = QGeoServiceProviderPrivate::plugins().values(providerName);
+void QGeoServiceProviderPrivate::loadMeta()
+{
+ factory = 0;
+ metaData = QJsonObject();
+ metaData.insert(QStringLiteral("index"), -1);
+ error = QGeoServiceProvider::NotSupportedError;
+ errorString = QString(QLatin1String("The geoservices provider %1 is not supported.")).arg(providerName);
+
+ QList<QJsonObject> candidates = QGeoServiceProviderPrivate::plugins().values(providerName);
int versionFound = -1;
+ int idx = -1;
+ // figure out which version of the plugin we want
+ // (always latest unless experimental)
for (int i = 0; i < candidates.size(); ++i) {
- QGeoServiceProviderFactory* f = candidates[i];
- if (f && (f->providerVersion() > versionFound)) {
- versionFound = f->providerVersion();
- factory = f;
+ QJsonObject meta = candidates[i];
+ if (meta.contains(QStringLiteral("Version"))
+ && meta.value(QStringLiteral("Version")).isDouble()
+ && meta.contains(QStringLiteral("Experimental"))
+ && meta.value(QStringLiteral("Experimental")).isBool()) {
+ int ver = int(meta.value(QStringLiteral("Version")).toDouble());
+ if (ver > versionFound && !(!experimental && meta.value(QStringLiteral("Experimental")).toBool())) {
+ versionFound = ver;
+ idx = i;
+ }
}
}
+
+ if (idx != -1) {
+ error = QGeoServiceProvider::NoError;
+ errorString = QStringLiteral("");
+ metaData = candidates[idx];
+ }
}
-QHash<QString, QGeoServiceProviderFactory*> QGeoServiceProviderPrivate::plugins(bool reload)
+void QGeoServiceProviderPrivate::loadPlugin(const QMap<QString, QVariant> &parameters)
{
- static QHash<QString, QGeoServiceProviderFactory*> plugins;
+ Q_UNUSED(parameters)
+
+ if (int(metaData.value(QStringLiteral("index")).toDouble()) < 0) {
+ error = QGeoServiceProvider::NotSupportedError;
+ errorString = QString(QLatin1String("The geoservices provider is not supported."));
+ factory = 0;
+ return;
+ }
+
+ error = QGeoServiceProvider::NoError;
+ errorString = QLatin1String("");
+
+ int idx = int(metaData.value(QStringLiteral("index")).toDouble());
+
+ // load the actual plugin (BWAHAHA)
+ factory = qobject_cast<QGeoServiceProviderFactory*>(loader()->instance(idx));
+}
+
+QHash<QString, QJsonObject> QGeoServiceProviderPrivate::plugins(bool reload)
+{
+ static QHash<QString, QJsonObject> plugins;
static bool alreadyDiscovered = false;
if (reload == true)
alreadyDiscovered = false;
if (!alreadyDiscovered) {
- loadStaticPlugins(&plugins);
- loadDynamicPlugins(&plugins);
+ loadPluginMetadata(plugins);
alreadyDiscovered = true;
}
return plugins;
}
-void QGeoServiceProviderPrivate::loadDynamicPlugins(QHash<QString, QGeoServiceProviderFactory*> *plugins)
+void QGeoServiceProviderPrivate::loadPluginMetadata(QHash<QString, QJsonObject> &list)
{
QFactoryLoader *l = loader();
- QString key;
- for (int i = 0; i < l->keys().count(); i++) {
- key = l->keys().at(i);
- QGeoServiceProviderFactory *f = qobject_cast<QGeoServiceProviderFactory*>(l->instance(key));
- if (f) {
- const QString name = f->providerName();
-#if !defined QT_NO_DEBUG
- const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
- if (showDebug)
- qDebug() << "Dynamic: found a service provider plugin with name" << name;
-#endif
- plugins->insertMulti(name, f);
- }
+ QList<QJsonObject> meta = l->metaData();
+ for (int i = 0; i < meta.size(); i++) {
+ QJsonObject obj = meta.at(i).value(QStringLiteral("MetaData")).toObject();
+ obj.insert(QStringLiteral("index"), i);
+ list.insertMulti(obj.value(QStringLiteral("Provider")).toString(), obj);
}
}
-void QGeoServiceProviderPrivate::loadStaticPlugins(QHash<QString, QGeoServiceProviderFactory*> *plugins)
-{
-#if !defined QT_NO_DEBUG
- const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
-#endif
-
- QObjectList staticPlugins = QPluginLoader::staticInstances();
- for (int i = 0; i < staticPlugins.count(); ++i) {
- QGeoServiceProviderFactory *f = qobject_cast<QGeoServiceProviderFactory*>(staticPlugins.at(i));
- if (f) {
- QString name = f->providerName();
-
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "Static: found a service provider plugin with name" << name;
-#endif
- if (!name.isEmpty()) {
- plugins->insertMulti(name, f);
- }
- }
-
- }
-}
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoserviceprovider.h b/src/location/maps/qgeoserviceprovider.h
index 6f8eb9b6..6d5a0281 100644
--- a/src/location/maps/qgeoserviceprovider.h
+++ b/src/location/maps/qgeoserviceprovider.h
@@ -45,6 +45,7 @@
#include <QMap>
#include <QVariant>
#include <QString>
+#include <QObject>
#include <QtLocation/qlocationglobal.h>
@@ -52,8 +53,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-
-
+class QLocale;
class QStringList;
class QGeocodingManager;
class QGeoMappingManager;
@@ -65,8 +65,10 @@ class QGeoRoutingManagerEngine;
class QPlaceManagerEngine;
class QGeoServiceProviderPrivate;
-class Q_LOCATION_EXPORT QGeoServiceProvider
+class Q_LOCATION_EXPORT QGeoServiceProvider : public QObject
{
+ Q_OBJECT
+
public:
enum Error {
NoError,
@@ -76,12 +78,75 @@ public:
ConnectionError
};
+ enum RoutingFeature {
+ NoRoutingFeatures = 0,
+ OnlineRoutingFeature = (1<<0),
+ OfflineRoutingFeature = (1<<1),
+ LocalizedRoutingFeature = (1<<2),
+ RouteUpdatesFeature = (1<<3),
+ AlternativeRoutesFeature = (1<<4),
+ ExcludeAreasRoutingFeature = (1<<5),
+ AnyRoutingFeatures = ~(0)
+ };
+
+ enum GeocodingFeature {
+ NoGeocodingFeatures = 0,
+ OnlineGeocodingFeature = (1<<0),
+ OfflineGeocodingFeature = (1<<1),
+ ReverseGeocodingFeature = (1<<2),
+ LocalizedGeocodingFeature = (1<<3),
+ AnyGeocodingFeatures = ~(0)
+ };
+
+ enum MappingFeature {
+ NoMappingFeatures = 0,
+ OnlineMappingFeature = (1<<0),
+ OfflineMappingFeature = (1<<1),
+ LocalizedMappingFeature = (1<<2),
+ AnyMappingFeatures = ~(0)
+ };
+
+ enum PlacesFeature {
+ NoPlacesFeatures = 0,
+ OnlinePlacesFeature = (1<<0),
+ OfflinePlacesFeature = (1<<1),
+ SavePlaceFeature = (1<<2),
+ RemovePlaceFeature = (1<<3),
+ SaveCategoryFeature = (1<<4),
+ RemoveCategoryFeature = (1<<5),
+ PlaceRecommendationsFeature = (1<<6),
+ SearchSuggestionsFeature = (1<<7),
+ CorrectionsFeature = (1<<8),
+ LocalizedPlacesFeature = (1<<9),
+ NotificationsFeature = (1<<10),
+ PlaceMatchingFeature = (1<<11),
+ AnyPlacesFeatures = ~(0)
+ };
+
+ Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature)
+ Q_FLAGS(RoutingFeatures)
+
+ Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature)
+ Q_FLAGS(GeocodingFeatures)
+
+ Q_DECLARE_FLAGS(MappingFeatures, MappingFeature)
+ Q_FLAGS(MappingFeatures)
+
+ Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature)
+ Q_FLAGS(PlacesFeatures)
+
static QStringList availableServiceProviders();
QGeoServiceProvider(const QString &providerName,
- const QMap<QString,QVariant> &parameters = (QMap<QString,QVariant>()));
+ const QMap<QString,QVariant> &parameters = (QMap<QString,QVariant>()),
+ bool allowExperimental = false);
~QGeoServiceProvider();
+ RoutingFeatures routingFeatures() const;
+ GeocodingFeatures geocodingFeatures() const;
+ MappingFeatures mappingFeatures() const;
+ PlacesFeatures placesFeatures() const;
+
QGeocodingManager* geocodingManager() const;
QGeoMappingManager* mappingManager() const;
QGeoRoutingManager* routingManager() const;
@@ -90,6 +155,10 @@ public:
Error error() const;
QString errorString() const;
+ void setParameters(const QMap<QString, QVariant> &parameters);
+ void setLocale(const QLocale &locale);
+ void setAllowExperimental(bool allow);
+
private:
QGeoServiceProviderPrivate* d_ptr;
};
diff --git a/src/location/maps/qgeoserviceprovider_p.h b/src/location/maps/qgeoserviceprovider_p.h
index 812e7948..191f3517 100644
--- a/src/location/maps/qgeoserviceprovider_p.h
+++ b/src/location/maps/qgeoserviceprovider_p.h
@@ -56,6 +56,9 @@
#include "qgeoserviceprovider.h"
#include <QHash>
+#include <QJsonObject>
+#include <QJsonArray>
+#include <QLocale>
QT_BEGIN_NAMESPACE
@@ -71,12 +74,16 @@ public:
QGeoServiceProviderPrivate();
~QGeoServiceProviderPrivate();
- void loadPlugin(const QString &providerName, const QMap<QString, QVariant> &parameters);
-
+ void loadMeta();
+ void loadPlugin(const QMap<QString, QVariant> &parameters);
+ void unload();
QGeoServiceProviderFactory *factory;
+ QJsonObject metaData;
QMap<QString, QVariant> parameterMap;
+ bool experimental;
+
QGeocodingManager *geocodingManager;
QGeoRoutingManager *routingManager;
QGeoMappingManager *mappingManager;
@@ -95,9 +102,13 @@ public:
QGeoServiceProvider::Error error;
QString errorString;
- static QHash<QString, QGeoServiceProviderFactory*> plugins(bool reload = false);
- static void loadDynamicPlugins(QHash<QString, QGeoServiceProviderFactory*> *plugins);
- static void loadStaticPlugins(QHash<QString, QGeoServiceProviderFactory*> *plugins);
+ QString providerName;
+
+ QLocale locale;
+ bool localeSet;
+
+ static QHash<QString, QJsonObject> plugins(bool reload = false);
+ static void loadPluginMetadata(QHash<QString, QJsonObject> &list);
};
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeoserviceproviderfactory.cpp b/src/location/maps/qgeoserviceproviderfactory.cpp
index 170ff77c..6761d762 100644
--- a/src/location/maps/qgeoserviceproviderfactory.cpp
+++ b/src/location/maps/qgeoserviceproviderfactory.cpp
@@ -65,25 +65,6 @@ QT_BEGIN_NAMESPACE
Destroys this QGeoServiceProviderFactory instance.
*/
-
-/*!
-\fn QString QGeoServiceProviderFactory::providerName() const
-
-Returns the string used to identify the service provider behind this implementation.
-
-The combination of providerName() and providerVersion() should be unique
-amongst the plugins.
-*/
-
-/*!
-\fn int QGeoServiceProviderFactory::providerVersion() const
-
-Returns the version of the plugin.
-
-The combination of providerName() and providerVersion() should be unique
-amongst the plugins.
-*/
-
/*!
Returns a new QGeocodingManagerEngine instance, initialized with \a
parameters, which implements the location geocoding functionality.
diff --git a/src/location/maps/qgeoserviceproviderfactory.h b/src/location/maps/qgeoserviceproviderfactory.h
index 362349e2..7e93d0b4 100644
--- a/src/location/maps/qgeoserviceproviderfactory.h
+++ b/src/location/maps/qgeoserviceproviderfactory.h
@@ -47,22 +47,16 @@
#include <QtPlugin>
#include <QMap>
#include <QString>
-#include <QFactoryInterface>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-
-
-class Q_LOCATION_EXPORT QGeoServiceProviderFactory : public QFactoryInterface
+class Q_LOCATION_EXPORT QGeoServiceProviderFactory
{
public:
virtual ~QGeoServiceProviderFactory() {}
- virtual QString providerName() const = 0;
- virtual int providerVersion() const = 0;
-
virtual QGeocodingManagerEngine* createGeocodingManagerEngine(const QMap<QString, QVariant> &parameters,
QGeoServiceProvider::Error *error,
QString *errorString) const;
@@ -77,8 +71,8 @@ public:
QString *errorString) const;
};
-#define QT_GEOSERVICE_BACKEND_INTERFACE "com.nokia.qt.geoservice.serviceproviderfactory/1.0"
-Q_DECLARE_INTERFACE(QGeoServiceProviderFactory, QT_GEOSERVICE_BACKEND_INTERFACE);
+Q_DECLARE_INTERFACE(QGeoServiceProviderFactory,
+ "org.qt-project.qt.geoservice.serviceproviderfactory/5.0");
QT_END_NAMESPACE