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

Added the "Show map markers" setting.

This commit is contained in:
Martin Tůma 2019-02-16 12:39:23 +01:00
parent 4ab4ff9bf1
commit aaf8c12084
7 changed files with 56 additions and 13 deletions

View File

@ -381,6 +381,11 @@ void GUI::createActions()
_showGraphSliderInfoAction->setCheckable(true); _showGraphSliderInfoAction->setCheckable(true);
connect(_showGraphSliderInfoAction, SIGNAL(triggered(bool)), this, connect(_showGraphSliderInfoAction, SIGNAL(triggered(bool)), this,
SLOT(showGraphSliderInfo(bool))); 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 // Settings actions
_showToolbarsAction = new QAction(tr("Show toolbars"), this); _showToolbarsAction = new QAction(tr("Show toolbars"), this);
@ -505,6 +510,7 @@ void GUI::createMenus()
graphMenu->addSeparator(); graphMenu->addSeparator();
graphMenu->addAction(_showGraphGridAction); graphMenu->addAction(_showGraphGridAction);
graphMenu->addAction(_showGraphSliderInfoAction); graphMenu->addAction(_showGraphSliderInfoAction);
graphMenu->addAction(_showMarkersAction);
graphMenu->addSeparator(); graphMenu->addSeparator();
graphMenu->addAction(_showGraphsAction); graphMenu->addAction(_showGraphsAction);
@ -1683,6 +1689,9 @@ void GUI::writeSettings()
!= SHOW_GRAPH_SLIDER_INFO_DEFAULT) != SHOW_GRAPH_SLIDER_INFO_DEFAULT)
settings.setValue(SHOW_GRAPH_SLIDER_INFO_SETTING, settings.setValue(SHOW_GRAPH_SLIDER_INFO_SETTING,
_showGraphSliderInfoAction->isChecked()); _showGraphSliderInfoAction->isChecked());
if (_showMarkersAction->isChecked() != SHOW_MARKERS_DEFAULT)
settings.setValue(SHOW_MARKERS_SETTING,
_showMarkersAction->isChecked());
settings.endGroup(); settings.endGroup();
settings.beginGroup(POI_SETTINGS_GROUP); settings.beginGroup(POI_SETTINGS_GROUP);
@ -1911,6 +1920,10 @@ void GUI::readSettings()
showGraphSliderInfo(false); showGraphSliderInfo(false);
else else
_showGraphSliderInfoAction->setChecked(true); _showGraphSliderInfoAction->setChecked(true);
if (!settings.value(SHOW_MARKERS_SETTING, SHOW_MARKERS_DEFAULT).toBool())
_mapView->showMarkers(false);
else
_showMarkersAction->setChecked(true);
settings.endGroup(); settings.endGroup();
settings.beginGroup(POI_SETTINGS_GROUP); settings.beginGroup(POI_SETTINGS_GROUP);

View File

@ -192,6 +192,7 @@ private:
QAction *_showWaypointLabelsAction; QAction *_showWaypointLabelsAction;
QAction *_showAreasAction; QAction *_showAreasAction;
QAction *_showRouteWaypointsAction; QAction *_showRouteWaypointsAction;
QAction *_showMarkersAction;
QAction *_openOptionsAction; QAction *_openOptionsAction;
QAction *_mapsEnd; QAction *_mapsEnd;
QList<QAction*> _mapActions; QList<QAction*> _mapActions;

View File

