1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2017-12-01 20:52:34 +01:00
parent 56d1ac7ff2
commit 90b780a444
3 changed files with 21 additions and 30 deletions

View File

@ -154,7 +154,7 @@ void MapView::addWaypoints(const QList<Waypoint> &waypoints)
WaypointItem *wi = new WaypointItem(w, _map); WaypointItem *wi = new WaypointItem(w, _map);
_waypoints.append(wi); _waypoints.append(wi);
updateWaypointsBoundingRect(wi->waypoint().coordinates()); _wr.unite(wi->waypoint().coordinates());
wi->setZValue(1); wi->setZValue(1);
wi->setSize(_waypointSize); wi->setSize(_waypointSize);
wi->setColor(_waypointColor); wi->setColor(_waypointColor);
@ -193,33 +193,20 @@ QList<PathItem *> MapView::loadData(const Data &data)
return paths; return paths;
} }
void MapView::updateWaypointsBoundingRect(const Coordinates &wp)
{
if (_wr.isNull())
_wr = RectC(wp, wp);
else
_wr.unite(wp);
}
qreal MapView::mapZoom() const qreal MapView::mapZoom() const
{ {
RectC br; RectC br = _tr | _rr | _wr;
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN),
br = RectC(_map->xy2ll(sceneRect().topLeft()), br.isNull() ? RectC(_map->xy2ll(sceneRect().topLeft()),
_map->xy2ll(sceneRect().bottomRight())); _map->xy2ll(sceneRect().bottomRight())) : br);
else
br = _tr | _rr | _wr;
return _map->zoomFit(viewport()->size() - QSize(2*MARGIN, 2*MARGIN), br);
} }
QPointF MapView::contentCenter() const QPointF MapView::contentCenter() const
{ {
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty()) RectC br = _tr | _rr | _wr;
return sceneRect().center();
else return br.isNull() ? sceneRect().center() : _map->ll2xy(br.center());
return _map->ll2xy((_tr | _rr | _wr).center());
} }
void MapView::updatePOIVisibility() void MapView::updatePOIVisibility()

View File

@ -85,7 +85,6 @@ private:
void digitalZoom(int zoom); void digitalZoom(int zoom);
void resetDigitalZoom(); void resetDigitalZoom();
void updatePOIVisibility(); void updatePOIVisibility();
void updateWaypointsBoundingRect(const Coordinates &wp);
void mouseDoubleClickEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);

View File

@ -46,14 +46,19 @@ RectC RectC::operator|(const RectC &r) const
void RectC::unite(const Coordinates &c) void RectC::unite(const Coordinates &c)
{ {
if (c.lon() < _tl.lon()) if (isNull()) {
_tl.setLon(c.lon()); _tl = c;
if (c.lon() > _br.lon()) _br = c;
_br.setLon(c.lon()); } else {
if (c.lat() > _br.lat()) if (c.lon() < _tl.lon())
_br.setLat(c.lat()); _tl.setLon(c.lon());
if (c.lat() < _tl.lat()) if (c.lon() > _br.lon())
_tl.setLat(c.lat()); _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) QDebug operator<<(QDebug dbg, const RectC &rect)