diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-08-10 12:50:10 +0200 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2018-08-14 11:16:53 +0000 |
commit | 40e9867254d2241fdac1ea76d416ad54e71d04ac (patch) | |
tree | 1e377b8ab2eabc87490e300c34983c5c0dc6461c | |
parent | 07be65e9d9a883aab4e1fda367cf591b7cb97631 (diff) | |
download | qtlocation-40e9867254d2241fdac1ea76d416ad54e71d04ac.tar.gz |
Make QDeclarativeGeoMapItemBase::geoShape R/W
This patch adds a setter for the geoShape property, overridden
in the subclasses.
Change-Id: I5fc4d412efee5e95c5650943ea5bf9b72dc40155
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
12 files changed, 90 insertions, 14 deletions
diff --git a/src/location/declarativemaps/qdeclarativecirclemapitem.cpp b/src/location/declarativemaps/qdeclarativecirclemapitem.cpp index 608260cd..2727cc26 100644 --- a/src/location/declarativemaps/qdeclarativecirclemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativecirclemapitem.cpp @@ -606,6 +606,24 @@ const QGeoShape &QDeclarativeCircleMapItem::geoShape() const return circle_; } +void QDeclarativeCircleMapItem::setGeoShape(const QGeoShape &shape) +{ + if (shape == circle_) + 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() != circle_.center(); + const bool radiusHasChanged = circle.radius() != circle_.radius(); + circle_ = circle; + + updateCirclePath(); + markSourceDirtyAndUpdate(); + if (centerHasChanged) + emit centerChanged(circle_.center()); + if (radiusHasChanged) + emit radiusChanged(circle_.radius()); +} + QGeoMap::ItemType QDeclarativeCircleMapItem::itemType() const { return QGeoMap::MapCircle; diff --git a/src/location/declarativemaps/qdeclarativecirclemapitem_p.h b/src/location/declarativemaps/qdeclarativecirclemapitem_p.h index 2e8c56f8..a5b92881 100644 --- a/src/location/declarativemaps/qdeclarativecirclemapitem_p.h +++ b/src/location/declarativemaps/qdeclarativecirclemapitem_p.h @@ -94,6 +94,7 @@ public: bool contains(const QPointF &point) const override; const QGeoShape &geoShape() const override; + void setGeoShape(const QGeoShape &shape) override; QGeoMap::ItemType itemType() const override; static bool crossEarthPole(const QGeoCoordinate ¢er, qreal distance); diff --git a/src/location/declarativemaps/qdeclarativegeomapitembase_p.h b/src/location/declarativemaps/qdeclarativegeomapitembase_p.h index f884c13e..4eff32db 100644 --- a/src/location/declarativemaps/qdeclarativegeomapitembase_p.h +++ b/src/location/declarativemaps/qdeclarativegeomapitembase_p.h @@ -83,7 +83,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoMapItemBase : public QQuickItem { Q_OBJECT - Q_PROPERTY(QGeoShape geoShape READ geoShape STORED false ) + Q_PROPERTY(QGeoShape geoShape READ geoShape WRITE setGeoShape STORED false ) public: explicit QDeclarativeGeoMapItemBase(QQuickItem *parent = 0); virtual ~QDeclarativeGeoMapItemBase(); @@ -94,6 +94,7 @@ public: QDeclarativeGeoMap *quickMap() { return quickMap_; } QGeoMap *map() { return map_; } virtual const QGeoShape &geoShape() const = 0; + virtual void setGeoShape(const QGeoShape &shape) = 0; QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); virtual QSGNode *updateMapItemPaintNode(QSGNode *, UpdatePaintNodeData *); diff --git a/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp b/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp index 9a86fc8e..8c71e7be 100644 --- a/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp +++ b/src/location/declarativemaps/qdeclarativegeomapquickitem.cpp @@ -346,6 +346,21 @@ const QGeoShape &QDeclarativeGeoMapQuickItem::geoShape() const return geoshape_; } +void QDeclarativeGeoMapQuickItem::setGeoShape(const QGeoShape &shape) +{ + if (shape == geoshape_) + return; + + const QGeoRectangle rect = shape.boundingGeoRectangle(); + geoshape_ = rect; + coordinate_ = rect.center(); + + // TODO: Handle zoomLevel != 0.0 + polishAndUpdate(); + emit coordinateChanged(); + +} + QGeoMap::ItemType QDeclarativeGeoMapQuickItem::itemType() const { return QGeoMap::MapQuickItem; diff --git a/src/location/declarativemaps/qdeclarativegeomapquickitem_p.h b/src/location/declarativemaps/qdeclarativegeomapquickitem_p.h index 8e2c2785..a27a0bce 100644 --- a/src/location/declarativemaps/qdeclarativegeomapquickitem_p.h +++ b/src/location/declarativemaps/qdeclarativegeomapquickitem_p.h @@ -97,6 +97,7 @@ public: qreal zoomLevel() const; const QGeoShape &geoShape() const override; + void setGeoShape(const QGeoShape &shape) override; QGeoMap::ItemType itemType() const override; Q_SIGNALS: diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp index c0d7f24b..b692bc76 100644 --- a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp @@ -615,6 +615,19 @@ const QGeoShape &QDeclarativePolygonMapItem::geoShape() const return geopath_; } +void QDeclarativePolygonMapItem::setGeoShape(const QGeoShape &shape) +{ + if (shape == geopath_) + return; + + geopath_ = shape; + regenerateCache(); + geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); + borderGeometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); + markSourceDirtyAndUpdate(); + emit pathChanged(); +} + QGeoMap::ItemType QDeclarativePolygonMapItem::itemType() const { return QGeoMap::MapPolygon; diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem_p.h b/src/location/declarativemaps/qdeclarativepolygonmapitem_p.h index 83983651..a68b6315 100644 --- a/src/location/declarativemaps/qdeclarativepolygonmapitem_p.h +++ b/src/location/declarativemaps/qdeclarativepolygonmapitem_p.h @@ -52,6 +52,7 @@ #include <QtLocation/private/qdeclarativegeomapitembase_p.h> #include <QtLocation/private/qdeclarativepolylinemapitem_p.h> #include <QtLocation/private/qgeomapitemgeometry_p.h> +#include <QtPositioning/qgeopolygon.h> #include <QSGGeometryNode> #include <QSGFlatColorMaterial> @@ -106,6 +107,7 @@ public: bool contains(const QPointF &point) const override; const QGeoShape &geoShape() const override; + void setGeoShape(const QGeoShape &shape) override; QGeoMap::ItemType itemType() const override; Q_SIGNALS: @@ -125,7 +127,7 @@ private: void regenerateCache(); void updateCache(); - QGeoPath geopath_; + QGeoPolygon geopath_; QList<QDoubleVector2D> geopathProjected_; QDeclarativeMapLineProperties border_; QColor color_; diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index e6619800..70b4bc21 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -998,6 +998,22 @@ const QGeoShape &QDeclarativePolylineMapItem::geoShape() const return geopath_; } +void QDeclarativePolylineMapItem::setGeoShape(const QGeoShape &shape) +{ + if (shape == geopath_) + return; + + const QGeoPath geopath(shape); // if shape isn't a path, path will be created as a default-constructed path + const bool pathHasChanged = geopath.path() != geopath_.path(); + geopath_ = geopath; + + regenerateCache(); + geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); + markSourceDirtyAndUpdate(); + if (pathHasChanged) + emit pathChanged(); +} + QGeoMap::ItemType QDeclarativePolylineMapItem::itemType() const { return QGeoMap::MapPolyline; diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h index 225f21d9..392841dd 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem_p.h @@ -149,6 +149,7 @@ public: bool contains(const QPointF &point) const override; const QGeoShape &geoShape() const override; + void setGeoShape(const QGeoShape &shape) override; QGeoMap::ItemType itemType() const override; QDeclarativeMapLineProperties *line(); diff --git a/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp b/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp index e90c0596..ba67ecad 100644 --- a/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativerectanglemapitem.cpp @@ -352,6 +352,24 @@ const QGeoShape &QDeclarativeRectangleMapItem::geoShape() const return rectangle_; } +void QDeclarativeRectangleMapItem::setGeoShape(const QGeoShape &shape) +{ + if (shape == rectangle_) + return; + + const QGeoRectangle rectangle = rectangle_.boundingGeoRectangle(); + const bool tlHasChanged = rectangle.topLeft() != rectangle_.topLeft(); + const bool brHasChanged = rectangle.bottomRight() != rectangle_.bottomRight(); + rectangle_ = rectangle; + + updatePath(); + markSourceDirtyAndUpdate(); + if (tlHasChanged) + emit topLeftChanged(rectangle_.topLeft()); + if (brHasChanged) + emit bottomRightChanged(rectangle_.bottomRight()); +} + QGeoMap::ItemType QDeclarativeRectangleMapItem::itemType() const { return QGeoMap::MapRectangle; diff --git a/src/location/declarativemaps/qdeclarativerectanglemapitem_p.h b/src/location/declarativemaps/qdeclarativerectanglemapitem_p.h index c475bf7f..e2ac2974 100644 --- a/src/location/declarativemaps/qdeclarativerectanglemapitem_p.h +++ b/src/location/declarativemaps/qdeclarativerectanglemapitem_p.h @@ -90,6 +90,7 @@ public: bool contains(const QPointF &point) const override; const QGeoShape &geoShape() const override; + void setGeoShape(const QGeoShape &shape) override; QGeoMap::ItemType itemType() const override; Q_SIGNALS: diff --git a/tests/auto/declarative_geoshape/tst_locationsingleton.qml b/tests/auto/declarative_geoshape/tst_locationsingleton.qml index a5e791e0..096a72e9 100644 --- a/tests/auto/declarative_geoshape/tst_locationsingleton.qml +++ b/tests/auto/declarative_geoshape/tst_locationsingleton.qml @@ -313,21 +313,10 @@ Item { compare(geopath.path.length, mapPolyline.pathLength()) compare(geopath.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) - mapPolylineGeopath.path = mapPolyline.path + mapPolylineGeopath.geoShape = geopath compare(mapPolylineGeopath.pathLength(), mapPolyline.pathLength()) compare(mapPolylineGeopath.geoShape.boundingGeoRectangle(), mapPolyline.geoShape.boundingGeoRectangle()) - try { - var err = false; - mapPolylineGeopath.geoShape = geopath - } catch (e) { - if (e.message != 'Cannot assign to read-only property "geoShape"') - fail('Expected Cannot assign to read-only property "geoShape", got: ' + e.message); - err = true; - } finally { - verify(err, 'should throw Cannot assign to read-only property "geoShape"'); - } - geopath.path = trace2 geopath.path[0].longitude = 11.0 compare(geopath.path.length, trace2.length) |