summaryrefslogtreecommitdiff
path: root/src/imports/positioning/locationsingleton.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-05-30 15:26:45 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-06-05 13:43:14 +0000
commit4417378dbb3a5b83c5c7a9563880b83ca0b52542 (patch)
tree36e9c3a81ba01cdf3041f5cd5778a6347339c150 /src/imports/positioning/locationsingleton.cpp
parent5c957221d0cca19a27abc9781c20c24f1c32030b (diff)
downloadqtlocation-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/imports/positioning/locationsingleton.cpp')
-rw-r--r--src/imports/positioning/locationsingleton.cpp42
1 files changed, 42 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