diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index e01664ca..95706e14 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -381,6 +381,11 @@ void GUI::createActions() _showGraphSliderInfoAction->setCheckable(true); connect(_showGraphSliderInfoAction, SIGNAL(triggered(bool)), this, SLOT(showGraphSliderInfo(bool))); + _showMarkersAction = new QAction(tr("Show path markers"), this); + _showMarkersAction->setMenuRole(QAction::NoRole); + _showMarkersAction->setCheckable(true); + connect(_showMarkersAction, SIGNAL(triggered(bool)), _mapView, + SLOT(showMarkers(bool))); // Settings actions _showToolbarsAction = new QAction(tr("Show toolbars"), this); @@ -505,6 +510,7 @@ void GUI::createMenus() graphMenu->addSeparator(); graphMenu->addAction(_showGraphGridAction); graphMenu->addAction(_showGraphSliderInfoAction); + graphMenu->addAction(_showMarkersAction); graphMenu->addSeparator(); graphMenu->addAction(_showGraphsAction); @@ -1683,6 +1689,9 @@ void GUI::writeSettings() != SHOW_GRAPH_SLIDER_INFO_DEFAULT) settings.setValue(SHOW_GRAPH_SLIDER_INFO_SETTING, _showGraphSliderInfoAction->isChecked()); + if (_showMarkersAction->isChecked() != SHOW_MARKERS_DEFAULT) + settings.setValue(SHOW_MARKERS_SETTING, + _showMarkersAction->isChecked()); settings.endGroup(); settings.beginGroup(POI_SETTINGS_GROUP); @@ -1911,6 +1920,10 @@ void GUI::readSettings() showGraphSliderInfo(false); else _showGraphSliderInfoAction->setChecked(true); + if (!settings.value(SHOW_MARKERS_SETTING, SHOW_MARKERS_DEFAULT).toBool()) + _mapView->showMarkers(false); + else + _showMarkersAction->setChecked(true); settings.endGroup(); settings.beginGroup(POI_SETTINGS_GROUP); diff --git a/src/GUI/gui.h b/src/GUI/gui.h index edfa7d31..4ef02e26 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -192,6 +192,7 @@ private: QAction *_showWaypointLabelsAction; QAction *_showAreasAction; QAction *_showRouteWaypointsAction; + QAction *_showMarkersAction; QAction *_openOptionsAction; QAction *_mapsEnd; QList _mapActions; diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index 1fc4d607..5b9d5937 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -65,6 +65,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) _showPOILabels = true; _overlapPOIs = true; _showRouteWaypoints = true; + _showMarkers = true; _trackWidth = 3; _routeWidth = 3; _trackStyle = Qt::SolidLine; @@ -113,6 +114,7 @@ PathItem *MapView::addTrack(const Track &track) ti->setVisible(_showTracks); ti->setDigitalZoom(_digitalZoom); ti->setMarkerColor(_markerColor); + ti->showMarker(_showMarkers); _scene->addItem(ti); if (_showTracks) @@ -141,6 +143,7 @@ PathItem *MapView::addRoute(const Route &route) ri->showWaypointLabels(_showWaypointLabels); ri->setDigitalZoom(_digitalZoom); ri->setMarkerColor(_markerColor); + ri->showMarker(_showMarkers); _scene->addItem(ri); if (_showRoutes) @@ -683,7 +686,6 @@ void MapView::showWaypointLabels(bool show) for (int i = 0; i < _waypoints.size(); i++) _waypoints.at(i)->showLabel(show); - for (int i = 0; i < _routes.size(); i++) _routes.at(i)->showWaypointLabels(show); } @@ -696,6 +698,16 @@ void MapView::showRouteWaypoints(bool show) _routes.at(i)->showWaypoints(show); } +void MapView::showMarkers(bool show) +{ + _showMarkers = show; + + for (int i = 0; i < _tracks.size(); i++) + _tracks.at(i)->showMarker(show); + for (int i = 0; i < _routes.size(); i++) + _routes.at(i)->showMarker(show); +} + void MapView::showMap(bool show) { _showMap = show; diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index ca7c0174..f0182827 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -74,6 +74,7 @@ public slots: void showAreas(bool show); void showWaypoints(bool show); void showRouteWaypoints(bool show); + void showMarkers(bool show); void clearMapCache(); void setCoordinatesFormat(CoordinatesFormat format); void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio); @@ -128,7 +129,8 @@ private: qreal _mapOpacity; bool _showMap, _showTracks, _showRoutes, _showAreas, _showWaypoints, - _showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints; + _showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints, + _showMarkers; bool _overlapPOIs; int _trackWidth, _routeWidth, _areaWidth; Qt::PenStyle _trackStyle, _routeStyle, _areaStyle; diff --git a/src/GUI/pathitem.cpp b/src/GUI/pathitem.cpp index 032bd769..9c6cc882 100644 --- a/src/GUI/pathitem.cpp +++ b/src/GUI/pathitem.cpp @@ -8,9 +8,9 @@ #define GEOGRAPHICAL_MILE 1855.3248 -static inline bool isInvalid(const QPointF &p) +static inline bool isValid(const QPointF &p) { - return (std::isnan(p.x()) || std::isnan(p.y())); + return (!std::isnan(p.x()) && !std::isnan(p.y())); } static inline unsigned segments(qreal distance) @@ -27,13 +27,14 @@ PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent) _width = 3; QBrush brush(Qt::SolidPattern); _pen = QPen(brush, _width); + _showMarker = true; updatePainterPath(); updateShape(); - _marker = new MarkerItem(this); - _marker->setPos(position(_path.first().first().distance())); _markerDistance = _path.first().first().distance(); + _marker = new MarkerItem(this); + _marker->setPos(position(_markerDistance)); setCursor(Qt::ArrowCursor); setAcceptHoverEvents(true); @@ -125,7 +126,9 @@ void PathItem::setMap(Map *map) updatePainterPath(); updateShape(); - _marker->setPos(position(_markerDistance)); + QPointF pos = position(_markerDistance); + if (isValid(pos)) + _marker->setPos(pos); } void PathItem::setColor(const QColor &color) @@ -244,15 +247,14 @@ QPointF PathItem::position(qreal x) const void PathItem::moveMarker(qreal distance) { + _markerDistance = distance; QPointF pos(position(distance)); - if (isInvalid(pos)) - _marker->setVisible(false); - else { - _marker->setVisible(true); + if (isValid(pos)) { + _marker->setVisible(_showMarker); _marker->setPos(pos); - _markerDistance = distance; - } + } else + _marker->setVisible(false); } void PathItem::setMarkerColor(const QColor &color) @@ -273,6 +275,15 @@ void PathItem::hover(bool hover) update(); } +void PathItem::showMarker(bool show) +{ + if (_showMarker == show) + return; + + _showMarker = show; + _marker->setVisible(show && isValid(position(_markerDistance))); +} + void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); diff --git a/src/GUI/pathitem.h b/src/GUI/pathitem.h index 1b6c5b82..b15bd25f 100644 --- a/src/GUI/pathitem.h +++ b/src/GUI/pathitem.h @@ -29,6 +29,7 @@ public: void setStyle(Qt::PenStyle style); void setDigitalZoom(int zoom); void setMarkerColor(const QColor &color); + void showMarker(bool show); public slots: void moveMarker(qreal distance); @@ -60,6 +61,7 @@ private: QPen _pen; QPainterPath _shape; QPainterPath _painterPath; + bool _showMarker; }; #endif // PATHITEM_H diff --git a/src/GUI/settings.h b/src/GUI/settings.h index b7d38322..447e73f3 100644 --- a/src/GUI/settings.h +++ b/src/GUI/settings.h @@ -29,6 +29,8 @@ #define SHOW_GRAPH_GRIDS_DEFAULT true #define SHOW_GRAPH_SLIDER_INFO_SETTING "sliderInfo" #define SHOW_GRAPH_SLIDER_INFO_DEFAULT true +#define SHOW_MARKERS_SETTING "pathMarkers" +#define SHOW_MARKERS_DEFAULT true #define MAP_SETTINGS_GROUP "Map" #define CURRENT_MAP_SETTING "map"