diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-06-29 11:34:29 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-07-23 12:04:55 +0000 |
commit | 515c99188f1419514ad48dfa0787cf8bcfca7c19 (patch) | |
tree | 25a4bc0553c5817c93e709f2bc02b3b06ee073b7 /src/positioning | |
parent | 43b015e21d7d972ef4e9f5189fc2e840f648a492 (diff) | |
download | qtlocation-515c99188f1419514ad48dfa0787cf8bcfca7c19.tar.gz |
Add property for QGeoPolygon's perimeter and QML autotests using it
QML autotests were previously missing.
Change-Id: Id2c3a7fc61c57cef369dda109dbbfca183979443
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/positioning')
-rw-r--r-- | src/positioning/qgeopolygon.cpp | 34 | ||||
-rw-r--r-- | src/positioning/qgeopolygon.h | 8 |
2 files changed, 39 insertions, 3 deletions
diff --git a/src/positioning/qgeopolygon.cpp b/src/positioning/qgeopolygon.cpp index 1dafd1e0..1cbbc06e 100644 --- a/src/positioning/qgeopolygon.cpp +++ b/src/positioning/qgeopolygon.cpp @@ -178,7 +178,7 @@ bool QGeoPolygon::operator!=(const QGeoPolygon &other) const } /*! - Sets the \a polygon from a list of coordinates. + Sets the \a polygon's boundary from a list of coordinates. */ void QGeoPolygon::setPath(const QList<QGeoCoordinate> &path) { @@ -187,7 +187,7 @@ void QGeoPolygon::setPath(const QList<QGeoCoordinate> &path) } /*! - Returns all the elements. + Returns all the elements of the polygon's boundary. */ const QList<QGeoCoordinate> &QGeoPolygon::path() const { @@ -196,6 +196,36 @@ const QList<QGeoCoordinate> &QGeoPolygon::path() const } /*! + Sets all the elements of the polygon's perimeter. + + \since QtPositioning 5.12 +*/ +void QGeoPolygon::setPerimeter(const QVariantList &path) +{ + Q_D(QGeoPolygon); + QList<QGeoCoordinate> p; + for (const auto &c: path) { + if (c.canConvert<QGeoCoordinate>()) + p << c.value<QGeoCoordinate>(); + } + d->setPath(p); +} + +/*! + Returns all the elements of the polygon's perimeter. + + \since QtPositioning 5.12 +*/ +QVariantList QGeoPolygon::perimeter() const +{ + Q_D(const QGeoPolygon); + QVariantList p; + for (const auto &c: d->path()) + p << QVariant::fromValue(c); + return p; +} + +/*! Translates this geo polygon by \a degreesLatitude northwards and \a degreesLongitude eastwards. Negative values of \a degreesLatitude and \a degreesLongitude correspond to diff --git a/src/positioning/qgeopolygon.h b/src/positioning/qgeopolygon.h index 90886da7..85b09e34 100644 --- a/src/positioning/qgeopolygon.h +++ b/src/positioning/qgeopolygon.h @@ -41,6 +41,7 @@ #define QGEOPOLYGON_H #include <QtPositioning/QGeoShape> +#include <QtCore/QVariantList> QT_BEGIN_NAMESPACE @@ -51,6 +52,7 @@ typedef QGeoPathPrivate QGeoPolygonPrivate; class Q_POSITIONING_EXPORT QGeoPolygon : public QGeoShape { Q_GADGET + Q_PROPERTY(QVariantList perimeter READ perimeter WRITE setPerimeter REVISION 12) public: QGeoPolygon(); @@ -68,7 +70,7 @@ public: using QGeoShape::operator!=; bool operator!=(const QGeoPolygon &other) const; - void setPath(const QList<QGeoCoordinate> &path); + void setPath(const QList<QGeoCoordinate> &path); // ### Qt6: rename into setPerimeter const QList<QGeoCoordinate> &path() const; Q_INVOKABLE void translate(double degreesLatitude, double degreesLongitude); @@ -85,6 +87,10 @@ public: Q_INVOKABLE QString toString() const; +protected: + void setPerimeter(const QVariantList &path); + QVariantList perimeter() const; + private: inline QGeoPolygonPrivate *d_func(); inline const QGeoPolygonPrivate *d_func() const; |