diff options
Diffstat (limited to 'src/imports/positioning')
-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; |