summaryrefslogtreecommitdiff
path: root/src/plugins/geoservices
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/plugins/geoservices
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/plugins/geoservices')
-rw-r--r--src/plugins/geoservices/mapbox/qgeoroutereplymapbox.cpp58
1 files changed, 56 insertions, 2 deletions
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 {