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

Fixed bounding rect computation in special case (rect + 1 waypoint)

This commit is contained in:
Martin Tůma 2017-01-09 00:20:06 +01:00
parent 7e6ed0933c
commit bd946fb477
2 changed files with 23 additions and 13 deletions

View File

@ -184,21 +184,13 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
const Waypoint &w = waypoints.at(i); const Waypoint &w = waypoints.at(i);
WaypointItem *wi = new WaypointItem(w); WaypointItem *wi = new WaypointItem(w);
_waypoints.append(wi);
updateWaypointsBoundingRect(wi->coordinates());
wi->setScale(1.0/scale); wi->setScale(1.0/scale);
wi->setZValue(1); wi->setZValue(1);
wi->showLabel(_showWaypointLabels); wi->showLabel(_showWaypointLabels);
wi->setVisible(_showWaypoints); wi->setVisible(_showWaypoints);
_scene->addItem(wi); _scene->addItem(wi);
if (_wr.isNull()) {
if (_wp.isNull())
_wp = wi->coordinates();
else
_wr = qrectf(_wp, wi->coordinates());
} else
unite(_wr, wi->coordinates());
_waypoints.append(wi);
} }
if (_poi) if (_poi)
@ -239,9 +231,24 @@ QList<PathItem *> PathView::loadData(const Data &data)
return paths; return paths;
} }
void PathView::updateWaypointsBoundingRect(const QPointF &wp)
{
if (_wr.isNull()) {
if (_wp.isNull())
_wp = wp;
else {
_wr = qrectf(_wp, wp);
_wp = QPointF();
}
} else
unite(_wr, wp);
}
qreal PathView::contentsScale() const qreal PathView::contentsScale() const
{ {
QRectF br = _tr | _rr | _wr; QRectF br = _tr | _rr | _wr;
if (!br.isNull() && !_wp.isNull())
unite(br, _wp);
if (br.isNull()) if (br.isNull())
return mapScale(ZOOM_MAX); return mapScale(ZOOM_MAX);
@ -255,14 +262,16 @@ qreal PathView::contentsScale() const
QRectF PathView::contentsSceneRect() const QRectF PathView::contentsSceneRect() const
{ {
qreal scale = mapScale(_zoom); qreal scale = mapScale(_zoom);
QRectF br = scaled(_tr | _rr | _wr, 1.0/scale); QRectF br = _tr | _rr | _wr;
if (!br.isNull() && !_wp.isNull())
unite(br, _wp);
if (br.isNull()) if (br.isNull())
return QRectF(QPointF(_wp.x() / scale - Tile::size()/2, return QRectF(QPointF(_wp.x() / scale - Tile::size()/2,
_wp.y() /scale - Tile::size()/2), QSizeF(Tile::size(), Tile::size())); _wp.y() /scale - Tile::size()/2), QSizeF(Tile::size(), Tile::size()));
else else
return br.adjusted(-Tile::size(), -Tile::size(), Tile::size(), return scaled(br, 1.0/scale).adjusted(-Tile::size(), -Tile::size(),
Tile::size()); Tile::size(), Tile::size());
} }
void PathView::updatePOIVisibility() void PathView::updatePOIVisibility()

View File

@ -78,6 +78,7 @@ private:
void rescale(); void rescale();
void zoom(int z, const QPoint &pos); void zoom(int z, const QPoint &pos);
void updatePOIVisibility(); void updatePOIVisibility();
void updateWaypointsBoundingRect(const QPointF &wp);
void mouseDoubleClickEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);