From 09f68b95b125cef0c8e93092b0aad3a3e794913f Mon Sep 17 00:00:00 2001 From: Wolfgang Bremer <wolfgang@w-bremer.de> Date: Tue, 5 Aug 2014 01:54:11 +0200 Subject: [PATCH] Fix fitViewportToMapItemsRefine The item counter was broken. Therefore the bounding box calculation only worked under certain circumstances. This commit removes the circle special case calculation, which is superfluous, and treats all map items the same way. Change-Id: Ida0a6cf695fb151132bc867eb30ecb834a5bf6c5 Reviewed-by: Fabian Bumberger <fbumberger@rim.com> Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com> --- src/imports/location/qdeclarativegeomap.cpp | 27 +++++---------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index b627da29a..6263ed336 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -1088,13 +1088,13 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine) double bottomRightY = 0; // find bounds of all map items - QGeoCoordinate geoCenter; - QDoubleVector2D centerPt; int itemCount = 0; for (int i = 0; i < mapItems_.count(); ++i) { if (!mapItems_.at(i)) continue; QDeclarativeGeoMapItemBase *item = mapItems_.at(i).data(); + if (!item) + continue; // skip quick items in the first pass and refine the fit later if (refine) { @@ -1104,26 +1104,11 @@ void QDeclarativeGeoMap::fitViewportToMapItemsRefine(bool refine) continue; } - // account for the special case - circle - QDeclarativeCircleMapItem *circleItem = - qobject_cast<QDeclarativeCircleMapItem *>(item); + topLeftX = item->position().x(); + topLeftY = item->position().y(); + bottomRightX = topLeftX + item->width(); + bottomRightY = topLeftY + item->height(); - if ((!circleItem || !circleItem->center().isValid()) && !item) - continue; - if (circleItem) { - geoCenter = circleItem->center(); - centerPt = map_->coordinateToScreenPosition(geoCenter, false); - topLeftX = centerPt.x() - circleItem->width() / 2.0; - topLeftY = centerPt.y() - circleItem->height() / 2.0; - bottomRightX = centerPt.x() + circleItem->width() / 2.0; - bottomRightY = centerPt.y() + circleItem->height() / 2.0; - } else if (item) { - topLeftX = item->position().x(); - topLeftY = item->position().y(); - bottomRightX = topLeftX + item->width(); - bottomRightY = topLeftY + item->height(); - ++itemCount; - } if (itemCount == 0) { minX = topLeftX; maxX = bottomRightX; -- GitLab