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

Added support for GPX routes

This commit is contained in:
Martin Tůma 2016-08-09 01:16:19 +02:00
parent 5912506292
commit dad85e46a7
28 changed files with 853 additions and 296 deletions

View File

@ -47,7 +47,9 @@ HEADERS += src/config.h \
src/graphtab.h \
src/misc.h \
src/trackitem.h \
src/tooltip.h
src/tooltip.h \
src/route.h \
src/routeitem.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
@ -82,7 +84,9 @@ SOURCES += src/main.cpp \
src/misc.cpp \
src/waypoint.cpp \
src/trackitem.cpp \
src/tooltip.cpp
src/tooltip.cpp \
src/route.cpp \
src/routeitem.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx {

View File

@ -163,17 +163,17 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/gui.cpp" line="446"/>
<location filename="../src/gui.cpp" line="477"/>
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="510"/>
<location filename="../src/gui.cpp" line="541"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="586"/>
<location filename="../src/gui.cpp" line="617"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
@ -189,8 +189,8 @@
</message>
<message>
<location filename="../src/gui.cpp" line="186"/>
<location filename="../src/gui.cpp" line="462"/>
<location filename="../src/gui.cpp" line="463"/>
<location filename="../src/gui.cpp" line="493"/>
<location filename="../src/gui.cpp" line="494"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
@ -205,20 +205,20 @@
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="378"/>
<location filename="../src/gui.cpp" line="409"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="317"/>
<location filename="../src/gui.cpp" line="372"/>
<location filename="../src/gui.cpp" line="339"/>
<location filename="../src/gui.cpp" line="403"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="184"/>
<location filename="../src/gui.cpp" line="485"/>
<location filename="../src/gui.cpp" line="486"/>
<location filename="../src/gui.cpp" line="516"/>
<location filename="../src/gui.cpp" line="517"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
@ -238,125 +238,150 @@
<translation>Překrývat POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="234"/>
<location filename="../src/gui.cpp" line="233"/>
<source>Show POI labels</source>
<translation>Zobrazovat názvy POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="238"/>
<source>Show POIs</source>
<translation>Zobrazit POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="242"/>
<location filename="../src/gui.cpp" line="246"/>
<source>Show map</source>
<translation>Zobrazit mapu</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="248"/>
<location filename="../src/gui.cpp" line="252"/>
<source>Clear tile cache</source>
<translation>Vymazat mezipaměť dlaždic</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="257"/>
<location filename="../src/gui.cpp" line="261"/>
<location filename="../src/gui.cpp" line="472"/>
<location filename="../src/gui.cpp" line="265"/>
<location filename="../src/gui.cpp" line="503"/>
<source>Next map</source>
<translation>Následující mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="268"/>
<location filename="../src/gui.cpp" line="272"/>
<source>Show tracks</source>
<translation>Zobrazit cesty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="276"/>
<source>Show routes</source>
<translation>Zobrazit trasy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="280"/>
<source>Show waypoints</source>
<translation>Zobrazit navigační body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="290"/>
<source>Show graphs</source>
<translation>Zobrazovat grafy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="274"/>
<location filename="../src/gui.cpp" line="296"/>
<source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="280"/>
<location filename="../src/gui.cpp" line="302"/>
<source>Metric</source>
<translation>Metrické</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="285"/>
<location filename="../src/gui.cpp" line="307"/>
<source>Imperial</source>
<translation>Imperiální</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="291"/>
<location filename="../src/gui.cpp" line="313"/>
<source>Fullscreen mode</source>
<translation>Celoobrazovkový režim</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="299"/>
<location filename="../src/gui.cpp" line="321"/>
<source>Next</source>
<translation>Následující</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="302"/>
<location filename="../src/gui.cpp" line="324"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="306"/>
<location filename="../src/gui.cpp" line="328"/>
<source>Last</source>
<translation>Poslední</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="309"/>
<location filename="../src/gui.cpp" line="331"/>
<source>First</source>
<translation>První</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="331"/>
<location filename="../src/gui.cpp" line="353"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="338"/>
<location filename="../src/gui.cpp" line="360"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="339"/>
<location filename="../src/gui.cpp" line="361"/>
<source>POI files</source>
<translation>POI soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="349"/>
<location filename="../src/gui.cpp" line="372"/>
<source>Data</source>
<translation>Data</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="380"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="350"/>
<location filename="../src/gui.cpp" line="381"/>
<source>Units</source>
<translation>Jednotky</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="359"/>
<location filename="../src/gui.cpp" line="390"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="474"/>
<location filename="../src/gui.cpp" line="505"/>
<source>Previous map</source>
<translation>Předchozí mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="672"/>
<location filename="../src/gui.cpp" line="675"/>
<location filename="../src/gui.cpp" line="703"/>
<location filename="../src/gui.cpp" line="706"/>
<source>Date</source>
<translation>Datum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="853"/>
<location filename="../src/gui.cpp" line="884"/>
<source>No GPX files loaded</source>
<translation>Nejsou načteny žádné GPX soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="465"/>
<location filename="../src/gui.cpp" line="496"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="442"/>
<location filename="../src/gui.cpp" line="473"/>
<source>Version </source>
<translation>Verze </translation>
</message>
@ -371,123 +396,133 @@
<translation>Exportovat do PDF...</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="466"/>
<location filename="../src/gui.cpp" line="284"/>
<source>Show waypoint labels</source>
<translation>Zobrazovat názvy navigačních bodů</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="377"/>
<source>Rendering</source>
<translation>Zobrazení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="497"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="468"/>
<location filename="../src/gui.cpp" line="499"/>
<source>First file</source>
<translation>První soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="469"/>
<location filename="../src/gui.cpp" line="500"/>
<source>Last file</source>
<translation>Poslední soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="470"/>
<location filename="../src/gui.cpp" line="501"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="489"/>
<location filename="../src/gui.cpp" line="520"/>
<source>Map (tiles) source URLs are read on program startup from the following file:</source>
<translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="492"/>
<location filename="../src/gui.cpp" line="523"/>
<source>The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like:</source>
<translation>Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="500"/>
<location filename="../src/gui.cpp" line="531"/>
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source>
<translation>POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="511"/>
<location filename="../src/gui.cpp" line="542"/>
<source>GPX files (*.gpx);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="577"/>
<location filename="../src/gui.cpp" line="603"/>
<location filename="../src/gui.cpp" line="608"/>
<location filename="../src/gui.cpp" line="634"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="587"/>
<location filename="../src/gui.cpp" line="618"/>
<source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="678"/>
<location filename="../src/gui.cpp" line="709"/>
<source>Tracks</source>
<translation>Počet tras</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="684"/>
<location filename="../src/gui.cpp" line="715"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="189"/>
<location filename="../src/gui.cpp" line="440"/>
<location filename="../src/gui.cpp" line="471"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="382"/>
<location filename="../src/gui.cpp" line="413"/>
<source>Navigation</source>
<translation>Navigace</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="488"/>
<location filename="../src/gui.cpp" line="519"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="499"/>
<location filename="../src/gui.cpp" line="530"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="683"/>
<location filename="../src/gui.cpp" line="686"/>
<location filename="../src/gui.cpp" line="714"/>
<location filename="../src/gui.cpp" line="717"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="691"/>
<location filename="../src/gui.cpp" line="722"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="860"/>
<location filename="../src/gui.cpp" line="891"/>
<source>%1 tracks</source>
<translation>Počet tras: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="687"/>
<location filename="../src/gui.cpp" line="718"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="579"/>
<location filename="../src/gui.cpp" line="604"/>
<location filename="../src/gui.cpp" line="610"/>
<location filename="../src/gui.cpp" line="635"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="574"/>
<location filename="../src/gui.cpp" line="605"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="600"/>
<location filename="../src/gui.cpp" line="631"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
@ -725,22 +760,27 @@
<context>
<name>WaypointItem</name>
<message>
<location filename="../src/waypointitem.cpp" line="16"/>
<location filename="../src/waypointitem.cpp" line="17"/>
<source>Name</source>
<translation>Název</translation>
</message>
<message>
<location filename="../src/waypointitem.cpp" line="18"/>
<source>Coordinates</source>
<translation>Souřadnice</translation>
</message>
<message>
<location filename="../src/waypointitem.cpp" line="19"/>
<location filename="../src/waypointitem.cpp" line="21"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/waypointitem.cpp" line="22"/>
<location filename="../src/waypointitem.cpp" line="24"/>
<source>Date</source>
<translation>Datum</translation>
</message>
<message>
<location filename="../src/waypointitem.cpp" line="25"/>
<location filename="../src/waypointitem.cpp" line="27"/>
<source>Description</source>
<translation>Popis</translation>
</message>

View File

@ -17,7 +17,7 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphTab(parent)
setMinYRange(50.0);
}
void ElevationGraph::addInfo()
void ElevationGraph::setInfo()
{
GraphView::addInfo(tr("Ascent"), QString::number(_ascent * yScale(), 'f', 0)
+ UNIT_SPACE + yUnits());
@ -27,20 +27,15 @@ void ElevationGraph::addInfo()
+ UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale(), 'f', 0)
+ UNIT_SPACE + yUnits());
redraw();
}
void ElevationGraph::loadGPX(const GPX &gpx)
void ElevationGraph::loadPath(const QVector<QPointF> &data)
{
for (int i = 0; i < gpx.trackCount(); i++) {
QVector<QPointF> data;
qreal ascent = 0, descent = 0;
gpx.track(i).elevationGraph(data);
if (data.count() < 2) {
skipColor();
continue;
return;
}
for (int j = 1; j < data.size(); j++) {
@ -59,8 +54,24 @@ void ElevationGraph::loadGPX(const GPX &gpx)
loadData(data);
}
void ElevationGraph::loadGPX(const GPX &gpx)
{
for (int i = 0; i < gpx.trackCount(); i++) {
QVector<QPointF> data;
gpx.track(i).elevationGraph(data);
loadPath(data);
}
for (int i = 0; i < gpx.routeCount(); i++) {
QVector<QPointF> data;
gpx.route(i).elevationGraph(data);
loadPath(data);
}
setXUnits();
addInfo();
setInfo();
redraw();
}
void ElevationGraph::clear()
@ -106,9 +117,10 @@ void ElevationGraph::setYUnits()
void ElevationGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
setInfo();
clearInfo();
addInfo();
redraw();
}

View File

@ -25,7 +25,9 @@ private:
void setXUnits();
void setYUnits();
void addInfo();
void setInfo();
void loadPath(const QVector<QPointF> &data);
qreal _ascent, _descent;
enum Units _units;

View File

@ -7,18 +7,21 @@
#include <QString>
#include "waypoint.h"
#include "track.h"
#include "route.h"
#include "parser.h"
class GPX
{
public:
GPX() : _parser(_tracks, _waypoints), _errorLine(0) {}
GPX() : _parser(_tracks, _routes, _waypoints), _errorLine(0) {}
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
int errorLine() const {return _errorLine;}
int trackCount() const {return _tracks.count();}
Track track(int i) const {return Track(_tracks.at(i));}
int routeCount() const {return _routes.count();}
Route route(int i) const {return Route(_routes.at(i));}
const QList<Waypoint> &waypoints() const {return _waypoints;}
private:
@ -27,6 +30,7 @@ private:
int _errorLine;
QList<QVector<Trackpoint> > _tracks;
QList<QVector<Waypoint> > _routes;
QList<Waypoint> _waypoints;
};

View File

@ -44,12 +44,12 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
loadMaps();
loadPOIs();
createActions();
createMenus();
createToolBars();
createTrackView();
createTrackGraphs();
createStatusBar();
createActions();
createMenus();
createToolBars();
_browser = new FileBrowser(this);
_browser->setFilter(QStringList("*.gpx"));
@ -189,7 +189,7 @@ void GUI::createActions()
tr("About GPXSee"), this);
connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
// File related actions
// File actions
_openFileAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
tr("Open"), this);
_openFileAction->setShortcut(OPEN_SHORTCUT);
@ -228,8 +228,12 @@ void GUI::createActions()
connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles()));
_overlapPOIAction = new QAction(tr("Overlap POIs"), this);
_overlapPOIAction->setCheckable(true);
connect(_overlapPOIAction, SIGNAL(triggered(bool)), this,
SLOT(overlapPOIs(bool)));
connect(_overlapPOIAction, SIGNAL(triggered(bool)), _track,
SLOT(setPOIOverlap(bool)));
_showPOILabelsAction = new QAction(tr("Show POI labels"), this);
_showPOILabelsAction->setCheckable(true);
connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _track,
SLOT(showPOILabels(bool)));
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
tr("Show POIs"), this);
_showPOIAction->setCheckable(true);
@ -264,6 +268,24 @@ void GUI::createActions()
addAction(_prevMapAction);
}
// Data actions
_showTracksAction = new QAction(tr("Show tracks"), this);
_showTracksAction->setCheckable(true);
connect(_showTracksAction, SIGNAL(triggered(bool)), _track,
SLOT(showTracks(bool)));
_showRoutesAction = new QAction(tr("Show routes"), this);
_showRoutesAction->setCheckable(true);
connect(_showRoutesAction, SIGNAL(triggered(bool)), _track,
SLOT(showRoutes(bool)));
_showWaypointsAction = new QAction(tr("Show waypoints"), this);
_showWaypointsAction->setCheckable(true);
connect(_showWaypointsAction, SIGNAL(triggered(bool)), _track,
SLOT(showWaypoints(bool)));
_showWaypointLabelsAction = new QAction(tr("Show waypoint labels"), this);
_showWaypointLabelsAction->setCheckable(true);
connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _track,
SLOT(showWaypointLabels(bool)));
// Settings actions
_showGraphsAction = new QAction(tr("Show graphs"), this);
_showGraphsAction->setCheckable(true);
@ -314,53 +336,62 @@ void GUI::createActions()
void GUI::createMenus()
{
_fileMenu = menuBar()->addMenu(tr("File"));
_fileMenu->addAction(_openFileAction);
_fileMenu->addSeparator();
_fileMenu->addAction(_printFileAction);
_fileMenu->addAction(_exportFileAction);
_fileMenu->addSeparator();
_fileMenu->addAction(_reloadFileAction);
_fileMenu->addSeparator();
_fileMenu->addAction(_closeFileAction);
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(_openFileAction);
fileMenu->addSeparator();
fileMenu->addAction(_printFileAction);
fileMenu->addAction(_exportFileAction);
fileMenu->addSeparator();
fileMenu->addAction(_reloadFileAction);
fileMenu->addSeparator();
fileMenu->addAction(_closeFileAction);
#ifndef Q_OS_MAC
_fileMenu->addSeparator();
_fileMenu->addAction(_exitAction);
fileMenu->addSeparator();
fileMenu->addAction(_exitAction);
#endif // Q_OS_MAC
_mapMenu = menuBar()->addMenu(tr("Map"));
_mapMenu->addActions(_mapActions);
_mapMenu->addSeparator();
_mapMenu->addAction(_clearMapCacheAction);
_mapMenu->addSeparator();
_mapMenu->addAction(_showMapAction);
QMenu *mapMenu = menuBar()->addMenu(tr("Map"));
mapMenu->addActions(_mapActions);
mapMenu->addSeparator();
mapMenu->addAction(_clearMapCacheAction);
mapMenu->addSeparator();
mapMenu->addAction(_showMapAction);
_poiMenu = menuBar()->addMenu(tr("POI"));
_poiFilesMenu = _poiMenu->addMenu(tr("POI files"));
QMenu *poiMenu = menuBar()->addMenu(tr("POI"));
_poiFilesMenu = poiMenu->addMenu(tr("POI files"));
_poiFilesMenu->addActions(_poiFilesActions);
_poiMenu->addSeparator();
_poiMenu->addAction(_openPOIAction);
_poiMenu->addAction(_closePOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_overlapPOIAction);
_poiMenu->addSeparator();
_poiMenu->addAction(_showPOIAction);
poiMenu->addSeparator();
poiMenu->addAction(_openPOIAction);
poiMenu->addAction(_closePOIAction);
poiMenu->addSeparator();
poiMenu->addAction(_showPOILabelsAction);
poiMenu->addAction(_overlapPOIAction);
poiMenu->addSeparator();
poiMenu->addAction(_showPOIAction);
_settingsMenu = menuBar()->addMenu(tr("Settings"));
_unitsMenu = _settingsMenu->addMenu(tr("Units"));
_unitsMenu->addAction(_metricUnitsAction);
_unitsMenu->addAction(_imperialUnitsAction);
_settingsMenu->addSeparator();
_settingsMenu->addAction(_showToolbarsAction);
_settingsMenu->addAction(_showGraphsAction);
_settingsMenu->addSeparator();
_settingsMenu->addAction(_fullscreenAction);
QMenu *dataMenu = menuBar()->addMenu(tr("Data"));
dataMenu->addAction(_showTracksAction);
dataMenu->addAction(_showRoutesAction);
dataMenu->addAction(_showWaypointsAction);
dataMenu->addSeparator();
QMenu *displayMenu = dataMenu->addMenu(tr("Rendering"));
displayMenu->addAction(_showWaypointLabelsAction);
_helpMenu = menuBar()->addMenu(tr("Help"));
_helpMenu->addAction(_dataSourcesAction);
_helpMenu->addAction(_keysAction);
_helpMenu->addSeparator();
_helpMenu->addAction(_aboutAction);
QMenu *settingsMenu = menuBar()->addMenu(tr("Settings"));
QMenu *unitsMenu = settingsMenu->addMenu(tr("Units"));
unitsMenu->addAction(_metricUnitsAction);
unitsMenu->addAction(_imperialUnitsAction);
settingsMenu->addSeparator();
settingsMenu->addAction(_showToolbarsAction);
settingsMenu->addAction(_showGraphsAction);
settingsMenu->addSeparator();
settingsMenu->addAction(_fullscreenAction);
QMenu *helpMenu = menuBar()->addMenu(tr("Help"));
helpMenu->addAction(_dataSourcesAction);
helpMenu->addAction(_keysAction);
helpMenu->addSeparator();
helpMenu->addAction(_aboutAction);
}
void GUI::createToolBars()
@ -706,8 +737,8 @@ void GUI::plot(QPrinter *printer)
? 0.15 * r * (printer->height() - ih - 2*mh)
: 0.15 * (printer->height() - ih - 2*mh);
gh = qMax(gh, ratio * 150);
GraphView *gv = static_cast<GraphView*>(_trackGraphs->currentWidget());
gv->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
GraphTab *gt = static_cast<GraphTab*>(_trackGraphs->currentWidget());
gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
} else
gh = 0;
_track->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
@ -771,11 +802,6 @@ void GUI::closeAll()
updateTrackView();
}
void GUI::overlapPOIs(bool checked)
{
_track->setPOIOverlap(checked);
}
void GUI::showPOI(bool checked)
{
if (checked)
@ -841,6 +867,11 @@ void GUI::showFullscreen(bool checked)
}
}
void GUI::showWaypointLabels(bool checked)
{
_track->showWaypointLabels(checked);
}
void GUI::clearMapCache()
{
_currentMap->clearCache();
@ -920,8 +951,8 @@ void GUI::graphChanged(int index)
if (index < 0)
return;
GraphView *gv = static_cast<GraphView*>(_trackGraphs->widget(index));
gv->setSliderPosition(_sliderPos);
GraphTab *gt = static_cast<GraphTab*>(_trackGraphs->widget(index));
gt->setSliderPosition(_sliderPos);
}
void GUI::updateNavigationActions()
@ -972,7 +1003,8 @@ void GUI::updateGraphTabs()
void GUI::updateTrackView()
{
_track->setHidden(!(_track->trackCount() + _track->waypointCount()));
_track->setHidden(!(_track->trackCount() + _track->routeCount()
+ _track->waypointCount()));
}
void GUI::setMetricUnits()
@ -1106,6 +1138,16 @@ void GUI::writeSettings()
}
settings.endArray();
settings.endGroup();
settings.beginGroup(DATA_SETTINGS_GROUP);
settings.setValue(SHOW_TRACKS_SETTING, _showTracksAction->isChecked());
settings.setValue(SHOW_ROUTES_SETTING, _showRoutesAction->isChecked());
settings.setValue(SHOW_WAYPOINTS_SETTING,
_showWaypointsAction->isChecked());
settings.setValue(SHOW_WAYPOINT_LABELS_SETTING,
_showWaypointLabelsAction->isChecked());
settings.endGroup();
}
void GUI::readSettings()
@ -1125,15 +1167,13 @@ void GUI::readSettings()
_imperialUnitsAction->setChecked(true);
} else
_metricUnitsAction->setChecked(true);
if (settings.value(SHOW_TOOLBARS_SETTING, true).toBool() == false) {
if (settings.value(SHOW_TOOLBARS_SETTING, true).toBool() == false)
showToolbars(false);
_showToolbarsAction->setChecked(false);
} else
else
_showToolbarsAction->setChecked(true);
if (settings.value(SHOW_GRAPHS_SETTING, true).toBool() == false) {
if (settings.value(SHOW_GRAPHS_SETTING, true).toBool() == false)
showGraphs(false);
_showGraphsAction->setChecked(false);
} else
else
_showGraphsAction->setChecked(true);
settings.endGroup();
@ -1151,11 +1191,14 @@ void GUI::readSettings()
settings.endGroup();
settings.beginGroup(POI_SETTINGS_GROUP);
if (settings.value(OVERLAP_POI_SETTING, true).toBool() == false) {
if (settings.value(OVERLAP_POI_SETTING, true).toBool() == false)
_track->setPOIOverlap(false);
_overlapPOIAction->setChecked(false);
} else
else
_overlapPOIAction->setChecked(true);
if (settings.value(LABELS_POI_SETTING, true).toBool() == false)
_track->showPOILabels(false);
else
_showPOILabelsAction->setChecked(true);
if (settings.value(SHOW_POI_SETTING, false).toBool() == true)
_showPOIAction->setChecked(true);
for (int i = 0; i < _poiFilesActions.count(); i++)
@ -1172,6 +1215,25 @@ void GUI::readSettings()
}
settings.endArray();
settings.endGroup();
settings.beginGroup(DATA_SETTINGS_GROUP);
if (settings.value(SHOW_TRACKS_SETTING, true).toBool() == false)
_track->showTracks(false);
else
_showTracksAction->setChecked(true);
if (settings.value(SHOW_ROUTES_SETTING, true).toBool() == false)
_track->showRoutes(false);
else
_showRoutesAction->setChecked(true);
if (settings.value(SHOW_WAYPOINTS_SETTING, true).toBool() == false)
_track->showWaypoints(false);
else
_showWaypointsAction->setChecked(true);
if (settings.value(SHOW_WAYPOINT_LABELS_SETTING, true).toBool() == false)
_track->showWaypointLabels(false);
else
_showWaypointLabelsAction->setChecked(true);
settings.endGroup();
}
int GUI::mapIndex(const QString &name)

