From bd946fb477cdb8fd691fe267125011acf68ea80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 9 Jan 2017 00:20:06 +0100 Subject: [PATCH] Fixed bounding rect computation in special case (rect + 1 waypoint) --- src/pathview.cpp | 35 ++++++++++++++++++++++------------- src/pathview.h | 1 + 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/pathview.cpp b/src/pathview.cpp index 70b87c75..5001da40 100644 --- a/src/pathview.cpp +++ b/src/pathview.cpp @@ -184,21 +184,13 @@ void PathView::addWaypoints(const QList &waypoints) const Waypoint &w = waypoints.at(i); WaypointItem *wi = new WaypointItem(w); + _waypoints.append(wi); + updateWaypointsBoundingRect(wi->coordinates()); wi->setScale(1.0/scale); wi->setZValue(1); wi->showLabel(_showWaypointLabels); wi->setVisible(_showWaypoints); _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) @@ -239,9 +231,24 @@ QList PathView::loadData(const Data &data) 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 { QRectF br = _tr | _rr | _wr; + if (!br.isNull() && !_wp.isNull()) + unite(br, _wp); if (br.isNull()) return mapScale(ZOOM_MAX); @@ -255,14 +262,16 @@ qreal PathView::contentsScale() const QRectF PathView::contentsSceneRect() const { 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()) return QRectF(QPointF(_wp.x() / scale - Tile::size()/2, _wp.y() /scale - Tile::size()/2), QSizeF(Tile::size(), Tile::size())); else - return br.adjusted(-Tile::size(), -Tile::size(), Tile::size(), - Tile::size()); + return scaled(br, 1.0/scale).adjusted(-Tile::size(), -Tile::size(), + Tile::size(), Tile::size()); } void PathView::updatePOIVisibility() diff --git a/src/pathview.h b/src/pathview.h index 06914804..a824b320 100644 --- a/src/pathview.h +++ b/src/pathview.h @@ -78,6 +78,7 @@ private: void rescale(); void zoom(int z, const QPoint &pos); void updatePOIVisibility(); + void updateWaypointsBoundingRect(const QPointF &wp); void mouseDoubleClickEvent(QMouseEvent *event); void wheelEvent(QWheelEvent *event);