From 480b5e168da11dc917dfd7ed8d44359d702eac83 Mon Sep 17 00:00:00 2001 From: Julian Sherollari Date: Mon, 20 Aug 2018 18:36:32 +0200 Subject: Add QGeoPolygon holes support to LocationSingleton Change-Id: I877e9c8e9d11c40ac302ceeaa9c8c85da958f038 Reviewed-by: Paolo Angelelli --- src/imports/positioning/locationsingleton.cpp | 34 +++++++++++++++++++++++++++ src/imports/positioning/locationsingleton.h | 1 + 2 files changed, 35 insertions(+) (limited to 'src') diff --git a/src/imports/positioning/locationsingleton.cpp b/src/imports/positioning/locationsingleton.cpp index 209a289b..e355851e 100644 --- a/src/imports/positioning/locationsingleton.cpp +++ b/src/imports/positioning/locationsingleton.cpp @@ -40,6 +40,7 @@ #include "locationsingleton.h" #include #include +#include static QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok) { @@ -266,6 +267,39 @@ QGeoPolygon LocationSingleton::polygon(const QVariantList &coordinates) const return QGeoPolygon(internalCoordinates); } +/*! + \qmlmethod geopolygon QtPositioning::polygon(list perimeter, list> holes) const + + Constructs a polygon from coordinates for perimeter and inner holes. + + \sa {geopolygon} + \since 5.12 +*/ +QGeoPolygon LocationSingleton::polygon(const QVariantList &perimeter, const QVariantList &holes) const +{ + QList internalCoordinates; + for (int i = 0; i < perimeter.size(); i++) { + if (perimeter.at(i).canConvert()) + internalCoordinates << perimeter.at(i).value(); + } + QGeoPolygon poly(internalCoordinates); + + for (int i = 0; i < holes.size(); i++) { + if (holes.at(i).type() == QVariant::List) { + QList hole; + const QVariantList &holeData = holes.at(i).toList(); + for (int j = 0; j < holeData.size(); j++) { + if (holeData.at(j).canConvert()) + hole << holeData.at(j).value(); + } + if (hole.size()) + poly.addHole(hole); + } + } + + return poly; +} + /*! \qmlmethod geocircle QtPositioning::shapeToCircle(geoshape shape) const diff --git a/src/imports/positioning/locationsingleton.h b/src/imports/positioning/locationsingleton.h index a70332ec..9372b8f1 100644 --- a/src/imports/positioning/locationsingleton.h +++ b/src/imports/positioning/locationsingleton.h @@ -80,6 +80,7 @@ public: Q_INVOKABLE QGeoPolygon polygon() const; Q_INVOKABLE QGeoPolygon polygon(const QVariantList &value) const; + Q_INVOKABLE QGeoPolygon polygon(const QVariantList &perimeter, const QVariantList &holes) const; Q_INVOKABLE QGeoCircle shapeToCircle(const QGeoShape &shape) const; Q_INVOKABLE QGeoRectangle shapeToRectangle(const QGeoShape &shape) const; -- cgit v1.2.1