View File

@ -43,12 +43,12 @@ private slots:
void reloadFile();
void openPOIFile();
void closePOIFiles();
void overlapPOIs(bool checked);
void showPOI(bool checked);
void showMap(bool checked);
void showGraphs(bool checked);
void showToolbars(bool checked);
void showFullscreen(bool checked);
void showWaypointLabels(bool checked);
void clearMapCache();
void nextMap();
void prevMap();
@ -101,21 +101,13 @@ private:
void readSettings();
void writeSettings();
QMenu *_fileMenu;
QMenu *_helpMenu;
QMenu *_poiMenu;
QMenu *_mapMenu;
QMenu *_settingsMenu;
QMenu *_unitsMenu;
QMenu *_poiFilesMenu;
QToolBar *_fileToolBar;
QToolBar *_showToolBar;
QToolBar *_navigationToolBar;
QTabWidget *_trackGraphs;
QMenu *_poiFilesMenu;
QActionGroup *_fileActionGroup;
QActionGroup *_navigationActionGroup;
QAction *_exitAction;
QAction *_keysAction;
QAction *_dataSourcesAction;
@ -130,6 +122,7 @@ private:
QAction *_closePOIAction;
QAction *_showPOIAction;
QAction *_overlapPOIAction;
QAction *_showPOILabelsAction;
QAction *_showMapAction;
QAction *_fullscreenAction;
QAction *_clearMapCacheAction;
@ -143,6 +136,10 @@ private:
QAction *_imperialUnitsAction;
QAction *_nextMapAction;
QAction *_prevMapAction;
QAction *_showTracksAction;
QAction *_showRoutesAction;
QAction *_showWaypointsAction;
QAction *_showWaypointLabelsAction;
QList<QAction*> _mapActions;
QList<QAction*> _poiFilesActions;
@ -153,6 +150,7 @@ private:
QLabel *_timeLabel;
TrackView *_track;
QTabWidget *_trackGraphs;
QList<GraphTab*> _tabs;
POI _poi;

