diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-12-08 18:45:36 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2019-02-01 14:09:48 +0000 |
commit | 587b8812c9b2fc7ed7ad4ab35d27114ee98eafc6 (patch) | |
tree | 4589a6518d38b504a6941524a959d871cbf2537c /src/location/labs/qmapcircleobject.cpp | |
parent | 8e923d801b460ccc6fdc92d4a7bc8750410ad042 (diff) | |
download | qtlocation-587b8812c9b2fc7ed7ad4ab35d27114ee98eafc6.tar.gz |
Introduce QGeoMapObject::geoShape property
In this way MapObjects become a little closer to MapItems,
and this property can be used to, for example, center the map
on one specific object or object group.
Fixes: QTBUG-69640
Change-Id: I4dbead9e670bf5d1eeaccb2bd09d956b8de7da87
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/location/labs/qmapcircleobject.cpp')
-rw-r--r-- | src/location/labs/qmapcircleobject.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/location/labs/qmapcircleobject.cpp b/src/location/labs/qmapcircleobject.cpp index d7f1d58f..5f0db29d 100644 --- a/src/location/labs/qmapcircleobject.cpp +++ b/src/location/labs/qmapcircleobject.cpp @@ -37,6 +37,7 @@ #include "qmapcircleobject_p.h" #include "qmapcircleobject_p_p.h" #include <QExplicitlySharedDataPointer> +#include <QtPositioning/qgeocircle.h> QT_BEGIN_NAMESPACE @@ -68,7 +69,30 @@ QGeoMapObject::Type QMapCircleObjectPrivate::type() const return QGeoMapObject::CircleType; } +QGeoShape QMapCircleObjectPrivate::geoShape() const +{ + return QGeoCircle(center(), radius()); +} + +void QMapCircleObjectPrivate::setGeoShape(const QGeoShape &shape) +{ + if (shape == geoShape()) + return; + const QGeoCircle circle(shape); // if shape isn't a circle, circle will be created as a default-constructed circle + const bool centerHasChanged = circle.center() != center(); + const bool radiusHasChanged = circle.radius() != radius(); + + if (centerHasChanged) + setCenter(circle.center()); // to handle overrides + if (radiusHasChanged) + setRadius(circle.radius()); // to handle overrides + + if (centerHasChanged) + emit static_cast<QMapCircleObject *>(q)->centerChanged(); + if (radiusHasChanged) + emit static_cast<QMapCircleObject *>(q)->radiusChanged(); +} // // QMapCircleObjectPrivate default implementation @@ -162,8 +186,6 @@ QGeoMapObjectPrivate *QMapCircleObjectPrivateDefault::clone() return new QMapCircleObjectPrivateDefault(static_cast<QMapCircleObjectPrivate &>(*this)); } - - QMapCircleObject::QMapCircleObject(QObject *parent) : QGeoMapObject(QExplicitlySharedDataPointer<QGeoMapObjectPrivate>(new QMapCircleObjectPrivateDefault(this)), parent) |