1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Added position date display option

Closes #330
This commit is contained in:
Martin Tůma 2021-02-06 15:23:02 +01:00
parent 7bc1c53452
commit a369a1689d
12 changed files with 164 additions and 1 deletions

View File

@ -22,6 +22,7 @@ HEADERS += src/common/config.h \
src/GUI/mapaction.h \
src/GUI/mapitem.h \
src/GUI/marginswidget.h \
src/GUI/markerinfoitem.h \
src/GUI/planeitem.h \
src/GUI/popup.h \
src/common/garmin.h \
@ -214,6 +215,7 @@ SOURCES += src/main.cpp \
src/GUI/axislabelitem.cpp \
src/GUI/mapitem.cpp \
src/GUI/marginswidget.cpp \
src/GUI/markerinfoitem.cpp \
src/GUI/popup.cpp \
src/common/coordinates.cpp \
src/common/rectc.cpp \

View File

@ -379,6 +379,11 @@ void GUI::createActions()
_showMarkersAction->setCheckable(true);
connect(_showMarkersAction, SIGNAL(triggered(bool)), _mapView,
SLOT(showMarkers(bool)));
_showMarkerInfoAction = new QAction(tr("Position date/time"), this);
_showMarkerInfoAction->setMenuRole(QAction::NoRole);
_showMarkerInfoAction->setCheckable(true);
connect(_showMarkerInfoAction, SIGNAL(triggered(bool)), _mapView,
SLOT(showMarkerInfo(bool)));
// Graph actions
_showGraphsAction = new QAction(QIcon(SHOW_GRAPHS_ICON), tr("Show graphs"),
@ -564,6 +569,7 @@ void GUI::createMenus()
displayMenu->addAction(_showRouteWaypointsAction);
displayMenu->addAction(_showTicksAction);
displayMenu->addAction(_showMarkersAction);
displayMenu->addAction(_showMarkerInfoAction);
dataMenu->addSeparator();
dataMenu->addAction(_showTracksAction);
dataMenu->addAction(_showRoutesAction);
@ -1018,6 +1024,7 @@ void GUI::openOptions()
_mapView->setTimeZone(options.timeZone.zone());
_dateRange.first = _dateRange.first.toTimeZone(options.timeZone.zone());
_dateRange.second = _dateRange.second.toTimeZone(options.timeZone.zone());
reload = true;
}
if (reload)
@ -2006,6 +2013,9 @@ void GUI::writeSettings()
if (_showMarkersAction->isChecked() != SHOW_MARKERS_DEFAULT)
settings.setValue(SHOW_MARKERS_SETTING,
_showMarkersAction->isChecked());
if (_showMarkerInfoAction->isChecked() != SHOW_MARKER_INFO_DEFAULT)
settings.setValue(SHOW_MARKER_INFO_SETTING,
_showMarkerInfoAction->isChecked());
settings.endGroup();
settings.beginGroup(PDF_EXPORT_SETTINGS_GROUP);
@ -2303,6 +2313,11 @@ void GUI::readSettings()
_mapView->showMarkers(false);
else
_showMarkersAction->setChecked(true);
if (settings.value(SHOW_MARKER_INFO_SETTING,
SHOW_MARKER_INFO_DEFAULT).toBool()) {
_mapView->showMarkerInfo(true);
_showMarkerInfoAction->setChecked(true);
}
settings.endGroup();
settings.beginGroup(PDF_EXPORT_SETTINGS_GROUP);

View File

@ -206,6 +206,7 @@ private:
QAction *_showAreasAction;
QAction *_showRouteWaypointsAction;
QAction *_showMarkersAction;
QAction *_showMarkerInfoAction;
QAction *_showTicksAction;
QAction *_showCoordinatesAction;
QAction *_openOptionsAction;

View File