View File

@ -13,14 +13,12 @@ HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
setSliderPrecision(0);
}
void HeartRateGraph::addInfo()
void HeartRateGraph::setInfo()
{
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 0)
+ UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 0)
+ UNIT_SPACE + yUnits());
redraw();
}
void HeartRateGraph::loadGPX(const GPX &gpx)
@ -44,8 +42,13 @@ void HeartRateGraph::loadGPX(const GPX &gpx)
loadData(data);
}
for (int i = 0; i < gpx.routeCount(); i++)
skipColor();
setXUnits();
addInfo();
setInfo();
redraw();
}
qreal HeartRateGraph::avg() const
@ -92,8 +95,9 @@ void HeartRateGraph::setXUnits()
void HeartRateGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
clearInfo();
addInfo();
setXUnits();
setInfo();
redraw();
}

View File

@ -21,7 +21,7 @@ private:
qreal avg() const;
qreal max() const {return bounds().bottom();}
void setXUnits();
void addInfo();
void setInfo();
QList<QPointF> _avg;
enum Units _units;

View File

@ -52,6 +52,30 @@ void Parser::handleWaypointData(DataType type, const QString &value)
}
}
void Parser::handleRoutepointData(DataType type, const QString &value)
{
switch (type) {
case Name:
_route->last().setName(value);
break;
case Description:
_route->last().setDescription(value);
break;
case Time:
_route->last().setTimestamp(QDateTime::fromString(
value.toLatin1(), Qt::ISODate));
break;
case Elevation:
_route->last().setElevation(value.toLatin1().toDouble());
break;
case Geoidheight:
_route->last().setGeoidHeight(value.toLatin1().toDouble());
break;
default:
break;
}
}
void Parser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
{
_track->last().setCoordinates(QPointF(
@ -59,6 +83,13 @@ void Parser::handleTrackpointAttributes(const QXmlStreamAttributes &attr)
attr.value("lat").toLatin1().toDouble()));
}
void Parser::handleRoutepointAttributes(const QXmlStreamAttributes &attr)
{
_route->last().setCoordinates(QPointF(
attr.value("lon").toLatin1().toDouble(),
attr.value("lat").toLatin1().toDouble()));
}
void Parser::handleWaypointAttributes(const QXmlStreamAttributes &attr)
{
_waypoints.last().setCoordinates(QPointF(
@ -110,6 +141,20 @@ void Parser::trackpointData()
}
}
void Parser::routepointData()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "name")
handleRoutepointData(Name, _reader.readElementText());
else if (_reader.name() == "ele")
handleRoutepointData(Elevation, _reader.readElementText());
else if (_reader.name() == "geoidheight")
handleRoutepointData(Geoidheight, _reader.readElementText());
else
_reader.skipCurrentElement();
}
}
void Parser::trackpoints()
{
while (_reader.readNextStartElement()) {
@ -122,6 +167,18 @@ void Parser::trackpoints()
}
}
void Parser::routepoints()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "rtept") {
_route->append(Waypoint());
handleRoutepointAttributes(_reader.attributes());
routepointData();
} else
_reader.skipCurrentElement();
}
}
void Parser::track()
{
while (_reader.readNextStartElement()) {
@ -157,6 +214,10 @@ void Parser::gpx()
_tracks.append(QVector<Trackpoint>());
_track = &_tracks.back();
track();
} else if (_reader.name() == "rte") {
_routes.append(QVector<Waypoint>());
_route = &_routes.back();
routepoints();
} else if (_reader.name() == "wpt") {
_waypoints.append(Waypoint());
handleWaypointAttributes(_reader.attributes());

View File

@ -11,8 +11,11 @@
class Parser
{
public:
Parser(QList<QVector<Trackpoint> > &tracks, QList<Waypoint> &waypoints)
: _tracks(tracks), _waypoints(waypoints) {_track = 0;}
Parser(QList<QVector<Trackpoint> > &tracks,
QList<QVector<Waypoint> > &routes, QList<Waypoint> &waypoints)
: _tracks(tracks), _routes(routes), _waypoints(waypoints)
{_track = 0; _route = 0;}
bool loadFile(QIODevice *device);
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
@ -27,20 +30,26 @@ private:
void gpx();
void track();
void trackpoints();
void routepoints();
void tpExtension();
void extensions();
void trackpointData();
void routepointData();
void waypointData();
void handleWaypointAttributes(const QXmlStreamAttributes &attr);
void handleWaypointData(DataType type, const QString &value);
void handleTrackpointAttributes(const QXmlStreamAttributes &attr);
void handleTrackpointData(DataType type, const QString &value);
void handleRoutepointAttributes(const QXmlStreamAttributes &attr);
void handleRoutepointData(DataType type, const QString &value);
QXmlStreamReader _reader;
QList<QVector<Trackpoint> > &_tracks;
QList<QVector<Waypoint> > &_routes;
QList<Waypoint> &_waypoints;
QVector<Trackpoint> *_track;
QVector<Waypoint> *_route;
};
#endif // PARSER_H

25
src/route.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "ll.h"
#include "route.h"
Route::Route(const QVector<Waypoint> &data) : _data(data)
{
qreal dist = 0;
_dd.append(dist);
for (int i = 1; i < _data.count(); i++) {
dist += llDistance(_data.at(i).coordinates(),
_data.at(i-1).coordinates());
_dd.append(dist);
}
}
void Route::elevationGraph(QVector<QPointF> &graph) const
{
if (!_data.size())
return;
for (int i = 0; i < _data.size(); i++)
if (_data.at(i).hasElevation())
graph.append(QPointF(_dd.at(i), _data.at(i).elevation()
- _data.at(i).geoidHeight()));
}

23
src/route.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef ROUTE_H
#define ROUTE_H
#include <QVector>
#include "waypoint.h"
class Route
{
public:
Route(const QVector<Waypoint> &data);
const QVector<Waypoint> &route() const {return _data;}
void elevationGraph(QVector<QPointF> &graph) const;
qreal distance() const {return _dd.last();}
bool isNull() const {return (_data.count() < 2) ? true : false;}
private:
const QVector<Waypoint> &_data;
QVector<qreal> _dd;
};
#endif // ROUTE_H

74
src/routeitem.cpp Normal file
View File

@ -0,0 +1,74 @@
#include <QPainter>
#include "ll.h"
#include "waypoint.h"
#include "waypointitem.h"
#include "routeitem.h"
#define ROUTE_WIDTH 3
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
: QGraphicsItem(parent)
{
WaypointItem *wi;
const QVector<Waypoint> &r = route.route();
Q_ASSERT(r.count() >= 2);
wi = new WaypointItem(r.at(0));
wi->setParentItem(this);
const QPointF &p = r.at(0).coordinates();
_path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
for (int i = 1; i < r.size(); i++) {
const QPointF &p = r.at(i).coordinates();
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
wi = new WaypointItem(r.at(i));
wi->setParentItem(this);
}
QBrush brush(Qt::SolidPattern);
_pen = QPen(brush, ROUTE_WIDTH, Qt::DotLine);
_marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0));
}
void RouteItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath(_path);
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
}
void RouteItem::setScale(qreal scale)
{
prepareGeometryChange();
_pen.setWidthF(ROUTE_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
_marker->setScale(1.0/scale);
QList<QGraphicsItem *> childs = childItems();
for (int i = 0; i < childs.count(); i++)
childs.at(i)->setScale(1.0/scale);
}
void RouteItem::setColor(const QColor &color)
{
_pen.setColor(color);
update();
}
void RouteItem::moveMarker(qreal t)
{
Q_ASSERT(t >= 0 && t <= 1.0);
_marker->setPos(_path.pointAtPercent(t));
}

32
src/routeitem.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef ROUTEITEM_H
#define ROUTEITEM_H
#include <QGraphicsItem>
#include "markeritem.h"
#include "route.h"
class RouteItem : public QGraphicsItem
{
public:
RouteItem(const Route &route, QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _path.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QPainterPath &path() const {return _path;}
void setScale(qreal scale);
void setColor(const QColor &color);
void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal t);
private:
QPainterPath _path;
QPen _pen;
MarkerItem *_marker;
};
#endif // ROUTEITEM_H

View File

@ -16,8 +16,15 @@
#define POI_SETTINGS_GROUP "POI"
#define OVERLAP_POI_SETTING "overlap"
#define LABELS_POI_SETTING "labels"
#define SHOW_POI_SETTING "show"
#define DISABLED_POI_FILE_SETTINGS_PREFIX "disabled"
#define DISABLED_POI_FILE_SETTING "file"
#define DATA_SETTINGS_GROUP "Data"
#define SHOW_TRACKS_SETTING "tracks"
#define SHOW_ROUTES_SETTING "routes"
#define SHOW_WAYPOINTS_SETTING "waypoints"
#define SHOW_WAYPOINT_LABELS_SETTING "waypointLabels"
#endif // SETTINGS_H

View File

@ -14,14 +14,12 @@ SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
setSliderPrecision(1);
}
void SpeedGraph::addInfo()
void SpeedGraph::setInfo()
{
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 1)
+ UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 1)
+ UNIT_SPACE + yUnits());
redraw();
}
void SpeedGraph::loadGPX(const GPX &gpx)
@ -41,8 +39,13 @@ void SpeedGraph::loadGPX(const GPX &gpx)
loadData(data);
}
for (int i = 0; i < gpx.routeCount(); i++)
skipColor();
setXUnits();
addInfo();
setInfo();
redraw();
}
qreal SpeedGraph::avg() const
@ -100,9 +103,10 @@ void SpeedGraph::setYUnits()
void SpeedGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
setInfo();
clearInfo();
addInfo();
redraw();
}

