diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-11-06 14:02:36 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-11-29 23:02:35 +0000 |
commit | 3e107c6d2933b4b924100d1aab18f52f7ca40edc (patch) | |
tree | 20b87cef43353cad503f2cf294f21d4755130691 /src/location/declarativemaps/qdeclarativegeoroutemodel.cpp | |
parent | efcffce97117f571fcf4bf745426eb36ef784804 (diff) | |
download | qtlocation-3e107c6d2933b4b924100d1aab18f52f7ca40edc.tar.gz |
Allow to specify extra parameters in RouteQuery using MapParameters
This patch works on top of the previous one, and passes the content of
the map parameters as a QMap<QString, QVariantMap>, where the key is the
parameter type and the value is a map<property name, property value> of
all properties of the map parameter except for the property "type".
To achieve this, a new list property, quickChildren, has been added to
RouteQuery, to pick up Map Parameters declared inside the query
Change-Id: I364f5438e8f4cfc42430bfe448d96519c407eb74
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeoroutemodel.cpp')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeoroutemodel.cpp | 78 |
1 files changed, 76 insertions, 2 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp index 0383c0c4..488e28ca 100644 --- a/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeoroutemodel.cpp @@ -45,6 +45,7 @@ #include <QtQml/private/qqmlengine_p.h> #include <QtLocation/QGeoRoutingManager> #include <QtPositioning/QGeoRectangle> +#include "qdeclarativegeomapparameter_p.h" QT_BEGIN_NAMESPACE @@ -653,7 +654,7 @@ void QDeclarativeGeoRouteModel::routingError(QGeoRouteReply *reply, \brief The RouteQuery type is used to provide query parameters to a RouteModel. - A RouteQuery contains all the parameters necessary to make a request + A RouteQuery is used to pack all the parameters necessary to make a request to a routing service, which can then populate the contents of a RouteModel. These parameters describe key details of the route, such as \l waypoints to @@ -665,6 +666,10 @@ void QDeclarativeGeoRouteModel::routingError(QGeoRouteReply *reply, RouteModel's \l{RouteModel::query}{query} property, which can then begin the retrieval process to populate the model. + Some plugins might allow or require specific parameters to operate. + In order to specify these plugin-specific parameters, MapParameter elements + can be nested inside a RouteQuery. + \section2 Example Usage The following snipped shows an incomplete example of creating a RouteQuery @@ -1285,8 +1290,17 @@ void QDeclarativeGeoRouteQuery::setRouteOptimizations(QDeclarativeGeoRouteQuery: /*! \internal */ -QGeoRouteRequest QDeclarativeGeoRouteQuery::routeRequest() const +QGeoRouteRequest QDeclarativeGeoRouteQuery::routeRequest() { + if (m_extraParametersChanged) { + m_extraParametersChanged = false; + // Update extra params into request + const QList<QDeclarativeGeoMapParameter *> params = quickChildren<QDeclarativeGeoMapParameter>(); + QMap<QString, QVariantMap> extraParameters; + for (const QDeclarativeGeoMapParameter *p: params) + extraParameters[p->type()] = p->toVariantMap(); + request_.setExtraParameters(extraParameters); + } return request_; } @@ -1298,6 +1312,66 @@ void QDeclarativeGeoRouteQuery::excludedAreaCoordinateChanged() } } +void QDeclarativeGeoRouteQuery::extraParameterChanged() +{ + m_extraParametersChanged = true; + if (complete_) { + emit extraParametersChanged(); + emit queryDetailsChanged(); + } +} + +void QDeclarativeGeoRouteQuery::append(QQmlListProperty<QObject> *p, QObject *v) +{ + QDeclarativeGeoRouteQuery *query = static_cast<QDeclarativeGeoRouteQuery*>(p->object); + query->m_children.append(v); + + QDeclarativeGeoMapParameter *param = qobject_cast<QDeclarativeGeoMapParameter *>(v); + if (param) { + query->m_extraParametersChanged = true; + query->connect(param, &QGeoMapParameter::propertyUpdated, + query, &QDeclarativeGeoRouteQuery::extraParameterChanged); + emit query->extraParametersChanged(); + emit query->queryDetailsChanged(); + } +} + +int QDeclarativeGeoRouteQuery::count(QQmlListProperty<QObject> *p) +{ + return static_cast<QDeclarativeGeoRouteQuery*>(p->object)->m_children.count(); +} + +QObject *QDeclarativeGeoRouteQuery::at(QQmlListProperty<QObject> *p, int idx) +{ + return static_cast<QDeclarativeGeoRouteQuery*>(p->object)->m_children.at(idx); +} + +void QDeclarativeGeoRouteQuery::clear(QQmlListProperty<QObject> *p) +{ + QDeclarativeGeoRouteQuery *query = static_cast<QDeclarativeGeoRouteQuery*>(p->object); + for (auto kid : qAsConst(query->m_children)) { + auto val = qobject_cast<QDeclarativeGeoMapParameter *>(kid); + if (val) { + val->disconnect(val, nullptr, query, nullptr); + query->m_extraParametersChanged = true; + } + } + query->m_children.clear(); + if (query->m_extraParametersChanged && query->complete_) { + emit query->extraParametersChanged(); + emit query->queryDetailsChanged(); + } +} + +QQmlListProperty<QObject> QDeclarativeGeoRouteQuery::declarativeChildren() +{ + return QQmlListProperty<QObject>(this, nullptr, + &QDeclarativeGeoRouteQuery::append, + &QDeclarativeGeoRouteQuery::count, + &QDeclarativeGeoRouteQuery::at, + &QDeclarativeGeoRouteQuery::clear); +} + void QDeclarativeGeoRouteQuery::doCoordinateChanged() { m_excludedAreaCoordinateChanged = false; |