@ -93,6 +93,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_overlapPOIs = true;
_showRouteWaypoints = true;
_showMarkers = true;
_showMarkerInfo = false;
_showPathTicks = false;
_trackWidth = 3;
_routeWidth = 3;
@ -141,6 +142,7 @@ PathItem *MapView::addTrack(const Track &track)
ti->setDigitalZoom(_digitalZoom);
ti->setMarkerColor(_markerColor);
ti->showMarker(_showMarkers);
ti->showMarkerInfo(_showMarkerInfo);
ti->showTicks(_showPathTicks);
_scene->addItem(ti);
@ -169,6 +171,7 @@ PathItem *MapView::addRoute(const Route &route)
ri->setDigitalZoom(_digitalZoom);
ri->setMarkerColor(_markerColor);
ri->showMarker(_showMarkers);
ri->showMarkerInfo(_showMarkerInfo);
ri->showTicks(_showPathTicks);
_scene->addItem(ri);
@ -805,6 +808,16 @@ void MapView::showMarkers(bool show)
_routes.at(i)->showMarker(show);
}
void MapView::showMarkerInfo(bool show)
{
_showMarkerInfo = show;
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->showMarkerInfo(show);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->showMarkerInfo(show);
}
void MapView::showTicks(bool show)
{
_showPathTicks = show;

View File

@ -95,6 +95,7 @@ public slots:
void showCoordinates(bool show);
void showTicks(bool show);
void showMarkers(bool show);
void showMarkerInfo(bool show);
void showOverlappedPOIs(bool show);
void showWaypointLabels(bool show);
void showTracks(bool show);
@ -161,7 +162,7 @@ private:
bool _showMap, _showTracks, _showRoutes, _showAreas, _showWaypoints,
_showWaypointLabels, _showPOI, _showPOILabels, _showRouteWaypoints,
_showMarkers, _showPathTicks;
_showMarkers, _showMarkerInfo, _showPathTicks;
bool _overlapPOIs;
int _trackWidth, _routeWidth, _areaWidth;
Qt::PenStyle _trackStyle, _routeStyle, _areaStyle;

View File

@ -0,0 +1,73 @@
#include <QPainter>
#include <QDateTime>
#include <QLocale>
#include "font.h"
#include "markerinfoitem.h"
#define OFFSET 7
MarkerInfoItem::MarkerInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{
_color = Qt::red;
_font.setPixelSize(FONT_SIZE);
_font.setFamily(FONT_FAMILY);
}
void MarkerInfoItem::setDate(const QDateTime &date)
{
prepareGeometryChange();
QLocale l;
_date = l.toString(date.date(), QLocale::ShortFormat);
_time = l.toString(date.time(), QLocale::ShortFormat);
updateBoundingRect();
}
void MarkerInfoItem::updateBoundingRect()
{
QFontMetrics fm(_font);
qreal width = qMax(fm.boundingRect(_date).width(),
fm.boundingRect(_time).width());
qreal height = 2 * fm.height() - 2*fm.descent();
_boundingRect = QRectF(-OFFSET/2, -height/2, width + 1.5*OFFSET, height);
}
void MarkerInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QFontMetrics fm(_font);
QRectF ry(OFFSET, -fm.height() + fm.descent(),
fm.boundingRect(_time).width(), fm.height() - fm.descent());
QRectF rx(OFFSET, 0, fm.boundingRect(_date).width(), fm.height()
- fm.descent());
painter->setPen(Qt::NoPen);
QColor bc(painter->background().color());
bc.setAlpha(196);
painter->setBrush(QBrush(bc));
painter->drawRect(ry);
painter->drawRect(rx);
painter->setBrush(Qt::NoBrush);
painter->setFont(_font);
painter->setPen(_color);
painter->drawText(OFFSET, -fm.descent()/2, _date);
painter->drawText(OFFSET, fm.height() - fm.descent()*1.5, _time);
//painter->drawRect(boundingRect());
}
void MarkerInfoItem::setColor(const QColor &color)
{
_color = color;
update();
}