View File

@ -23,7 +23,7 @@ private:
qreal max() const {return bounds().bottom();}
void setXUnits();
void setYUnits();
void addInfo();
void setInfo();
QList<QPointF> _avg;
enum Units _units;

View File

@ -13,7 +13,7 @@ TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
setSliderPrecision(1);
}
void TemperatureGraph::addInfo()
void TemperatureGraph::setInfo()
{
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
@ -21,8 +21,6 @@ void TemperatureGraph::addInfo()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
redraw();
}
void TemperatureGraph::loadGPX(const GPX &gpx)
@ -46,8 +44,13 @@ void TemperatureGraph::loadGPX(const GPX &gpx)
loadData(data);
}
for (int i = 0; i < gpx.routeCount(); i++)
skipColor();
setXUnits();
addInfo();
setInfo();
redraw();
}
qreal TemperatureGraph::avg() const
@ -107,9 +110,10 @@ void TemperatureGraph::setYUnits()
void TemperatureGraph::setUnits(enum Units units)
{
_units = units;
setXUnits();
setYUnits();
setInfo();
clearInfo();
addInfo();
redraw();
}

View File

@ -23,7 +23,7 @@ private:
qreal max() const {return bounds().bottom();}
void setXUnits();
void setYUnits();
void addInfo();
void setInfo();
QList<QPointF> _avg;
enum Units _units;

