1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Redesigned obscure position marker handling

This commit is contained in:
Martin Tůma 2016-08-10 20:35:39 +02:00
parent 36083d2fa1
commit 392b829733
6 changed files with 31 additions and 38 deletions

View File

@ -26,6 +26,8 @@ RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
wi->setParentItem(this); wi->setParentItem(this);
} }
_distance = route.distance();
QBrush brush(Qt::SolidPattern); QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, ROUTE_WIDTH, Qt::DotLine); _pen = QPen(brush, ROUTE_WIDTH, Qt::DotLine);
@ -66,10 +68,14 @@ void RouteItem::setColor(const QColor &color)
update(); update();
} }
void RouteItem::moveMarker(qreal t) void RouteItem::moveMarker(qreal distance)
{ {
Q_ASSERT(t >= 0 && t <= 1.0); if (distance > _distance)
_marker->setPos(_path.pointAtPercent(t)); _marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
} }
void RouteItem::showWaypoints(bool show) void RouteItem::showWaypoints(bool show)

View File

@ -20,7 +20,7 @@ public:
void setColor(const QColor &color); void setColor(const QColor &color);
void showMarker(bool show) {_marker->setVisible(show);} void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal t); void moveMarker(qreal distance);
void showWaypoints(bool show); void showWaypoints(bool show);
void showWaypointLabels(bool show); void showWaypointLabels(bool show);
@ -30,6 +30,8 @@ private:
QPen _pen; QPen _pen;
MarkerItem *_marker; MarkerItem *_marker;
qreal _distance;
}; };
#endif // ROUTEITEM_H #endif // ROUTEITEM_H

View File

@ -99,8 +99,12 @@ void TrackItem::setUnits(enum Units units)
setToolTip(toolTip()); setToolTip(toolTip());
} }
void TrackItem::moveMarker(qreal t) void TrackItem::moveMarker(qreal distance)
{ {
Q_ASSERT(t >= 0 && t <= 1.0); if (distance > _distance)
_marker->setPos(_path.pointAtPercent(t)); _marker->setVisible(false);
else {
_marker->setVisible(true);
_marker->setPos(_path.pointAtPercent(distance / _distance));
}
} }

View File

@ -25,7 +25,7 @@ public:
void setColor(const QColor &color); void setColor(const QColor &color);
void showMarker(bool show) {_marker->setVisible(show);} void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal t); void moveMarker(qreal distance);
private: private:
void updateShape(); void updateShape();

View File

@ -34,8 +34,6 @@ TrackView::TrackView(QWidget *parent)
_zoom = ZOOM_MAX; _zoom = ZOOM_MAX;
_scale = mapScale(_zoom); _scale = mapScale(_zoom);
_map = 0; _map = 0;
_maxPath = 0;
_maxDistance = 0;
_units = Metric; _units = Metric;
@ -48,6 +46,7 @@ TrackView::TrackView(QWidget *parent)
_showRouteWaypoints = true; _showRouteWaypoints = true;
_plot = false; _plot = false;
_markerPos = 0;
} }
TrackView::~TrackView() TrackView::~TrackView()
@ -70,10 +69,8 @@ void TrackView::addTrack(const Track &track)
ti->setScale(1.0/_scale); ti->setScale(1.0/_scale);
ti->setColor(_palette.color()); ti->setColor(_palette.color());
ti->setVisible(_showTracks); ti->setVisible(_showTracks);
ti->moveMarker(_markerPos);
_scene->addItem(ti); _scene->addItem(ti);
_maxPath = qMax(ti->path().length(), _maxPath);
_maxDistance = qMax(track.distance(), _maxDistance);
} }
void TrackView::addRoute(const Route &route) void TrackView::addRoute(const Route &route)
@ -92,10 +89,8 @@ void TrackView::addRoute(const Route &route)
ri->setVisible(_showRoutes); ri->setVisible(_showRoutes);
ri->showWaypoints(_showRouteWaypoints); ri->showWaypoints(_showRouteWaypoints);
ri->showWaypointLabels(_showWaypointLabels); ri->showWaypointLabels(_showWaypointLabels);
ri->moveMarker(_markerPos);
_scene->addItem(ri); _scene->addItem(ri);
_maxPath = qMax(ri->path().length(), _maxPath);
_maxDistance = qMax(route.distance(), _maxDistance);
} }
void TrackView::addWaypoints(const QList<Waypoint> &waypoints) void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
@ -478,37 +473,23 @@ void TrackView::clear()
_scene->clear(); _scene->clear();
_palette.reset(); _palette.reset();
_maxPath = 0;
_maxDistance = 0;
_zoom = ZOOM_MAX; _zoom = ZOOM_MAX;
_scale = mapScale(_zoom); _scale = mapScale(_zoom);
_scene->setSceneRect(QRectF()); _scene->setSceneRect(QRectF());
_markerPos = 0;
} }
void TrackView::movePositionMarker(qreal val) void TrackView::movePositionMarker(qreal val)
{ {
qreal mp = val / _maxDistance; _markerPos = val;
for (int i = 0; i < _tracks.size(); i++) { for (int i = 0; i < _tracks.size(); i++)
qreal f = _maxPath / _tracks.at(i)->path().length(); _tracks.at(i)->moveMarker(val);
if (mp * f < 0 || mp * f > 1.0)
_tracks.at(i)->showMarker(false);
else {
_tracks.at(i)->moveMarker(mp * f);
_tracks.at(i)->showMarker(true);
}
}
for (int i = 0; i < _routes.size(); i++) { for (int i = 0; i < _routes.size(); i++)
qreal f = _maxPath / _routes.at(i)->path().length(); _routes.at(i)->moveMarker(val);
if (mp * f < 0 || mp * f > 1.0)
_routes.at(i)->showMarker(false);
else {
_routes.at(i)->moveMarker(mp * f);
_routes.at(i)->showMarker(true);
}
}
} }
void TrackView::showTracks(bool show) void TrackView::showTracks(bool show)

View File

@ -88,7 +88,6 @@ private:
ScaleItem *_mapScale; ScaleItem *_mapScale;
Palette _palette; Palette _palette;
qreal _maxPath, _maxDistance;
qreal _scale; qreal _scale;
int _zoom; int _zoom;
@ -104,6 +103,7 @@ private:
bool _showRouteWaypoints; bool _showRouteWaypoints;
bool _plot; bool _plot;
qreal _markerPos;
}; };
#endif // TRACKVIEW_H #endif // TRACKVIEW_H