27
src/GUI/markerinfoitem.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef MARKERINFOITEM_H
#define MARKERINFOITEM_H
#include <QGraphicsItem>
class MarkerInfoItem : public QGraphicsItem
{
public:
MarkerInfoItem(QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setDate(const QDateTime &date);
void setColor(const QColor &color);
private:
void updateBoundingRect();
QString _date, _time;
QRectF _boundingRect;
QColor _color;
QFont _font;
};
#endif // MARKERINFOITEM_H

View File

@ -8,6 +8,7 @@
#include "popup.h"
#include "graphitem.h"
#include "markeritem.h"
#include "markerinfoitem.h"
#include "pathitem.h"
@ -52,6 +53,8 @@ PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
_marker = new MarkerItem(this);
_marker->setZValue(1);
_marker->setPos(position(_markerDistance));
_markerInfo = new MarkerInfoItem(_marker);
_markerInfo->setVisible(false);
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
@ -278,13 +281,26 @@ void PathItem::setMarkerPosition(qreal pos)
if (isValid(pp)) {
_marker->setVisible(_showMarker);
_marker->setPos(pp);
setMarkerInfo(pos);
} else
_marker->setVisible(false);
}
void PathItem::setMarkerInfo(qreal pos)
{
qreal time = _graph
? (_graph->graphType() == Time) ? pos : _graph->timeAtDistance(pos)
: NAN;
QDateTime d(date());
if (!std::isnan(time) && d.isValid())
_markerInfo->setDate(d.addSecs(time).toTimeZone(_timeZone));
}
void PathItem::setMarkerColor(const QColor &color)
{
_marker->setColor(color);
_markerInfo->setColor(color);
}
void PathItem::hover(bool hover)
@ -309,6 +325,11 @@ void PathItem::showMarker(bool show)
_marker->setVisible(show && isValid(position(_markerDistance)));
}
void PathItem::showMarkerInfo(bool show)
{
_markerInfo->setVisible(show);
}
qreal PathItem::xInM() const
{
return (_units == Nautical) ? NMIINM : (_units == Imperial) ? MIINM : KMINM;

View File

@ -12,6 +12,7 @@ class Map;
class PathTickItem;
class GraphItem;
class MarkerItem;
class MarkerInfoItem;
class PathItem : public QObject, public GraphicsItem
{
@ -26,6 +27,8 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
virtual QDateTime date() const = 0;
const Path &path() const {return _path;}
void addGraph(GraphItem *graph);
@ -39,6 +42,7 @@ public:
void setDigitalZoom(int zoom);
void setMarkerColor(const QColor &color);
void showMarker(bool show);
void showMarkerInfo(bool show);
void showTicks(bool show);
void setMarkerPosition(qreal pos);
@ -68,6 +72,7 @@ private:
void updatePainterPath();
void updateShape();
void addSegment(const Coordinates &c1, const Coordinates &c2);
void setMarkerInfo(qreal pos);
qreal xInM() const;
unsigned tickSize() const;
@ -87,6 +92,7 @@ private:
bool _showTicks;
MarkerItem *_marker;
MarkerInfoItem *_markerInfo;
QVector<PathTickItem*> _ticks;
};

View File

@ -21,6 +21,7 @@ public:
void showWaypointLabels(bool show);
QString info() const;
QDateTime date() const {return QDateTime();}
private:
QString _name;

View File

@ -65,6 +65,8 @@
#define SHOW_WAYPOINT_LABELS_DEFAULT true
#define SHOW_MARKERS_SETTING "positionMarkers"
#define SHOW_MARKERS_DEFAULT true
#define SHOW_MARKER_INFO_SETTING "markerInfo"
#define SHOW_MARKER_INFO_DEFAULT false
#define PDF_EXPORT_SETTINGS_GROUP "Export"
#define PAPER_ORIENTATION_SETTING "orientation"

View File

@ -16,6 +16,7 @@ public:
TrackItem(const Track &track, Map *map, QGraphicsItem *parent = 0);
QString info() const;
QDateTime date() const {return _date;}
private:
QString _name;