@ -65,6 +65,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_showPOILabels = true; _showPOILabels = true;
_overlapPOIs = true; _overlapPOIs = true;
_showRouteWaypoints = true; _showRouteWaypoints = true;
_showMarkers = true;
_trackWidth = 3; _trackWidth = 3;
_routeWidth = 3; _routeWidth = 3;
_trackStyle = Qt::SolidLine; _trackStyle = Qt::SolidLine;
@ -113,6 +114,7 @@ PathItem *MapView::addTrack(const Track &track)
ti->setVisible(_showTracks); ti->setVisible(_showTracks);
ti->setDigitalZoom(_digitalZoom); ti->setDigitalZoom(_digitalZoom);
ti->setMarkerColor(_markerColor); ti->setMarkerColor(_markerColor);
ti->showMarker(_showMarkers);
_scene->addItem(ti); _scene->addItem(ti);
if (_showTracks) if (_showTracks)
@ -141,6 +143,7 @@ PathItem *MapView::addRoute(const Route &route)
ri->showWaypointLabels(_showWaypointLabels); ri->showWaypointLabels(_showWaypointLabels);
ri->setDigitalZoom(_digitalZoom); ri->setDigitalZoom(_digitalZoom);
ri->setMarkerColor(_markerColor); ri->setMarkerColor(_markerColor);
ri->showMarker(_showMarkers);
_scene->addItem(ri); _scene->addItem(ri);
if (_showRoutes) if (_showRoutes)
@ -683,7 +686,6 @@ void MapView::showWaypointLabels(bool show)
for (int i = 0; i < _waypoints.size(); i++) for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->showLabel(show); _waypoints.at(i)->showLabel(show);
for (int i = 0; i < _routes.size(); i++) for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->showWaypointLabels(show); _routes.at(i)->showWaypointLabels(show);
} }
@ -696,6 +698,16 @@ void MapView::showRouteWaypoints(bool show)
_routes.at(i)->showWaypoints(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) void MapView::showMap(bool show)
{ {
_showMap = show; _showMap = show;

View File

@ -74,6 +74,7 @@ public slots:
void showAreas(bool show); void showAreas(bool show);
void showWaypoints(bool show); void showWaypoints(bool show);
void showRouteWaypoints(bool show); void showRouteWaypoints(bool show);
void showMarkers(bool show);
void clearMapCache(); void clearMapCache();
void setCoordinatesFormat(CoordinatesFormat format); void setCoordinatesFormat(CoordinatesFormat format);
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio); void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
@ -128,7 +129,8 @@ private:
qreal _mapOpacity; qreal _mapOpacity;
bool _showMap, _showTracks, _showRoutes, _showAreas, _showWaypoints, bool _showMap, _showTracks, _showRoutes, _showAreas, _showWaypoints,
_showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints; _showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints,
_showMarkers;
bool _overlapPOIs; bool _overlapPOIs;
int _trackWidth, _routeWidth, _areaWidth; int _trackWidth, _routeWidth, _areaWidth;
Qt::PenStyle _trackStyle, _routeStyle, _areaStyle; Qt::PenStyle _trackStyle, _routeStyle, _areaStyle;

View File

@ -8,9 +8,9 @@
#define GEOGRAPHICAL_MILE 1855.3248 #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) static inline unsigned segments(qreal distance)
@ -27,13 +27,14 @@ PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
_width = 3; _width = 3;
QBrush brush(Qt::SolidPattern); QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, _width); _pen = QPen(brush, _width);
_showMarker = true;
updatePainterPath(); updatePainterPath();
updateShape(); updateShape();
_marker = new MarkerItem(this);
_marker->setPos(position(_path.first().first().distance()));
_markerDistance = _path.first().first().distance(); _markerDistance = _path.first().first().distance();
_marker = new MarkerItem(this);
_marker->setPos(position(_markerDistance));
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true); setAcceptHoverEvents(true);
@ -125,7 +126,9 @@ void PathItem::setMap(Map *map)
updatePainterPath(); updatePainterPath();
updateShape(); updateShape();
_marker->setPos(position(_markerDistance)); QPointF pos = position(_markerDistance);
if (isValid(pos))
_marker->setPos(pos);
} }
void PathItem::setColor(const QColor &color) void PathItem::setColor(const QColor &color)
@ -244,15 +247,14 @@ QPointF PathItem::position(qreal x) const
void PathItem::moveMarker(qreal distance) void PathItem::moveMarker(qreal distance)
{ {
_markerDistance = distance;
QPointF pos(position(distance)); QPointF pos(position(distance));
if (isInvalid(pos)) if (isValid(pos)) {
_marker->setVisible(false); _marker->setVisible(_showMarker);
else {
_marker->setVisible(true);
_marker->setPos(pos); _marker->setPos(pos);
_markerDistance = distance; } else
} _marker->setVisible(false);
} }
void PathItem::setMarkerColor(const QColor &color) void PathItem::setMarkerColor(const QColor &color)
@ -273,6 +275,15 @@ void PathItem::hover(bool hover)
update(); update();
} }
void PathItem::showMarker(bool show)
{
if (_showMarker == show)
return;
_showMarker = show;
_marker->setVisible(show && isValid(position(_markerDistance)));
}
void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);

View File

@ -29,6 +29,7 @@ public:
void setStyle(Qt::PenStyle style); void setStyle(Qt::PenStyle style);
void setDigitalZoom(int zoom); void setDigitalZoom(int zoom);
void setMarkerColor(const QColor &color); void setMarkerColor(const QColor &color);
void showMarker(bool show);
public slots: public slots:
void moveMarker(qreal distance); void moveMarker(qreal distance);
@ -60,6 +61,7 @@ private:
QPen _pen; QPen _pen;
QPainterPath _shape; QPainterPath _shape;
QPainterPath _painterPath; QPainterPath _painterPath;
bool _showMarker;
}; };
#endif // PATHITEM_H #endif // PATHITEM_H

View File

@ -29,6 +29,8 @@
#define SHOW_GRAPH_GRIDS_DEFAULT true #define SHOW_GRAPH_GRIDS_DEFAULT true
#define SHOW_GRAPH_SLIDER_INFO_SETTING "sliderInfo" #define SHOW_GRAPH_SLIDER_INFO_SETTING "sliderInfo"
#define SHOW_GRAPH_SLIDER_INFO_DEFAULT true #define SHOW_GRAPH_SLIDER_INFO_DEFAULT true
#define SHOW_MARKERS_SETTING "pathMarkers"
#define SHOW_MARKERS_DEFAULT true
#define MAP_SETTINGS_GROUP "Map" #define MAP_SETTINGS_GROUP "Map"
#define CURRENT_MAP_SETTING "map" #define CURRENT_MAP_SETTING "map"