From e7bb8f636086c04acd97e4eb3c42e7c6c05dc8f2 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Fri, 7 Dec 2018 14:22:08 +0100 Subject: QGeoPath/QGeoPolygon: defer bbox computation This patch introduces 2 versions of QGeoPath/polygon private: a lazy version (default) and an eager version. The reason is that certain classes such as MapItems make heavy use of the bounding box of the geoshapes, as well as the contains method, and in those cases it's beneficial to have it eagerly computed and cached. Other use cases do not see this feature so much in use, and the added costs, both in terms of computation and in terms of memory requirements for cached data can be avoided. As the patch currently stands, using copy constructors for QGeoPath and QGeoPolygon with a QGeoPathEager and a QGeoPolygonEager (and vice-versa) changes the type of d_ptr. This means that doing, for example, QGeoPath(someQGeoPathEager) effectively returns a QGeoPath that behaves like a QGeoPathEager (although not being one). Change-Id: I8cfed1e0a747139d0fb6d5fb5236bf5f5fbf24c1 Reviewed-by: Alex Blasche --- .../declarativemaps/qdeclarativepolygonmapitem.cpp | 4 +++- .../declarativemaps/qdeclarativepolylinemapitem.cpp | 16 ++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'src/location/declarativemaps') diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp index f4cdc6bf..23ea5666 100644 --- a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp @@ -50,6 +50,7 @@ #include #include +#include /* poly2tri triangulator includes */ #include @@ -318,6 +319,7 @@ QDeclarativePolygonMapItem::QDeclarativePolygonMapItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), border_(this), color_(Qt::transparent), dirtyMaterial_(true), updatingGeometry_(false) { + geopath_ = QGeoPolygonEager(); setFlag(ItemHasContents, true); QObject::connect(&border_, SIGNAL(colorChanged(QColor)), this, SLOT(markSourceDirtyAndUpdate())); @@ -611,7 +613,7 @@ void QDeclarativePolygonMapItem::setGeoShape(const QGeoShape &shape) if (shape == geopath_) return; - geopath_ = shape; + geopath_ = QGeoPathEager(shape); regenerateCache(); geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); borderGeometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); diff --git a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp index 2fb3098d..2bed0896 100644 --- a/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp +++ b/src/location/declarativemaps/qdeclarativepolylinemapitem.cpp @@ -54,6 +54,7 @@ #include #include +#include #include QT_BEGIN_NAMESPACE @@ -738,6 +739,7 @@ bool QGeoMapPolylineGeometry::contains(const QPointF &point) const QDeclarativePolylineMapItem::QDeclarativePolylineMapItem(QQuickItem *parent) : QDeclarativeGeoMapItemBase(parent), line_(this), dirtyMaterial_(true), updatingGeometry_(false) { + geopath_ = QGeoPathEager(); setFlag(ItemHasContents, true); QObject::connect(&line_, SIGNAL(colorChanged(QColor)), this, SLOT(updateAfterLinePropertiesChanged())); @@ -806,7 +808,7 @@ void QDeclarativePolylineMapItem::setPath(const QGeoPath &path) if (geopath_.path() == path.path()) return; - geopath_ = path; + geopath_ = QGeoPathEager(path); regenerateCache(); geometry_.setPreserveGeometry(true, geopath_.boundingGeoRectangle().topLeft()); markSourceDirtyAndUpdate(); @@ -1135,18 +1137,8 @@ const QGeoShape &QDeclarativePolylineMapItem::geoShape() const 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(); + setPath(geopath); } QGeoMap::ItemType QDeclarativePolylineMapItem::itemType() const -- cgit v1.2.1