View File

@ -24,7 +24,6 @@ public:
private:
const QVector<Trackpoint> &_data;
QVector<qreal> _dd;
qreal _distance;
};
#endif // TRACK_H

View File

@ -1,6 +1,6 @@
#include <QApplication>
#include <QCursor>
#include <QPen>
#include <QPainter>
#include "ll.h"
#include "misc.h"
#include "tooltip.h"
@ -28,23 +28,22 @@ void TrackItem::updateShape()
{
QPainterPathStroker s;
s.setWidth(TRACK_WIDTH * 1.0/scale());
_shape = s.createStroke(path().simplified());
_shape = s.createStroke(_path.simplified());
}
TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
: QGraphicsPathItem(parent)
: QGraphicsItem(parent)
{
QVector<QPointF> t;
QPainterPath path;
track.track(t);
Q_ASSERT(t.count() >= 2);
const QPointF &p = t.at(0);
path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
_path.moveTo(ll2mercator(QPointF(p.x(), -p.y())));
for (int i = 1; i < t.size(); i++) {
const QPointF &p = t.at(i);
path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
}
_units = Metric;
@ -52,32 +51,48 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
_distance = track.distance();
_time = track.time();
setPath(path);
setToolTip(toolTip());
setCursor(Qt::ArrowCursor);
updateShape();
QBrush brush(Qt::SolidPattern);
QPen pen(brush, TRACK_WIDTH);
setPen(pen);
_pen = QPen(brush, TRACK_WIDTH);
_marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0));
}
void TrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath(_path);
/*
painter->setPen(Qt::red);
painter->drawRect(boundingRect());
*/
}
void TrackItem::setScale(qreal scale)
{
QGraphicsPathItem::setScale(scale);
updateShape();
prepareGeometryChange();
QPen p(pen());
p.setWidthF(TRACK_WIDTH * 1.0/scale);
setPen(p);
_pen.setWidthF(TRACK_WIDTH * 1.0/scale);
QGraphicsItem::setScale(scale);
_marker->setScale(1.0/scale);
updateShape();
}
void TrackItem::setColor(const QColor &color)
{
QPen p(pen());
p.setColor(color);
setPen(p);
_pen.setColor(color);
update();
}
void TrackItem::setUnits(enum Units units)
@ -85,3 +100,9 @@ void TrackItem::setUnits(enum Units units)
_units = units;
setToolTip(toolTip());
}
void TrackItem::moveMarker(qreal t)
{
Q_ASSERT(t >= 0 && t <= 1.0);
_marker->setPos(_path.pointAtPercent(t));
}

