diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-11-28 19:38:10 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-12-04 16:11:50 +0000 |
commit | 4919bb49039dd84bd58290fb66e2c272a920929c (patch) | |
tree | 79469376d4b2ec7c86194455f5d32c6c88126a9e /src/plugins/geoservices/osm/qgeocodereplyosm.cpp | |
parent | 9ec2fa87650607337f1692b7bc52e16cc3f74860 (diff) | |
download | qtlocation-4919bb49039dd84bd58290fb66e2c272a920929c.tar.gz |
Provide extended, plugin dependent information for Geo Locations
This includes support for osm geojson and class fields.
At the present, the content of the geojson field is returned
as is.
As soon as QGeoJson support is finalized, this will be
integrated with a QGeoPolygon.
Fixes: QTBUG-43401
Change-Id: Ifa7e24cf904a2c1e1e77ebfaa7948ac0ce81d265
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins/geoservices/osm/qgeocodereplyosm.cpp')
-rw-r--r-- | src/plugins/geoservices/osm/qgeocodereplyosm.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp index 11bdaa6c..0bdf4bf9 100644 --- a/src/plugins/geoservices/osm/qgeocodereplyosm.cpp +++ b/src/plugins/geoservices/osm/qgeocodereplyosm.cpp @@ -49,8 +49,8 @@ QT_BEGIN_NAMESPACE -QGeoCodeReplyOsm::QGeoCodeReplyOsm(QNetworkReply *reply, QObject *parent) -: QGeoCodeReply(*new QGeoCodeReplyOsmPrivate, parent) +QGeoCodeReplyOsm::QGeoCodeReplyOsm(QNetworkReply *reply, bool includeExtraData, QObject *parent) +: QGeoCodeReply(*new QGeoCodeReplyOsmPrivate, parent), m_includeExtraData(includeExtraData) { if (!reply) { setError(UnknownError, QStringLiteral("Null reply")); @@ -98,6 +98,20 @@ static QGeoAddress parseAddressObject(const QJsonObject &object) return address; } +static void injectExtra(QGeoLocation &location, const QJsonObject &object) +{ + QVariantMap extra; + static const QList<QString> extraKeys = { QStringLiteral("geojson"), + QStringLiteral("class") }; + + for (const auto k: extraKeys) { + if (object.contains(k)) + extra[k] = object.value(k).toVariant(); + } + + location.setExtendedAttributes(extra); +} + void QGeoCodeReplyOsm::networkReplyFinished() { QNetworkReply *reply = static_cast<QNetworkReply *>(sender()); @@ -121,6 +135,8 @@ void QGeoCodeReplyOsm::networkReplyFinished() location.setCoordinate(coordinate); location.setAddress(parseAddressObject(object)); + if (m_includeExtraData) + injectExtra(location, object); locations.append(location); setLocations(locations); @@ -154,6 +170,8 @@ void QGeoCodeReplyOsm::networkReplyFinished() location.setCoordinate(coordinate); location.setBoundingBox(rectangle); location.setAddress(parseAddressObject(object)); + if (m_includeExtraData) + injectExtra(location, object); locations.append(location); } |