diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-05-30 15:26:45 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2017-06-05 13:43:14 +0000 |
commit | 4417378dbb3a5b83c5c7a9563880b83ca0b52542 (patch) | |
tree | 36e9c3a81ba01cdf3041f5cd5778a6347339c150 /src | |
parent | 5c957221d0cca19a27abc9781c20c24f1c32030b (diff) | |
download | qtlocation-4417378dbb3a5b83c5c7a9563880b83ca0b52542.tar.gz |
Add mean to create qgeopath in locationsingleton
As currently there is no way to create a pre-filled qgeopath,
this patch adds an overload to QtPositioning.geopath() to pass
parameters to the constructor.
Change-Id: I05af4dbef07bd62e9e2eace7105b5255e8a392fa
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/positioning/locationsingleton.cpp | 42 | ||||
-rw-r--r-- | src/imports/positioning/locationsingleton.h | 2 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/imports/positioning/locationsingleton.cpp b/src/imports/positioning/locationsingleton.cpp index a48c1a96..19b05761 100644 --- a/src/imports/positioning/locationsingleton.cpp +++ b/src/imports/positioning/locationsingleton.cpp @@ -39,6 +39,26 @@ #include "locationsingleton.h" +static QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok) +{ + QGeoCoordinate c; + + if (value.isObject()) { + if (value.hasProperty(QStringLiteral("latitude"))) + c.setLatitude(value.property(QStringLiteral("latitude")).toNumber()); + if (value.hasProperty(QStringLiteral("longitude"))) + c.setLongitude(value.property(QStringLiteral("longitude")).toNumber()); + if (value.hasProperty(QStringLiteral("altitude"))) + c.setAltitude(value.property(QStringLiteral("altitude")).toNumber()); + + if (ok) + *ok = true; + } + + return c; +} + + /*! \qmltype QtPositioning \instantiates LocationSingleton @@ -191,6 +211,28 @@ QGeoPath LocationSingleton::path() const return QGeoPath(); } +QGeoPath LocationSingleton::path(const QJSValue &value, qreal width) const +{ + QList<QGeoCoordinate> pathList; + + if (value.isArray()) { + quint32 length = value.property(QStringLiteral("length")).toUInt(); + for (quint32 i = 0; i < length; ++i) { + bool ok; + QGeoCoordinate c = parseCoordinate(value.property(i), &ok); + + if (!ok || !c.isValid()) { + pathList.clear(); // aborting + break; + } + + pathList.append(c); + } + } + + return QGeoPath(pathList, width); +} + /*! \qmlmethod geocircle QtPositioning::shapeToCircle(geoshape shape) const diff --git a/src/imports/positioning/locationsingleton.h b/src/imports/positioning/locationsingleton.h index 9a5320e0..4faf2738 100644 --- a/src/imports/positioning/locationsingleton.h +++ b/src/imports/positioning/locationsingleton.h @@ -47,6 +47,7 @@ #include <QtPositioning/QGeoRectangle> #include <QtPositioning/QGeoCircle> #include <QtPositioning/QGeoPath> +#include <QtQml/QJSValue> #include <QVariant> class LocationSingleton : public QObject @@ -73,6 +74,7 @@ public: Q_INVOKABLE QGeoCircle circle(const QGeoCoordinate ¢er, qreal radius = -1.0) const; Q_INVOKABLE QGeoPath path() const; + Q_INVOKABLE QGeoPath path(const QJSValue &value, qreal width = 0.0) const; Q_INVOKABLE QGeoCircle shapeToCircle(const QGeoShape &shape) const; Q_INVOKABLE QGeoRectangle shapeToRectangle(const QGeoShape &shape) const; |