diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index ee2920ef..c11b886c 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -154,7 +154,7 @@ void MapView::addWaypoints(const QList &waypoints) WaypointItem *wi = new WaypointItem(w, _map); _waypoints.append(wi); - updateWaypointsBoundingRect(wi->waypoint().coordinates()); + _wr.unite(wi->waypoint().coordinates()); wi->setZValue(1); wi->setSize(_waypointSize); wi->setColor(_waypointColor); @@ -193,33 +193,20 @@ QList MapView::loadData(const Data &data) return paths; } -void MapView::updateWaypointsBoundingRect(const Coordinates &wp) -{ - if (_wr.isNull()) - _wr = RectC(wp, wp); - else - _wr.unite(wp); -} - qreal MapView::mapZoom() const { - RectC br; + RectC br = _tr | _rr | _wr; - if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) - br = RectC(_map->xy2ll(sceneRect().topLeft()), - _map->xy2ll(sceneRect().bottomRight())); - else - br = _tr | _rr | _wr; - - return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN), br); + return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN), + br.isNull() ? RectC(_map->xy2ll(sceneRect().topLeft()), + _map->xy2ll(sceneRect().bottomRight())) : br); } QPointF MapView::contentCenter() const { - if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) - return sceneRect().center(); - else - return _map->ll2xy((_tr | _rr | _wr).center()); + RectC br = _tr | _rr | _wr; + + return br.isNull() ? sceneRect().center() : _map->ll2xy(br.center()); } void MapView::updatePOIVisibility() diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index fc410aa3..089eb6d7 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -85,7 +85,6 @@ private: void digitalZoom(int zoom); void resetDigitalZoom(); void updatePOIVisibility(); - void updateWaypointsBoundingRect(const Coordinates &wp); void mouseDoubleClickEvent(QMouseEvent *event); void wheelEvent(QWheelEvent *event); diff --git a/src/common/rectc.cpp b/src/common/rectc.cpp index e4c29b46..8c042bd6 100644 --- a/src/common/rectc.cpp +++ b/src/common/rectc.cpp @@ -46,14 +46,19 @@ RectC RectC::operator|(const RectC &r) const void RectC::unite(const Coordinates &c) { - if (c.lon() < _tl.lon()) - _tl.setLon(c.lon()); - if (c.lon() > _br.lon()) - _br.setLon(c.lon()); - if (c.lat() > _br.lat()) - _br.setLat(c.lat()); - if (c.lat() < _tl.lat()) - _tl.setLat(c.lat()); + if (isNull()) { + _tl = c; + _br = c; + } else { + if (c.lon() < _tl.lon()) + _tl.setLon(c.lon()); + if (c.lon() > _br.lon()) + _br.setLon(c.lon()); + if (c.lat() > _br.lat()) + _br.setLat(c.lat()); + if (c.lat() < _tl.lat()) + _tl.setLat(c.lat()); + } } QDebug operator<<(QDebug dbg, const RectC &rect)