summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2015-05-20 11:30:13 +0200
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-05-26 13:29:26 +0000
commit9c61ad227761c9f83ea441c6a8db2d570a4009a3 (patch)
tree71320572d0be2d2c4d2ad5a96445567596b06602 /src
parent68115c86eb0bfbe3218ed4fa3af3b006720a8c43 (diff)
downloadqtlocation-9c61ad227761c9f83ea441c6a8db2d570a4009a3.tar.gz
Workaround for failing conversion between Q_GADGET's
QGeoRectangle and QGeoCircle are subclasses of QGeoShape. Before this patch setting a QGeoShape property of a QML object is not possible because the QGeoRectangle/QGeoCircle cannot be converted to a QGeoShape. This patch addresses the problem by providing custom converters for the above classes. It enables QVariant::convert() for the classes above. Change-Id: I7daba5254dad0df598324432db3b1819e68648b6 Task-number: QTBUG-46232 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/positioning/qgeocircle.cpp15
-rw-r--r--src/positioning/qgeorectangle.cpp18
2 files changed, 33 insertions, 0 deletions
diff --git a/src/positioning/qgeocircle.cpp b/src/positioning/qgeocircle.cpp
index 6b5b24fd..c52b631e 100644
--- a/src/positioning/qgeocircle.cpp
+++ b/src/positioning/qgeocircle.cpp
@@ -100,12 +100,24 @@ inline const QGeoCirclePrivate *QGeoCircle::d_func() const
return static_cast<const QGeoCirclePrivate *>(d_ptr.constData());
}
+struct CircleVariantConversions
+{
+ CircleVariantConversions()
+ {
+ QMetaType::registerConverter<QGeoShape, QGeoCircle>();
+ QMetaType::registerConverter<QGeoCircle, QGeoShape>();
+ }
+};
+
+Q_GLOBAL_STATIC(CircleVariantConversions, initCircleConversions)
+
/*!
Constructs a new, invalid geo circle.
*/
QGeoCircle::QGeoCircle()
: QGeoShape(new QGeoCirclePrivate)
{
+ initCircleConversions();
}
/*!
@@ -113,6 +125,7 @@ QGeoCircle::QGeoCircle()
*/
QGeoCircle::QGeoCircle(const QGeoCoordinate &center, qreal radius)
{
+ initCircleConversions();
d_ptr = new QGeoCirclePrivate(center, radius);
}
@@ -122,6 +135,7 @@ QGeoCircle::QGeoCircle(const QGeoCoordinate &center, qreal radius)
QGeoCircle::QGeoCircle(const QGeoCircle &other)
: QGeoShape(other)
{
+ initCircleConversions();
}
/*!
@@ -130,6 +144,7 @@ QGeoCircle::QGeoCircle(const QGeoCircle &other)
QGeoCircle::QGeoCircle(const QGeoShape &other)
: QGeoShape(other)
{
+ initCircleConversions();
if (type() != QGeoShape::CircleType)
d_ptr = new QGeoCirclePrivate;
}
diff --git a/src/positioning/qgeorectangle.cpp b/src/positioning/qgeorectangle.cpp
index 2e615494..421e6b29 100644
--- a/src/positioning/qgeorectangle.cpp
+++ b/src/positioning/qgeorectangle.cpp
@@ -180,12 +180,25 @@ inline const QGeoRectanglePrivate *QGeoRectangle::d_func() const
return static_cast<const QGeoRectanglePrivate *>(d_ptr.constData());
}
+struct RectangleVariantConversions
+{
+ RectangleVariantConversions()
+ {
+ QMetaType::registerConverter<QGeoRectangle, QGeoShape>();
+ QMetaType::registerConverter<QGeoShape, QGeoRectangle>();
+ }
+};
+
+
+Q_GLOBAL_STATIC(RectangleVariantConversions, initRectangleConversions)
+
/*!
Constructs a new, invalid geo rectangle.
*/
QGeoRectangle::QGeoRectangle()
: QGeoShape(new QGeoRectanglePrivate)
{
+ initRectangleConversions();
}
/*!
@@ -200,6 +213,7 @@ QGeoRectangle::QGeoRectangle()
*/
QGeoRectangle::QGeoRectangle(const QGeoCoordinate &center, double degreesWidth, double degreesHeight)
{
+ initRectangleConversions();
d_ptr = new QGeoRectanglePrivate(center, center);
setWidth(degreesWidth);
setHeight(degreesHeight);
@@ -211,6 +225,7 @@ QGeoRectangle::QGeoRectangle(const QGeoCoordinate &center, double degreesWidth,
*/
QGeoRectangle::QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate &bottomRight)
{
+ initRectangleConversions();
d_ptr = new QGeoRectanglePrivate(topLeft, bottomRight);
}
@@ -219,6 +234,7 @@ QGeoRectangle::QGeoRectangle(const QGeoCoordinate &topLeft, const QGeoCoordinate
*/
QGeoRectangle::QGeoRectangle(const QList<QGeoCoordinate> &coordinates)
{
+ initRectangleConversions();
if (coordinates.isEmpty()) {
d_ptr = new QGeoRectanglePrivate;
} else {
@@ -237,6 +253,7 @@ QGeoRectangle::QGeoRectangle(const QList<QGeoCoordinate> &coordinates)
QGeoRectangle::QGeoRectangle(const QGeoRectangle &other)
: QGeoShape(other)
{
+ initRectangleConversions();
}
/*!
@@ -245,6 +262,7 @@ QGeoRectangle::QGeoRectangle(const QGeoRectangle &other)
QGeoRectangle::QGeoRectangle(const QGeoShape &other)
: QGeoShape(other)
{
+ initRectangleConversions();
if (type() != QGeoShape::RectangleType)
d_ptr = new QGeoRectanglePrivate;
}