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 | |
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>
-rw-r--r-- | src/positioning/qgeopolygon.cpp | 34 | ||||
-rw-r--r-- | src/positioning/qgeopolygon.h | 8 | ||||
-rw-r--r-- | tests/auto/declarative_geoshape/tst_locationsingleton.qml | 41 |
3 files changed, 80 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; diff --git a/tests/auto/declarative_geoshape/tst_locationsingleton.qml b/tests/auto/declarative_geoshape/tst_locationsingleton.qml index 3d6a9f9c..a5e791e0 100644 --- a/tests/auto/declarative_geoshape/tst_locationsingleton.qml +++ b/tests/auto/declarative_geoshape/tst_locationsingleton.qml @@ -215,6 +215,28 @@ Item { verify(path !== QtPositioning.shapeToPath(QtPositioning.path(trace1, 1))) compare(path, QtPositioning.shapeToPath(QtPositioning.path(trace2, 2))) } + + function test_shape_polygon_conversions() { + var polygon = QtPositioning.shapeToPolygon(QtPositioning.shape()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.circle()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.circle(tl, 10000)) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.rectangle()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.rectangle(tl, br)) + verify(!polygon.isValid) + + polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon()) + verify(!polygon.isValid) + polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon(trace1)) + verify(!polygon.isValid) // polygon needs 3 coords at least + polygon = QtPositioning.shapeToPolygon(QtPositioning.polygon(trace2)) + verify(polygon.isValid) + verify(polygon !== QtPositioning.shapeToPolygon(QtPositioning.polygon(trace1))) + compare(polygon, QtPositioning.shapeToPolygon(QtPositioning.polygon(trace2))) + } } @@ -314,4 +336,23 @@ Item { compare(geopath.coordinateAt(0).longitude, 11) } } + + TestCase { + name: "GeoPolygon path" + function test_qgeopolygon_path_operations() { + var geopolygon = QtPositioning.polygon() + + geopolygon.perimeter = trace2 + compare(geopolygon.perimeter.length, trace2.length) + + geopolygon.perimeter = mapPolyline.path + compare(geopolygon.perimeter.length, mapPolyline.pathLength()) + compare(geopolygon.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) + + geopolygon.perimeter = trace2 + compare(geopolygon.perimeter.length, trace2.length) + compare(geopolygon.coordinateAt(0).latitude, trace2[0].latitude) + compare(geopolygon.coordinateAt(0).longitude, trace2[0].longitude) + } + } } |