diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-11-28 17:47:00 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-11-29 23:02:25 +0000 |
commit | 057fe199941b8783312abeedde315118b59ccb8e (patch) | |
tree | 293194d2e0c705d71c9b5d1b809da3e378a6bf40 | |
parent | e5fab0a22988ed98657a4954b0104cc25213effc (diff) | |
download | qtlocation-057fe199941b8783312abeedde315118b59ccb8e.tar.gz |
Add extended attributes to QGeoManeuver/QDeclarativeGeoManeuver
Change-Id: I6ed1d869d0a97e397057e92cf17ce9fddb4eca3f
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeomaneuver.cpp | 30 | ||||
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeomaneuver_p.h | 9 | ||||
-rw-r--r-- | src/location/maps/qgeomaneuver.cpp | 21 | ||||
-rw-r--r-- | src/location/maps/qgeomaneuver.h | 4 | ||||
-rw-r--r-- | src/location/maps/qgeomaneuver_p.h | 1 |
5 files changed, 64 insertions, 1 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomaneuver.cpp b/src/location/declarativemaps/qdeclarativegeomaneuver.cpp index b1c67167..ef3639af 100644 --- a/src/location/declarativemaps/qdeclarativegeomaneuver.cpp +++ b/src/location/declarativemaps/qdeclarativegeomaneuver.cpp @@ -185,6 +185,36 @@ QGeoCoordinate QDeclarativeGeoManeuver::waypoint() const } /*! + \qmlproperty Object RouteManeuver::extendedAttributes + + This property holds the extended attributes of the maneuver and is a map. + These attributes are plugin specific, and can be empty. + + Consult the \l {Qt Location#Plugin References and Parameters}{plugin documentation} + for what attributes are supported and how they should be used. + + Note, due to limitations of the QQmlPropertyMap, it is not possible + to declaratively specify the attributes in QML, assignment of attributes keys + and values can only be accomplished by JavaScript. + + \since QtLocation 5.11 +*/ +QQmlPropertyMap *QDeclarativeGeoManeuver::extendedAttributes() const +{ + if (!m_extendedAttributes) { + QDeclarativeGeoManeuver *self = const_cast<QDeclarativeGeoManeuver *>(this); + self->m_extendedAttributes = new QQmlPropertyMap(self); + // Fill it + const QStringList keys = maneuver_.extendedAttributes().keys(); + for (const QString &key: keys) { + self->m_extendedAttributes->insert(key, + maneuver_.extendedAttributes().value(key)); + } + } + return m_extendedAttributes; +} + +/*! \qmlproperty bool RouteManeuver::waypointValid This read-only property holds whether this \l waypoint, associated with this diff --git a/src/location/declarativemaps/qdeclarativegeomaneuver_p.h b/src/location/declarativemaps/qdeclarativegeomaneuver_p.h index 0e957a1f..f321c133 100644 --- a/src/location/declarativemaps/qdeclarativegeomaneuver_p.h +++ b/src/location/declarativemaps/qdeclarativegeomaneuver_p.h @@ -50,7 +50,7 @@ #include <QtLocation/private/qlocationglobal_p.h> #include <QtLocation/qgeomaneuver.h> - +#include <QtQml/QQmlPropertyMap> #include <QtPositioning/QGeoCoordinate> #include <QObject> @@ -71,6 +71,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoManeuver : public QObject Q_PROPERTY(qreal distanceToNextInstruction READ distanceToNextInstruction CONSTANT) Q_PROPERTY(QGeoCoordinate waypoint READ waypoint CONSTANT) Q_PROPERTY(bool waypointValid READ waypointValid CONSTANT) + Q_PROPERTY(QObject *extendedAttributes READ extendedAttributes NOTIFY extendedAttributesChanged) public: enum Direction { @@ -101,9 +102,15 @@ public: int timeToNextInstruction() const; qreal distanceToNextInstruction() const; QGeoCoordinate waypoint() const; + QQmlPropertyMap *extendedAttributes() const; + +Q_SIGNALS: + void extendedAttributesChanged(); //in practice is never emitted since parameters cannot be re-assigned + //the declaration is needed to avoid warnings about non-notifyable properties private: QGeoManeuver maneuver_; + QQmlPropertyMap *m_extendedAttributes = nullptr; }; QT_END_NAMESPACE diff --git a/src/location/maps/qgeomaneuver.cpp b/src/location/maps/qgeomaneuver.cpp index f38cb293..d1322228 100644 --- a/src/location/maps/qgeomaneuver.cpp +++ b/src/location/maps/qgeomaneuver.cpp @@ -283,6 +283,27 @@ QGeoCoordinate QGeoManeuver::waypoint() const return d_ptr->waypoint; } +/*! + Sets the extended attributes associated with this maneuver. + + \since QtLocation 5.11 +*/ +void QGeoManeuver::setExtendedAttributes(const QVariantMap &extendedAttributes) +{ + d_ptr->valid = true; + d_ptr->extendedAttributes = extendedAttributes; +} + +/*! + Returns the extended attributes associated with this maneuver. + + \since QtLocation 5.11 +*/ +QVariantMap QGeoManeuver::extendedAttributes() const +{ + return d_ptr->extendedAttributes; +} + /******************************************************************************* *******************************************************************************/ diff --git a/src/location/maps/qgeomaneuver.h b/src/location/maps/qgeomaneuver.h index 9710f8fc..a86acfbd 100644 --- a/src/location/maps/qgeomaneuver.h +++ b/src/location/maps/qgeomaneuver.h @@ -39,6 +39,7 @@ #include <QtCore/qshareddata.h> #include <QtLocation/qlocationglobal.h> +#include <QVariantMap> QT_BEGIN_NAMESPACE @@ -95,6 +96,9 @@ public: void setWaypoint(const QGeoCoordinate &coordinate); QGeoCoordinate waypoint() const; + void setExtendedAttributes(const QVariantMap &extendedAttributes); + QVariantMap extendedAttributes() const; + private: QSharedDataPointer<QGeoManeuverPrivate> d_ptr; }; diff --git a/src/location/maps/qgeomaneuver_p.h b/src/location/maps/qgeomaneuver_p.h index c048f132..4a491b73 100644 --- a/src/location/maps/qgeomaneuver_p.h +++ b/src/location/maps/qgeomaneuver_p.h @@ -73,6 +73,7 @@ public: int timeToNextInstruction; qreal distanceToNextInstruction; QGeoCoordinate waypoint; + QVariantMap extendedAttributes; }; QT_END_NAMESPACE |