View File

@ -1,27 +1,41 @@
#ifndef TRACKITEM_H
#define TRACKITEM_H
#include <QGraphicsPathItem>
#include <QGraphicsItem>
#include <QDateTime>
#include "units.h"
#include "track.h"
#include "markeritem.h"
class TrackItem : public QGraphicsPathItem
class TrackItem : public QGraphicsItem
{
public:
TrackItem(const Track &track, QGraphicsItem *parent = 0);
QPainterPath shape() const {return _shape;}
void setScale(qreal scale);
QRectF boundingRect() const {return _shape.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QPainterPath &path() const {return _path;}
void setScale(qreal scale);
void setUnits(enum Units units);
void setColor(const QColor &color);
void showMarker(bool show) {_marker->setVisible(show);}
void moveMarker(qreal t);
private:
void updateShape();
QString toolTip();
QPainterPath _path;
QPainterPath _shape;
QPen _pen;
MarkerItem *_marker;
Units _units;
QDateTime _date;

View File

@ -7,8 +7,8 @@
#include "gpx.h"
#include "map.h"
#include "trackitem.h"
#include "routeitem.h"
#include "waypointitem.h"
#include "markeritem.h"
#include "scaleitem.h"
#include "trackview.h"
@ -37,9 +37,16 @@ TrackView::TrackView(QWidget *parent)
_maxPath = 0;
_maxDistance = 0;
_plot = false;
_units = Metric;
_overlap = true;
_showTracks = true;
_showRoutes = true;
_showWaypoints = true;
_showWaypointLabels = true;
_showPOILabels = true;
_overlapPOIs = true;
_plot = false;
}
TrackView::~TrackView()
@ -55,23 +62,39 @@ void TrackView::addTrack(const Track &track)
return;
}
TrackItem *pi = new TrackItem(track);
_paths.append(pi);
TrackItem *ti = new TrackItem(track);
_tracks.append(ti);
_zoom = qMin(_zoom, scale2zoom(trackScale()));
_scale = mapScale(_zoom);
pi->setScale(1.0/_scale);
pi->setColor(_palette.color());
_scene->addItem(pi);
ti->setScale(1.0/_scale);
ti->setColor(_palette.color());
ti->setVisible(_showTracks);
_scene->addItem(ti);
MarkerItem *mi = new MarkerItem(pi);
_markers.append(mi);
mi->setPos(pi->path().pointAtPercent(0));
mi->setScale(_scale);
_maxPath = qMax(pi->path().length(), _maxPath);
_maxPath = qMax(ti->path().length(), _maxPath);
_maxDistance = qMax(track.distance(), _maxDistance);
}
void TrackView::addRoute(const Route &route)
{
if (route.isNull()) {
_palette.color();
return;
}
RouteItem *ri = new RouteItem(route);
_routes.append(ri);
_zoom = qMin(_zoom, scale2zoom(routeScale()));
_scale = mapScale(_zoom);
ri->setScale(1.0/_scale);
ri->setColor(_palette.color());
ri->setVisible(_showRoutes);
_scene->addItem(ri);
_maxPath = qMax(ri->path().length(), _maxPath);
_maxDistance = qMax(route.distance(), _maxDistance);
}
void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
{
for (int i = 0; i < waypoints.count(); i++) {
@ -80,6 +103,8 @@ void TrackView::addWaypoints(const QList<Waypoint> &waypoints)
WaypointItem *wi = new WaypointItem(w);
wi->setScale(1.0/_scale);
wi->setZValue(1);
wi->showLabel(_showWaypointLabels);
wi->setVisible(_showWaypoints);
_scene->addItem(wi);
_waypoints.append(wi);
@ -95,16 +120,19 @@ void TrackView::loadGPX(const GPX &gpx)
for (int i = 0; i < gpx.trackCount(); i++)
addTrack(gpx.track(i));
for (int i = 0; i < gpx.routeCount(); i++)
addRoute(gpx.route(i));
addWaypoints(gpx.waypoints());
if (_paths.empty() && _waypoints.empty())
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
return;
if ((_paths.size() > 1 && _zoom < zoom)
if ((_tracks.size() > 1 && _zoom < zoom)
|| (_waypoints.size() && _zoom < zoom))
rescale(_scale);
QRectF br = trackBoundingRect() | waypointBoundingRect();
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
centerOn(ba.center());
@ -117,12 +145,24 @@ void TrackView::loadGPX(const GPX &gpx)
QRectF TrackView::trackBoundingRect() const
{
if (_paths.empty())
if (_tracks.empty())
return QRectF();
QRectF br = _paths.at(0)->sceneBoundingRect();
for (int i = 1; i < _paths.size(); i++)
br |= _paths.at(i)->sceneBoundingRect();
QRectF br = _tracks.at(0)->sceneBoundingRect();
for (int i = 1; i < _tracks.size(); i++)
br |= _tracks.at(i)->sceneBoundingRect();
return br;
}
QRectF TrackView::routeBoundingRect() const
{
if (_routes.empty())
return QRectF();
QRectF br = _routes.at(0)->sceneBoundingRect();
for (int i = 1; i < _routes.size(); i++)
br |= _routes.at(i)->sceneBoundingRect();
return br;
}
@ -153,13 +193,29 @@ QRectF TrackView::waypointBoundingRect() const
qreal TrackView::trackScale() const
{
if (_paths.empty())
if (_tracks.empty())
return mapScale(ZOOM_MAX);
QRectF br = _paths.at(0)->path().boundingRect();
QRectF br = _tracks.at(0)->path().boundingRect();
for (int i = 1; i < _paths.size(); i++)
br |= _paths.at(i)->path().boundingRect();
for (int i = 1; i < _tracks.size(); i++)
br |= _tracks.at(i)->path().boundingRect();
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
qreal TrackView::routeScale() const
{
if (_routes.empty())
return mapScale(ZOOM_MAX);
QRectF br = _routes.at(0)->path().boundingRect();
for (int i = 1; i < _routes.size(); i++)
br |= _routes.at(i)->path().boundingRect();
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
@ -215,10 +271,11 @@ void TrackView::checkPOIOverlap()
void TrackView::rescale(qreal scale)
{
for (int i = 0; i < _paths.size(); i++) {
_markers.at(i)->setScale(scale);
_paths.at(i)->setScale(1.0/scale);
}
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setScale(1.0/scale);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setScale(1.0/scale);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setScale(1.0/scale);
@ -229,7 +286,7 @@ void TrackView::rescale(qreal scale)
it.value()->show();
}
if (!_overlap)
if (!_overlapPOIs)
checkPOIOverlap();
_scale = scale;
@ -246,6 +303,7 @@ void TrackView::addPOI(const QVector<Waypoint> &waypoints)
WaypointItem *pi = new WaypointItem(w);
pi->setScale(1.0/_scale);
pi->setZValue(1);
pi->showLabel(_showPOILabels);
_scene->addItem(pi);
_pois.insert(w, pi);
@ -254,14 +312,16 @@ void TrackView::addPOI(const QVector<Waypoint> &waypoints)
void TrackView::loadPOI(const POI &poi)
{
if (!_paths.size() && !_waypoints.size())
if (!_tracks.size() && !_routes.size() && !_waypoints.size())
return;
for (int i = 0; i < _paths.size(); i++)
addPOI(poi.points(_paths.at(i)->path()));
for (int i = 0; i < _tracks.size(); i++)
addPOI(poi.points(_tracks.at(i)->path()));
for (int i = 0; i < _routes.size(); i++)
addPOI(poi.points(_routes.at(i)->path()));
addPOI(poi.points(_waypoints));
if (!_overlap)
if (!_overlapPOIs)
checkPOIOverlap();
}
@ -280,8 +340,8 @@ void TrackView::setUnits(enum Units units)
_mapScale->setUnits(units);
for (int i = 0; i < _paths.count(); i++)
_paths[i]->setUnits(units);
for (int i = 0; i < _tracks.count(); i++)
_tracks[i]->setUnits(units);
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setUnits(units);
@ -298,21 +358,24 @@ void TrackView::redraw()
void TrackView::rescale()
{
_zoom = qMin(scale2zoom(trackScale()), scale2zoom(waypointScale()));
_zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())),
scale2zoom(waypointScale()));
rescale(mapScale(_zoom));
_mapScale->setZoom(_zoom);
}
void TrackView::zoom(int z, const QPointF &pos)
{
if (_paths.isEmpty() && _waypoints.isEmpty())
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
qreal scale = _scale;
_zoom = z;
rescale(mapScale(_zoom));
QRectF br = trackBoundingRect() | waypointBoundingRect();
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
@ -329,7 +392,7 @@ void TrackView::zoom(int z, const QPointF &pos)
void TrackView::wheelEvent(QWheelEvent *event)
{
if (_paths.isEmpty() && _waypoints.isEmpty())
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
QPointF pos = mapToScene(event->pos());
@ -406,9 +469,9 @@ void TrackView::clear()
_scene->removeItem(_mapScale);
_pois.clear();
_paths.clear();
_tracks.clear();
_routes.clear();
_waypoints.clear();
_markers.clear();
_scene->clear();
_palette.reset();
@ -424,23 +487,75 @@ void TrackView::movePositionMarker(qreal val)
{
qreal mp = val / _maxDistance;
for (int i = 0; i < _paths.size(); i++) {
qreal f = _maxPath / _paths.at(i)->path().length();
for (int i = 0; i < _tracks.size(); i++) {
qreal f = _maxPath / _tracks.at(i)->path().length();
if (mp * f < 0 || mp * f > 1.0)
_markers.at(i)->setVisible(false);
_tracks.at(i)->showMarker(false);
else {
QPointF pos = _paths.at(i)->path().pointAtPercent(mp * f);
_markers.at(i)->setPos(pos);
_markers.at(i)->setVisible(true);
_tracks.at(i)->moveMarker(mp * f);
_tracks.at(i)->showMarker(true);
}
}
for (int i = 0; i < _routes.size(); i++) {
qreal f = _maxPath / _routes.at(i)->path().length();
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)
{
_showTracks = show;
for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setVisible(show);
}
void TrackView::showRoutes(bool show)
{
_showRoutes = show;
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setVisible(show);
}
void TrackView::showWaypoints(bool show)
{
_showWaypoints = show;
for (int i = 0; i < _waypoints.count(); i++)
_waypoints.at(i)->setVisible(show);
}
void TrackView::showWaypointLabels(bool show)
{
_showWaypointLabels = show;
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->showLabel(show);
}
void TrackView::showPOILabels(bool show)
{
_showPOILabels = show;
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->showLabel(show);
setPOIOverlap(_overlapPOIs);
}
void TrackView::setPOIOverlap(bool overlap)
{
_overlap = overlap;
_overlapPOIs = overlap;
if (_overlap) {
if (_overlapPOIs) {
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->show();
@ -450,7 +565,8 @@ void TrackView::setPOIOverlap(bool overlap)
void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
{
if ((_paths.isEmpty() && _waypoints.isEmpty()) || !_map) {
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|| !_map) {
painter->fillRect(rect, Qt::white);
return;
}
@ -481,12 +597,13 @@ void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
void TrackView::resizeEvent(QResizeEvent *e)
{
if (_paths.isEmpty() && _waypoints.isEmpty())
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
rescale();
QRectF br = trackBoundingRect() | waypointBoundingRect();
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
if (ba.width() < e->size().width()) {

View File

@ -13,9 +13,10 @@ class GPX;
class POI;
class Map;
class Track;
class Route;
class TrackItem;
class RouteItem;
class WaypointItem;
class MarkerItem;
class ScaleItem;
class TrackView : public QGraphicsView
@ -34,25 +35,35 @@ public:
void setMap(Map *map);
void setUnits(enum Units units);
void setPOIOverlap(bool overlap);
void plot(QPainter *painter, const QRectF &target);
int trackCount() const {return _paths.count();}
int trackCount() const {return _tracks.count();}
int routeCount() const {return _routes.count();}
int waypointCount() const {return _waypoints.count();}
public slots:
void movePositionMarker(qreal val);
void redraw();
void setPOIOverlap(bool overlap);
void showWaypointLabels(bool show);
void showPOILabels(bool show);
void showTracks(bool show);
void showRoutes(bool show);
void showWaypoints(bool show);
private:
void addTrack(const Track &track);
void addRoute(const Route &route);
void addWaypoints(const QList<Waypoint> &waypoints);
void addPOI(const QVector<Waypoint> &waypoints);
QRectF trackBoundingRect() const;
QRectF routeBoundingRect() const;
QRectF waypointBoundingRect() const;
qreal trackScale() const;
qreal routeScale() const;
qreal waypointScale() const;
qreal mapScale(int zoom) const;
void rescale(qreal scale);
@ -67,8 +78,8 @@ private:
void paintEvent(QPaintEvent *e);
QGraphicsScene *_scene;
QList<TrackItem*> _paths;
QList<MarkerItem*> _markers;
QList<TrackItem*> _tracks;
QList<RouteItem*> _routes;
QList<WaypointItem*> _waypoints;
QHash<Waypoint, WaypointItem*> _pois;
@ -82,7 +93,14 @@ private:
int _zoom;
Units _units;
bool _overlap;
bool _showTracks;
bool _showRoutes;
bool _showWaypoints;
bool _showWaypointLabels;
bool _showPOILabels;
bool _overlapPOIs;
bool _plot;
};

View File

@ -31,6 +31,8 @@ public:
void setElevation(qreal elevation) {_elevation = elevation;}
void setGeoidHeight(qreal geoidHeight) {_geoidHeight = geoidHeight;}
bool hasElevation() const {return !std::isnan(_elevation);}
bool operator==(const Waypoint &other) const
{return this->_name == other._name
&& this->_coordinates == other._coordinates;}

View File

@ -13,6 +13,8 @@ QString WaypointItem::toolTip()
{
ToolTip tt;
if (!_waypoint.name().isEmpty() && !_showLabel)
tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name());
tt.insert(qApp->translate("WaypointItem", "Coordinates"),
::coordinates(_waypoint.coordinates()));
if (!std::isnan(_waypoint.elevation()))
@ -32,6 +34,7 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent)
: QGraphicsItem(parent)
{
_units = Metric;
_showLabel = true;
_waypoint = waypoint;
_coordinates = ll2mercator(QPointF(waypoint.coordinates().x(),
@ -46,6 +49,7 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, QGraphicsItem *parent)
void WaypointItem::updateBoundingRect()
{
if (_showLabel) {
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
@ -54,6 +58,9 @@ void WaypointItem::updateBoundingRect()
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, ts.width()
+ POINT_SIZE, ts.height() + fm.descent() + POINT_SIZE);
} else
_boundingRect = QRectF(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE,
POINT_SIZE);
}
void WaypointItem::paint(QPainter *painter,
@ -61,6 +68,8 @@ void WaypointItem::paint(QPainter *painter,
{
Q_UNUSED(option);
Q_UNUSED(widget);
if (_showLabel) {
QFont font;
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
@ -68,8 +77,10 @@ void WaypointItem::paint(QPainter *painter,
QRect ts = fm.tightBoundingRect(_waypoint.name());
painter->setFont(font);
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2 + ts.height(),
_waypoint.name());
painter->drawText(POINT_SIZE/2 - qMax(ts.x(), 0), POINT_SIZE/2
+ ts.height(), _waypoint.name());
}
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(-POINT_SIZE/2, -POINT_SIZE/2, POINT_SIZE, POINT_SIZE);
@ -90,3 +101,11 @@ void WaypointItem::setUnits(enum Units units)
_units = units;
setToolTip(toolTip());
}
void WaypointItem::showLabel(bool show)
{
prepareGeometryChange();
_showLabel = show;
updateBoundingRect();
setToolTip(toolTip());
}

View File

@ -15,6 +15,7 @@ public:
void setUnits(enum Units units);
void setScale(qreal scale);
void showLabel(bool show);
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -28,6 +29,7 @@ private:
QPointF _coordinates;
Waypoint _waypoint;
Units _units;
bool _showLabel;
};
#endif // WAYPOINTITEM_H