summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2015-05-21 13:30:28 +0200
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-05-26 13:29:42 +0000
commit046eec04fb47dee9a1802503004446d1fe777874 (patch)
tree9031a5a971fb89e527b68910aa5737ae612e51e8
parent9c61ad227761c9f83ea441c6a8db2d570a4009a3 (diff)
Provide means to convert GeoShape to appropriate subclass in QML
Change-Id: I1f0d1540b07af8f385ef670990a8669ec8c973d8 Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/imports/positioning/locationsingleton.cpp26
-rw-r--r--src/imports/positioning/locationsingleton.h3
-rw-r--r--tests/auto/declarative_geoshape/tst_locationsingleton.qml38
3 files changed, 67 insertions, 0 deletions
diff --git a/src/imports/positioning/locationsingleton.cpp b/src/imports/positioning/locationsingleton.cpp
index 6c1a8683..bb53bc9f 100644
--- a/src/imports/positioning/locationsingleton.cpp
+++ b/src/imports/positioning/locationsingleton.cpp
@@ -172,3 +172,29 @@ QGeoCircle LocationSingleton::circle(const QGeoCoordinate &center, qreal radius)
return QGeoCircle(center, radius);
}
+/*!
+ \qmlmethod geocircle QtPositioning::shapeToCircle(geoshape shape) const
+
+ Converts \a shape to a geocircle.
+
+ \sa {geocircle}
+ \since 5.5
+*/
+QGeoCircle LocationSingleton::shapeToCircle(const QGeoShape &shape) const
+{
+ return QGeoCircle(shape);
+}
+
+/*!
+ \qmlmethod georectangle QtPositioning::shapeToRectangle(geoshape shape) const
+
+ Converts \a shape to a georectangle.
+
+ \sa {georectangle}
+ \since 5.5
+*/
+QGeoRectangle LocationSingleton::shapeToRectangle(const QGeoShape &shape) const
+{
+ return QGeoRectangle(shape);
+}
+
diff --git a/src/imports/positioning/locationsingleton.h b/src/imports/positioning/locationsingleton.h
index 52c24a4c..c5d70b3a 100644
--- a/src/imports/positioning/locationsingleton.h
+++ b/src/imports/positioning/locationsingleton.h
@@ -64,6 +64,9 @@ public:
Q_INVOKABLE QGeoCircle circle() const;
Q_INVOKABLE QGeoCircle circle(const QGeoCoordinate &center, qreal radius = -1.0) const;
+
+ Q_INVOKABLE QGeoCircle shapeToCircle(const QGeoShape &shape) const;
+ Q_INVOKABLE QGeoRectangle shapeToRectangle(const QGeoShape &shape) const;
};
#endif // LOCATIONSINGLETON_H
diff --git a/tests/auto/declarative_geoshape/tst_locationsingleton.qml b/tests/auto/declarative_geoshape/tst_locationsingleton.qml
index 5c080171..f01ee5e2 100644
--- a/tests/auto/declarative_geoshape/tst_locationsingleton.qml
+++ b/tests/auto/declarative_geoshape/tst_locationsingleton.qml
@@ -153,4 +153,42 @@ Item {
compare(data.shape1 != data.shape2, !data.result)
}
}
+
+ TestCase {
+ name: "Conversions"
+
+ function test_shape_circle_conversions() {
+ var circle = QtPositioning.shapeToCircle(QtPositioning.shape())
+ verify(!circle.isValid)
+ circle = QtPositioning.shapeToCircle(QtPositioning.circle())
+ verify(!circle.isValid)
+ circle = QtPositioning.shapeToCircle(QtPositioning.circle(tl, 10000))
+ verify(circle.isValid)
+ compare(circle.center, tl)
+ compare(circle.radius, 10000)
+ circle = QtPositioning.shapeToCircle(QtPositioning.rectangle())
+ verify(!circle.isValid)
+ circle = QtPositioning.shapeToCircle(QtPositioning.rectangle(tl, br))
+ verify(!circle.isValid)
+ circle = QtPositioning.shapeToCircle(listBox)
+ verify(!circle.isValid)
+ }
+
+ function test_shape_rectangle_conversions() {
+ var rectangle = QtPositioning.shapeToRectangle(QtPositioning.shape())
+ verify(!rectangle.isValid)
+ rectangle = QtPositioning.shapeToRectangle(QtPositioning.circle())
+ verify(!rectangle.isValid)
+ rectangle = QtPositioning.shapeToRectangle(QtPositioning.circle(tl, 10000))
+ verify(!rectangle.isValid)
+ rectangle = QtPositioning.shapeToRectangle(QtPositioning.rectangle())
+ verify(!rectangle.isValid)
+ rectangle = QtPositioning.shapeToRectangle(QtPositioning.rectangle(tl, br))
+ verify(rectangle.isValid)
+ compare(rectangle.topLeft, tl)
+ compare(rectangle.bottomRight, br)
+ rectangle = QtPositioning.shapeToRectangle(listBox)
+ verify(rectangle.isValid)
+ }
+ }
}