summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-03-27 14:18:44 +0300
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-03-28 11:40:58 +0000
commit27837cdf26a2f7d83f57f55a1a4e7ce947479592 (patch)
tree8a54947c50714bdcc018f249970d92e7dece2fc0 /src
parentbda6fa9d1f67525e741b45362c58ac4f1a780624 (diff)
downloadqtlocation-27837cdf26a2f7d83f57f55a1a4e7ce947479592.tar.gz
Implement QGeoRoute{,Private}Mapbox
Adds QGeoRoutePrivate::metadata(), which provides a QVariantMap containing route plugin-specific data, that could be privately used by other plugins. Taking Mapbox routes as example, we want to expose the route JSON server reply, so we've added QGeoRouteMapbox for that purpose. Change-Id: I6823ed4623b05a0e678b73676b2361cf74823ddb Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/location/maps/qgeoroute.cpp9
-rw-r--r--src/location/maps/qgeoroute_p.h2
-rw-r--r--src/plugins/geoservices/mapbox/qgeoroutereplymapbox.cpp58
3 files changed, 66 insertions, 3 deletions
diff --git a/src/location/maps/qgeoroute.cpp b/src/location/maps/qgeoroute.cpp
index 12ac16bd..979c1667 100644
--- a/src/location/maps/qgeoroute.cpp
+++ b/src/location/maps/qgeoroute.cpp
@@ -41,6 +41,7 @@
#include "qgeoroutesegment.h"
#include <QDateTime>
+#include <QVariantMap>
QT_BEGIN_NAMESPACE
@@ -339,7 +340,8 @@ bool QGeoRoutePrivate::equals(const QGeoRoutePrivate &other) const
&& (travelTime() == other.travelTime())
&& (distance() == other.distance())
&& (travelMode() == other.travelMode())
- && (path() == other.path()));
+ && (path() == other.path()))
+ && (metadata() == other.metadata());
}
void QGeoRoutePrivate::setId(const QString &id)
@@ -427,6 +429,11 @@ const QGeoRoutePrivate *QGeoRoutePrivate::routePrivateData(const QGeoRoute &rout
return route.d_ptr.data();
}
+QVariantMap QGeoRoutePrivate::metadata() const
+{
+ return QVariantMap();
+}
+
/*******************************************************************************
*******************************************************************************/
diff --git a/src/location/maps/qgeoroute_p.h b/src/location/maps/qgeoroute_p.h
index d56b2d44..384802ee 100644
--- a/src/location/maps/qgeoroute_p.h
+++ b/src/location/maps/qgeoroute_p.h
@@ -94,6 +94,8 @@ public:
virtual void setFirstSegment(const QGeoRouteSegment &firstSegment);
virtual QGeoRouteSegment firstSegment() const;
+ virtual QVariantMap metadata() const;
+
virtual QString engineName() const = 0;
virtual int segmentsCount() const = 0;
diff --git a/src/plugins/geoservices/mapbox/qgeoroutereplymapbox.cpp b/src/plugins/geoservices/mapbox/qgeoroutereplymapbox.cpp
index 43b18454..c5f9d38c 100644
--- a/src/plugins/geoservices/mapbox/qgeoroutereplymapbox.cpp
+++ b/src/plugins/geoservices/mapbox/qgeoroutereplymapbox.cpp
@@ -41,12 +41,55 @@
#include "qgeoroutereplymapbox.h"
#include "qgeoroutingmanagerenginemapbox.h"
#include <QtLocation/private/qgeorouteparser_p.h>
+#include <QtLocation/private/qgeoroute_p.h>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QJsonArray>
#include <QtLocation/QGeoRouteSegment>
#include <QtLocation/QGeoManeuver>
+namespace {
+
+class QGeoRouteMapbox : public QGeoRoute
+{
+public:
+ QGeoRouteMapbox(const QGeoRoute &other, const QVariantMap &metadata);
+};
+
+class QGeoRoutePrivateMapbox : public QGeoRoutePrivateDefault
+{
+public:
+ QGeoRoutePrivateMapbox(const QGeoRoutePrivateDefault &other, const QVariantMap &metadata);
+
+ virtual QString engineName() const override;
+ virtual QVariantMap metadata() const override;
+
+ QVariantMap m_metadata;
+};
+
+QGeoRouteMapbox::QGeoRouteMapbox(const QGeoRoute &other, const QVariantMap &metadata)
+ : QGeoRoute(QExplicitlySharedDataPointer<QGeoRoutePrivateMapbox>(new QGeoRoutePrivateMapbox(*static_cast<const QGeoRoutePrivateDefault *>(QGeoRoutePrivate::routePrivateData(other)), metadata)))
+{
+}
+
+QGeoRoutePrivateMapbox::QGeoRoutePrivateMapbox(const QGeoRoutePrivateDefault &other, const QVariantMap &metadata)
+ : QGeoRoutePrivateDefault(other)
+ , m_metadata(metadata)
+{
+}
+
+QString QGeoRoutePrivateMapbox::engineName() const
+{
+ return QStringLiteral("mapbox");
+}
+
+QVariantMap QGeoRoutePrivateMapbox::metadata() const
+{
+ return m_metadata;
+}
+
+} // namespace
+
QT_BEGIN_NAMESPACE
QGeoRouteReplyMapbox::QGeoRouteReplyMapbox(QNetworkReply *reply, const QGeoRouteRequest &request,
@@ -81,10 +124,21 @@ void QGeoRouteReplyMapbox::networkReplyFinished()
QList<QGeoRoute> routes;
QString errorString;
- QGeoRouteReply::Error error = parser->parseReply(routes, errorString, reply->readAll());
+
+ QByteArray routeReply = reply->readAll();
+ QGeoRouteReply::Error error = parser->parseReply(routes, errorString, routeReply);
+
+ QVariantMap metadata;
+ metadata["osrm.reply-json"] = routeReply;
+
+ QList<QGeoRoute> mapboxRoutes;
+ for (const QGeoRoute &route : routes.mid(0, request().numberAlternativeRoutes() + 1)) {
+ QGeoRouteMapbox mapboxRoute(route, metadata);
+ mapboxRoutes.append(mapboxRoute);
+ }
if (error == QGeoRouteReply::NoError) {
- setRoutes(routes.mid(0, request().numberAlternativeRoutes() + 1));
+ setRoutes(mapboxRoutes);
// setError(QGeoRouteReply::NoError, status); // can't do this, or NoError is emitted and does damages
setFinished(true);
} else {