diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-03-08 16:10:48 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-03-14 11:10:48 +0000 |
commit | f93c464f7b0f2b3223a4d17cb52f6b5f4a6b0002 (patch) | |
tree | 1ad5f7b0a41d2195702ff470906d32dd82742c2d /src | |
parent | d7df0fa2952e3a00032ff50b0dc10ad93be57f54 (diff) | |
download | qtlocation-f93c464f7b0f2b3223a4d17cb52f6b5f4a6b0002.tar.gz |
API Fix: Expose Waypoint metadata and RouteQuery extraParameters
Both RouteQuery and Waypoint are currently intended to be a one-way
interface to push data into a route request.
With the upcoming navigation support, there is need for these to become
also a way to report to the user updated request info.
This patch fixes the problem by adding two read only qml properties,
a Waypoint.metadata, that can also be used to read all of what is
being set via Map Parameters, and a RouteQuery.extraParameters,
intended to be used in the same way.
Change-Id: I65e484d96d50e89f44271781cb21e58dfe7badf8
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeoroutemodel.cpp | 49 | ||||
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeoroutemodel_p.h | 5 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp index 0a95ddf9..add53854 100644 --- a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp @@ -752,6 +752,21 @@ QDeclarativeGeoRouteQuery::QDeclarativeGeoRouteQuery(QObject *parent) { } +QDeclarativeGeoRouteQuery::QDeclarativeGeoRouteQuery(const QGeoRouteRequest &request, QObject *parent) +: QObject(parent), request_(request), complete_(false), m_excludedAreaCoordinateChanged(false) +{ + // Extra params assumed to be already set in the request. + // Init waypoints + const QList<QGeoCoordinate> wpts = request_.waypoints(); + const QList<QVariantMap> meta = request_.waypointsMetadata(); + for (int i = 0; i < wpts.size(); ++i) { + QDeclarativeGeoWaypoint *w = new QDeclarativeGeoWaypoint(this); + w->setCoordinate(wpts.at(i)); + w->setMetadata(meta.at(i)); + m_waypoints << w; + } +} + QDeclarativeGeoRouteQuery::~QDeclarativeGeoRouteQuery() { } @@ -1456,6 +1471,21 @@ QGeoRouteRequest QDeclarativeGeoRouteQuery::routeRequest() return request_; } + +/*! + \qmlproperty VariantMap extraParameters + + The route query extra parameters. This property is read only. If the query is + defined by the user, these can be set by using MapParameters. + If the route query comes from the engine via signals, the query is intended to be read-only. + + \since 5.11 +*/ +QVariantMap QDeclarativeGeoRouteQuery::extraParameters() +{ + return routeRequest().extraParameters(); +} + void QDeclarativeGeoRouteQuery::excludedAreaCoordinateChanged() { if (!m_excludedAreaCoordinateChanged) { @@ -1771,6 +1801,16 @@ void QDeclarativeGeoWaypoint::setBearing(qreal bearing) } } +/*! + \qmlproperty VariantMap metadata + + The waypoint metadata. This property is read only. If the waypoint is + defined by the user, these can be set by using MapParameters. + If the waypoint comes from the engine via signals, or as part of a read-only route query, + the waypoint is intended to be read-only. + + \since 5.11 +*/ QVariantMap QDeclarativeGeoWaypoint::metadata() { if (m_metadataChanged) { @@ -1787,6 +1827,15 @@ QVariantMap QDeclarativeGeoWaypoint::metadata() return m_metadata; } +// Used only by QDeclarativeGeoRouteRequest +void QDeclarativeGeoWaypoint::setMetadata(const QVariantMap &meta) +{ + m_metadata = meta; + if (m_metadata.contains(QStringLiteral("bearing")) && m_metadata.value(QStringLiteral("bearing")).canConvert<double>()) + m_bearing = m_metadata.value(QStringLiteral("bearing")).toDouble(); + m_metadataChanged = false; +} + void QDeclarativeGeoWaypoint::extraParameterChanged() { m_metadataChanged = true; diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h index 5d8d1803..b8c2e84d 100644 --- a/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h +++ b/src/location/declarativemaps/qdeclarativegeoroutemodel_p.h @@ -200,6 +200,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoWaypoint : public QGeoCoordinateO Q_PROPERTY(bool isValid READ isValid STORED false) Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged) + Q_PROPERTY(QVariantMap metadata READ metadata) Q_PROPERTY(QQmlListProperty<QObject> quickChildren READ declarativeChildren DESIGNABLE false) Q_CLASSINFO("DefaultProperty", "quickChildren") @@ -236,6 +237,7 @@ public: } QVariantMap metadata(); + void setMetadata(const QVariantMap &meta); Q_SIGNALS: void completed(); @@ -292,6 +294,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoRouteQuery : public QObject, publ Q_PROPERTY(QVariantList waypoints READ waypoints WRITE setWaypoints NOTIFY waypointsChanged) Q_PROPERTY(QJSValue excludedAreas READ excludedAreas WRITE setExcludedAreas NOTIFY excludedAreasChanged) Q_PROPERTY(QList<int> featureTypes READ featureTypes NOTIFY featureTypesChanged) + Q_PROPERTY(QVariantMap extraParameters READ extraParameters) Q_PROPERTY(QQmlListProperty<QObject> quickChildren READ declarativeChildren DESIGNABLE false) Q_CLASSINFO("DefaultProperty", "quickChildren") Q_INTERFACES(QQmlParserStatus) @@ -299,6 +302,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoRouteQuery : public QObject, publ public: explicit QDeclarativeGeoRouteQuery(QObject *parent = 0); + QDeclarativeGeoRouteQuery(const QGeoRouteRequest &request, QObject *parent = 0); // init from request. For instances intended to be read only ~QDeclarativeGeoRouteQuery(); // From QQmlParserStatus @@ -306,6 +310,7 @@ public: void componentComplete(); QGeoRouteRequest routeRequest(); + QVariantMap extraParameters(); enum TravelMode { CarTravel = QGeoRouteRequest::CarTravel, |