From 61c82a08368f0347252059c1362d07dbf8a20558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 13 Mar 2016 17:44:25 +0100 Subject: [PATCH] Fixed (centred) waypoint position markers Fixed waypoint "radius" computation --- src/poi.cpp | 5 ++--- src/track.cpp | 2 +- src/trackview.cpp | 15 ++++++++------- src/waypointitem.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/poi.cpp b/src/poi.cpp index 88725432..37612670 100644 --- a/src/poi.cpp +++ b/src/poi.cpp @@ -46,8 +46,7 @@ bool POI::loadGPXFile(const QString &fileName) if (gpx.loadFile(fileName)) { for (int i = 0; i < gpx.waypoints().size(); i++) - _data.append(Waypoint( - ll2mercator(gpx.waypoints().at(i).coordinates()), + _data.append(Waypoint(gpx.waypoints().at(i).coordinates(), gpx.waypoints().at(i).description())); index.end = _data.size() - 1; @@ -108,7 +107,7 @@ bool POI::loadCSVFile(const QString &fileName) } QByteArray ba = list[2].trimmed(); - _data.append(Waypoint(ll2mercator(QPointF(lon, lat)), + _data.append(Waypoint(QPointF(lon, lat), QString::fromUtf8(ba.data(), ba.size()))); ln++; } diff --git a/src/track.cpp b/src/track.cpp index 20137ee8..f09215a3 100644 --- a/src/track.cpp +++ b/src/track.cpp @@ -124,7 +124,7 @@ void Track::speedGraph(QVector &graph) const void Track::track(QVector &track) const { for (int i = 0; i < _data.size(); i++) - track.append(ll2mercator(_data.at(i).coordinates)); + track.append(_data.at(i).coordinates); } qreal Track::distance() const diff --git a/src/trackview.cpp b/src/trackview.cpp index 2092e64b..1b53d5c1 100644 --- a/src/trackview.cpp +++ b/src/trackview.cpp @@ -55,9 +55,9 @@ void TrackView::addTrack(const QVector &track) _tracks.append(track); - path.moveTo(track.at(0).x(), -track.at(0).y()); + path.moveTo(ll2mercator(QPointF(track.at(0).x(), -track.at(0).y()))); for (int i = 1; i < track.size(); i++) - path.lineTo(track.at(i).x(), -track.at(i).y()); + path.lineTo(ll2mercator(QPointF(track.at(i).x(), -track.at(i).y()))); _maxLen = qMax(path.length(), _maxLen); @@ -167,8 +167,7 @@ void TrackView::rescale(qreal scale) QHash::const_iterator it, jt; for (it = _pois.constBegin(); it != _pois.constEnd(); it++) { - it.value()->setPos(QPointF(it.value()->entry().coordinates().x() - * 1.0/scale, -it.value()->entry().coordinates().y() * 1.0/scale)); + it.value()->setPos(it.value()->entry().coordinates() * 1.0/scale); it.value()->show(); } @@ -197,9 +196,11 @@ void TrackView::loadPOI(const POI &poi) if (_pois.contains(p.at(i))) continue; - WaypointItem *pi = new WaypointItem(p.at(i)); - pi->setPos(p.at(i).coordinates().x() * 1.0/_scale, - -p.at(i).coordinates().y() * 1.0/_scale); + WaypointItem *pi = new WaypointItem( + Waypoint(ll2mercator(QPointF(p.at(i).coordinates().x(), + -p.at(i).coordinates().y())), p.at(i).description())); + + pi->setPos(pi->entry().coordinates() * 1.0/_scale); pi->setZValue(1); _scene->addItem(pi); diff --git a/src/waypointitem.cpp b/src/waypointitem.cpp index 1758051d..297edfe6 100644 --- a/src/waypointitem.cpp +++ b/src/waypointitem.cpp @@ -20,8 +20,8 @@ void WaypointItem::updateBoundingRect() QFontMetrics fm(font); QRect ts = fm.tightBoundingRect(_entry.description()); - _boundingRect = QRectF(0, 0, ts.width() + POINT_SIZE, - ts.height() + fm.descent() + POINT_SIZE); + _boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width() + + POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE); } void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, @@ -36,10 +36,10 @@ void WaypointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti QRect ts = fm.tightBoundingRect(_entry.description()); painter->setFont(font); - painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(), + painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(), _entry.description()); painter->setBrush(Qt::SolidPattern); - painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE); + painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE); /* painter->setPen(Qt::red);