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

Added heart rate graph

Improved graphs loading performance
Fixed various corner case behaviour bugs
This commit is contained in:
Martin Tůma 2016-03-21 22:37:55 +01:00
parent b212ccf594
commit 93670d3026
16 changed files with 409 additions and 169 deletions

View File

@ -33,7 +33,8 @@ HEADERS += src/config.h \
src/graphview.h \
src/trackpoint.h \
src/waypointitem.h \
src/palette.h
src/palette.h \
src/heartrategraph.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
@ -57,7 +58,8 @@ SOURCES += src/main.cpp \
src/track.cpp \
src/graphview.cpp \
src/waypointitem.cpp \
src/palette.cpp
src/palette.cpp \
src/heartrategraph.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx:ICON = icons/gpxsee.icns

View File

@ -15,43 +15,43 @@
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="16"/>
<location filename="../src/elevationgraph.cpp" line="83"/>
<location filename="../src/elevationgraph.cpp" line="84"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="17"/>
<location filename="../src/elevationgraph.cpp" line="84"/>
<location filename="../src/elevationgraph.cpp" line="85"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="23"/>
<location filename="../src/elevationgraph.cpp" line="24"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="25"/>
<location filename="../src/elevationgraph.cpp" line="26"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="29"/>
<location filename="../src/elevationgraph.cpp" line="30"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="88"/>
<location filename="../src/elevationgraph.cpp" line="89"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="89"/>
<location filename="../src/elevationgraph.cpp" line="90"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="27"/>
<location filename="../src/elevationgraph.cpp" line="28"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
@ -59,352 +59,396 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/gui.cpp" line="161"/>
<location filename="../src/gui.cpp" line="172"/>
<source>About Qt</source>
<translation>O Qt</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="380"/>
<location filename="../src/gui.cpp" line="393"/>
<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="441"/>
<location filename="../src/gui.cpp" line="454"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="175"/>
<location filename="../src/gui.cpp" line="186"/>
<source>Save as</source>
<translation>Uložit jako</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="501"/>
<location filename="../src/gui.cpp" line="515"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="166"/>
<location filename="../src/gui.cpp" line="177"/>
<source>Open</source>
<translation>Otevřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="149"/>
<location filename="../src/gui.cpp" line="160"/>
<source>Quit</source>
<translation>Ukončit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="156"/>
<location filename="../src/gui.cpp" line="396"/>
<location filename="../src/gui.cpp" line="397"/>
<location filename="../src/gui.cpp" line="167"/>
<location filename="../src/gui.cpp" line="409"/>
<location filename="../src/gui.cpp" line="410"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="170"/>
<location filename="../src/gui.cpp" line="181"/>
<source>Save</source>
<translation>Uložit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="180"/>
<location filename="../src/gui.cpp" line="191"/>
<source>Close</source>
<translation>Zavřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="185"/>
<location filename="../src/gui.cpp" line="196"/>
<source>Reload</source>
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="317"/>
<location filename="../src/gui.cpp" line="328"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="262"/>
<location filename="../src/gui.cpp" line="308"/>
<location filename="../src/gui.cpp" line="273"/>
<location filename="../src/gui.cpp" line="319"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="154"/>
<location filename="../src/gui.cpp" line="414"/>
<location filename="../src/gui.cpp" line="415"/>
<location filename="../src/gui.cpp" line="165"/>
<location filename="../src/gui.cpp" line="427"/>
<location filename="../src/gui.cpp" line="428"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="192"/>
<location filename="../src/gui.cpp" line="203"/>
<source>Load POI file</source>
<translation>Nahrát POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="195"/>
<location filename="../src/gui.cpp" line="206"/>
<source>Close POI files</source>
<translation>Zavřit soubory POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="198"/>
<location filename="../src/gui.cpp" line="209"/>
<source>Show POIs</source>
<translation>Zobrazit POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="205"/>
<location filename="../src/gui.cpp" line="216"/>
<source>Show map</source>
<translation>Zobrazit mapu</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="218"/>
<location filename="../src/gui.cpp" line="229"/>
<source>Show graphs</source>
<translation>Zobrazovat grafy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="224"/>
<location filename="../src/gui.cpp" line="235"/>
<source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="231"/>
<location filename="../src/gui.cpp" line="242"/>
<source>Metric</source>
<translation>Metrické</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="237"/>
<location filename="../src/gui.cpp" line="248"/>
<source>Imperial</source>
<translation>Imperiální</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="244"/>
<location filename="../src/gui.cpp" line="255"/>
<source>Next</source>
<translation>Následující</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="247"/>
<location filename="../src/gui.cpp" line="258"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="251"/>
<location filename="../src/gui.cpp" line="262"/>
<source>Last</source>
<translation>Poslední</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="254"/>
<location filename="../src/gui.cpp" line="265"/>
<source>First</source>
<translation>První</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="276"/>
<location filename="../src/gui.cpp" line="287"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="281"/>
<location filename="../src/gui.cpp" line="292"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="282"/>
<location filename="../src/gui.cpp" line="293"/>
<source>POI files</source>
<translation>POI soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="290"/>
<location filename="../src/gui.cpp" line="301"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="291"/>
<location filename="../src/gui.cpp" line="302"/>
<source>Units</source>
<translation>Jednotky</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="298"/>
<location filename="../src/gui.cpp" line="309"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="348"/>
<location filename="../src/gui.cpp" line="360"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="349"/>
<location filename="../src/gui.cpp" line="361"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="399"/>
<location filename="../src/gui.cpp" line="362"/>
<source>Heart rate</source>
<translation>Tep</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="412"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="400"/>
<location filename="../src/gui.cpp" line="413"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="402"/>
<location filename="../src/gui.cpp" line="415"/>
<source>First file</source>
<translation>První soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="403"/>
<location filename="../src/gui.cpp" line="416"/>
<source>Last file</source>
<translation>Poslední soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="404"/>
<location filename="../src/gui.cpp" line="417"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="418"/>
<location filename="../src/gui.cpp" line="431"/>
<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="422"/>
<location filename="../src/gui.cpp" line="435"/>
<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="430"/>
<location filename="../src/gui.cpp" line="443"/>
<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="442"/>
<location filename="../src/gui.cpp" line="455"/>
<source>GPX files (*.gpx);;All files (*)</source>
<translation>soubory GPX (*.gpx);;všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="492"/>
<location filename="../src/gui.cpp" line="509"/>
<location filename="../src/gui.cpp" line="506"/>
<location filename="../src/gui.cpp" line="523"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="502"/>
<location filename="../src/gui.cpp" line="516"/>
<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="577"/>
<location filename="../src/gui.cpp" line="697"/>
<location filename="../src/gui.cpp" line="585"/>
<location filename="../src/gui.cpp" line="707"/>
<source>mi</source>
<translation>mi</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="580"/>
<location filename="../src/gui.cpp" line="582"/>
<location filename="../src/gui.cpp" line="584"/>
<location filename="../src/gui.cpp" line="586"/>
<location filename="../src/gui.cpp" line="588"/>
<location filename="../src/gui.cpp" line="590"/>
<location filename="../src/gui.cpp" line="592"/>
<location filename="../src/gui.cpp" line="594"/>
<source>ft</source>
<translation>ft</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="583"/>
<location filename="../src/gui.cpp" line="595"/>
<location filename="../src/gui.cpp" line="591"/>
<location filename="../src/gui.cpp" line="603"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="585"/>
<location filename="../src/gui.cpp" line="597"/>
<location filename="../src/gui.cpp" line="593"/>
<location filename="../src/gui.cpp" line="605"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="159"/>
<location filename="../src/gui.cpp" line="376"/>
<location filename="../src/gui.cpp" line="170"/>
<location filename="../src/gui.cpp" line="389"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="324"/>
<location filename="../src/gui.cpp" line="335"/>
<source>Navigation</source>
<translation>Navigace</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="378"/>
<location filename="../src/gui.cpp" line="391"/>
<source>GPX viewer and analyzer</source>
<translation>Prohlížeč a analyzátor GPX</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="417"/>
<location filename="../src/gui.cpp" line="430"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="429"/>
<location filename="../src/gui.cpp" line="442"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="576"/>
<location filename="../src/gui.cpp" line="588"/>
<location filename="../src/gui.cpp" line="584"/>
<location filename="../src/gui.cpp" line="596"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="578"/>
<location filename="../src/gui.cpp" line="590"/>
<location filename="../src/gui.cpp" line="586"/>
<location filename="../src/gui.cpp" line="598"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="579"/>
<location filename="../src/gui.cpp" line="591"/>
<location filename="../src/gui.cpp" line="587"/>
<location filename="../src/gui.cpp" line="599"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="592"/>
<location filename="../src/gui.cpp" line="594"/>
<location filename="../src/gui.cpp" line="596"/>
<location filename="../src/gui.cpp" line="598"/>
<location filename="../src/gui.cpp" line="600"/>
<location filename="../src/gui.cpp" line="602"/>
<location filename="../src/gui.cpp" line="604"/>
<location filename="../src/gui.cpp" line="606"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="581"/>
<location filename="../src/gui.cpp" line="593"/>
<location filename="../src/gui.cpp" line="589"/>
<location filename="../src/gui.cpp" line="601"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="693"/>
<location filename="../src/gui.cpp" line="703"/>
<source>%1 tracks</source>
<translation>Počet tras: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="589"/>
<location filename="../src/gui.cpp" line="700"/>
<location filename="../src/gui.cpp" line="597"/>
<location filename="../src/gui.cpp" line="710"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="494"/>
<location filename="../src/gui.cpp" line="510"/>
<location filename="../src/gui.cpp" line="508"/>
<location filename="../src/gui.cpp" line="524"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="489"/>
<location filename="../src/gui.cpp" line="503"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="506"/>
<location filename="../src/gui.cpp" line="520"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
%1</translation>
</message>
</context>
<context>
<name>HeartRateGraph</name>
<message>
<location filename="../src/heartrategraph.cpp" line="9"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="10"/>
<source>Heart rate</source>
<translation>Tep</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="11"/>
<location filename="../src/heartrategraph.cpp" line="74"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="12"/>
<source>1/min</source>
<translation>1/min</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="19"/>
<source>Average</source>
<translation>Průměr</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="21"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/heartrategraph.cpp" line="77"/>
<source>mi</source>
<translation>mi</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>

View File

@ -11,12 +11,12 @@ ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
_max = -FLT_MAX;
_min = FLT_MAX;
GraphView::setXLabel(tr("Distance"));
GraphView::setYLabel(tr("Elevation"));
GraphView::setXUnits(tr("km"));
GraphView::setYUnits(tr("m"));
GraphView::setXScale(M2KM);
GraphView::setMinRange(50.0);
setXLabel(tr("Distance"));
setYLabel(tr("Elevation"));
setXUnits(tr("km"));
setYUnits(tr("m"));
setXScale(M2KM);
setMinRange(50.0);
}
void ElevationGraph::addInfo()
@ -38,14 +38,16 @@ void ElevationGraph::loadGPX(const GPX &gpx)
qreal min, max, ascent = 0, descent = 0;
gpx.track(i).elevationGraph(data);
if (data.isEmpty())
if (data.count() < 2) {
skipColor();
continue;
}
min = max = data.at(0).y();
for (int i = 1; i < data.size(); i++) {
qreal cur = data.at(i).y();
qreal prev = data.at(i-1).y();
for (int j = 1; j < data.size(); j++) {
qreal cur = data.at(j).y();
qreal prev = data.at(j-1).y();
if (cur > prev)
ascent += cur - prev;
@ -81,15 +83,15 @@ void ElevationGraph::clear()
void ElevationGraph::setUnits(enum Units units)
{
if (units == Metric) {
GraphView::setXUnits(tr("km"));
GraphView::setYUnits(tr("m"));
GraphView::setXScale(M2KM);
GraphView::setYScale(1);
setXUnits(tr("km"));
setYUnits(tr("m"));
setXScale(M2KM);
setYScale(1);
} else {
GraphView::setXUnits(tr("mi"));
GraphView::setYUnits(tr("ft"));
GraphView::setXScale(M2MI);
GraphView::setYScale(M2FT);
setXUnits(tr("mi"));
setYUnits(tr("ft"));
setXScale(M2MI);
setYScale(M2FT);
}
clearInfo();

View File

@ -294,7 +294,7 @@ void GraphView::emitSliderPositionChanged(const QPointF &pos)
return;
qreal val = pos.x() / _slider->area().width();
emit sliderPositionChanged(val);
emit sliderPositionChanged(val * (_xMax - _xMin));
const QPainterPath &path = _graphs.at(0)->path();
QRectF br = path.boundingRect();
@ -309,18 +309,27 @@ void GraphView::emitSliderPositionChanged(const QPointF &pos)
qreal GraphView::sliderPosition() const
{
return _slider->pos().x() / _slider->area().width();
if (!_slider->isVisible())
return -1;
else
return (_slider->pos().x() / _slider->area().width()) * (_xMax - _xMin);
}
void GraphView::setSliderPosition(qreal pos)
{
_slider->setPos(pos * _slider->area().width(), 0);
if (pos > (_xMax - _xMin))
_slider->setVisible(false);
else {
_slider->setPos((pos / (_xMax - _xMin)) * _slider->area().width(), 0);
_slider->setVisible(true);
}
}
void GraphView::newSliderPosition(const QPointF &pos)
{
if (_slider->area().contains(pos)) {
_slider->setPos(pos);
_slider->setVisible(true);
emitSliderPositionChanged(pos);
}
}

View File

@ -55,6 +55,8 @@ public:
void addInfo(const QString &key, const QString &value);
void clearInfo();
void skipColor() {_palette.color();}
signals:
void sliderPositionChanged(qreal);

View File

@ -22,6 +22,7 @@
#include "maplist.h"
#include "elevationgraph.h"
#include "speedgraph.h"
#include "heartrategraph.h"
#include "trackview.h"
#include "infoitem.h"
#include "filebrowser.h"
@ -56,6 +57,8 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
SLOT(movePositionMarker(qreal)));
connect(_speedGraph, SIGNAL(sliderPositionChanged(qreal)), _track,
SLOT(movePositionMarker(qreal)));
connect(_heartRateGraph, SIGNAL(sliderPositionChanged(qreal)), _track,
SLOT(movePositionMarker(qreal)));
_browser = new FileBrowser(this);
_browser->setFilter(QStringList("*.gpx"));
@ -75,6 +78,9 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
_time = 0;
_trackCount = 0;
_lastGraph = static_cast<GraphView*>(_trackGraphs->currentWidget());
_lastSliderPos = _lastGraph->sliderPosition();
resize(600, 800);
}
@ -349,10 +355,12 @@ void GUI::createTrackGraphs()
{
_elevationGraph = new ElevationGraph;
_speedGraph = new SpeedGraph;
_heartRateGraph = new HeartRateGraph;
_trackGraphs = new QTabWidget;
_trackGraphs->addTab(_elevationGraph, tr("Elevation"));
_trackGraphs->addTab(_speedGraph, tr("Speed"));
_trackGraphs->addTab(_heartRateGraph, tr("Heart rate"));
connect(_trackGraphs, SIGNAL(currentChanged(int)), this,
SLOT(graphChanged(int)));
@ -478,6 +486,7 @@ bool GUI::loadFile(const QString &fileName)
if (gpx.loadFile(fileName)) {
_elevationGraph->loadGPX(gpx);
_speedGraph->loadGPX(gpx);
_heartRateGraph->loadGPX(gpx);
_track->loadGPX(gpx);
if (_showPOIAction->isChecked())
_track->loadPOI(_poi);
@ -611,6 +620,7 @@ void GUI::reloadFile()
_elevationGraph->clear();
_speedGraph->clear();
_heartRateGraph->clear();
_track->clear();
for (int i = 0; i < _files.size(); i++) {
@ -635,6 +645,7 @@ void GUI::closeFile()
_elevationGraph->clear();
_speedGraph->clear();
_heartRateGraph->clear();
_track->clear();
_files.clear();
@ -721,10 +732,11 @@ void GUI::poiFileChecked(int index)
void GUI::graphChanged(int index)
{
if (_trackGraphs->widget(index) == _elevationGraph)
_elevationGraph->setSliderPosition(_speedGraph->sliderPosition());
else if (_trackGraphs->widget(index) == _speedGraph)
_speedGraph->setSliderPosition(_elevationGraph->sliderPosition());
GraphView *tv = static_cast<GraphView*>(_trackGraphs->widget(index));
if (_lastGraph->sliderPosition() >= 0)
_lastSliderPos = _lastGraph->sliderPosition();
tv->setSliderPosition(_lastSliderPos);
_lastGraph = tv;
}
void GUI::updateNavigationActions()
@ -751,6 +763,7 @@ void GUI::setMetricUnits()
_track->setUnits(Metric);
_elevationGraph->setUnits(Metric);
_speedGraph->setUnits(Metric);
_heartRateGraph->setUnits(Metric);
updateStatusBarInfo();
}
@ -759,6 +772,7 @@ void GUI::setImperialUnits()
_track->setUnits(Imperial);
_elevationGraph->setUnits(Imperial);
_speedGraph->setUnits(Imperial);
_heartRateGraph->setUnits(Imperial);
updateStatusBarInfo();
}

View File

@ -14,8 +14,10 @@ class QAction;
class QLabel;
class QSignalMapper;
class FileBrowser;
class GraphView;
class ElevationGraph;
class SpeedGraph;
class HeartRateGraph;
class TrackView;
class Map;
@ -124,6 +126,7 @@ private:
ElevationGraph *_elevationGraph;
SpeedGraph *_speedGraph;
HeartRateGraph *_heartRateGraph;
TrackView *_track;
POI _poi;
@ -137,6 +140,9 @@ private:
qreal _distance;
qreal _time;
int _trackCount;
GraphView *_lastGraph;
qreal _lastSliderPos;
};
#endif // GUI_H

87
src/heartrategraph.cpp Normal file
View File

@ -0,0 +1,87 @@
#include "gpx.h"
#include "heartrategraph.h"
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphView(parent)
{
_max = 0;
setXLabel(tr("Distance"));
setYLabel(tr("Heart rate"));
setXUnits(tr("km"));
setYUnits(tr("1/min"));
setXScale(M2KM);
setPrecision(0);
}
void HeartRateGraph::addInfo()
{
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);
}
void HeartRateGraph::loadGPX(const GPX &gpx)
{
for (int i = 0; i < gpx.trackCount(); i++) {
QVector<QPointF> data;
qreal max = 0, sum = 0, w = 0;
gpx.track(i).heartRateGraph(data);
if (data.count() < 2) {
skipColor();
continue;
}
for (int j = 1; j < data.size(); j++) {
sum += data.at(j).y() * (data.at(j).x() - data.at(j-1).x());
w += data.at(j).x() - data.at(j-1).x();
}
_avg.append(QPointF(gpx.track(i).distance(), sum/w));
for (int j = 0; j < data.size(); j++)
max = qMax(max, data.at(j).y());
_max = qMax(_max, max);
addInfo();
loadData(data);
}
}
qreal HeartRateGraph::avg() const
{
qreal sum = 0, w = 0;
QList<QPointF>::const_iterator it;
for (it = _avg.begin(); it != _avg.end(); it++) {
sum += it->y() * it->x();
w += it->x();
}
return (sum / w);
}
void HeartRateGraph::clear()
{
_max = 0;
_avg.clear();
GraphView::clear();
}
void HeartRateGraph::setUnits(enum Units units)
{
if (units == Metric) {
setXUnits(tr("km"));
setXScale(M2KM);
} else {
setXUnits(tr("mi"));
setXScale(M2MI);
}
clearInfo();
addInfo();
redraw();
}

30
src/heartrategraph.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef HEARTRATEGRAPH_H
#define HEARTRATEGRAPH_H
#include "graphview.h"
#include "units.h"
class GPX;
class HeartRateGraph : public GraphView
{
Q_OBJECT
public:
HeartRateGraph(QWidget *parent = 0);
void loadGPX(const GPX &gpx);
void clear();
void setUnits(enum Units units);
qreal avg() const;
qreal max() const {return _max;}
private:
void addInfo();
qreal _max;
QList<QPointF> _avg;
};
#endif // HEARTRATEGRAPH_H

View File

@ -5,16 +5,18 @@ void Parser::handleExtensionData(QStringRef element, const QString &value)
{
if (element == "speed")
_track->last().speed = value.toDouble();
else if (element == "hr" || element == "heartrate")
_track->last().heartRate = value.toDouble();
}
void Parser::handleTrekPointData(QStringRef element, const QString &value)
{
if (element == "ele")
_track->last().elevation = value.toLatin1().toDouble();
if (element == "time")
else if (element == "time")
_track->last().timestamp = QDateTime::fromString(value.toLatin1(),
Qt::ISODate);
if (element == "geoidheight")
else if (element == "geoidheight")
_track->last().geoidheight = value.toLatin1().toDouble();
}
@ -40,7 +42,8 @@ void Parser::handleWayPointAttributes(const QXmlStreamAttributes &attr)
void Parser::extensions()
{
while (_reader.readNextStartElement()) {
if (_reader.name() == "speed")
if (_reader.name() == "speed" || _reader.name() == "hr"
|| _reader.name() == "heartrate")
handleExtensionData(_reader.name(), _reader.readElementText());
else
_reader.skipCurrentElement();

View File

@ -7,13 +7,13 @@ SpeedGraph::SpeedGraph(QWidget *parent) : GraphView(parent)
{
_max = 0;
GraphView::setXLabel(tr("Distance"));
GraphView::setYLabel(tr("Speed"));
GraphView::setXUnits(tr("km"));
GraphView::setYUnits(tr("km/h"));
GraphView::setXScale(M2KM);
GraphView::setYScale(MS2KMH);
GraphView::setPrecision(1);
setXLabel(tr("Distance"));
setYLabel(tr("Speed"));
setXUnits(tr("km"));
setYUnits(tr("km/h"));
setXScale(M2KM);
setYScale(MS2KMH);
setPrecision(1);
}
void SpeedGraph::addInfo()
@ -31,14 +31,16 @@ void SpeedGraph::loadGPX(const GPX &gpx)
qreal max = 0;
gpx.track(i).speedGraph(data);
if (data.isEmpty())
if (data.count() < 2) {
skipColor();
continue;
}
_avg.append(QPointF(gpx.track(i).distance(), gpx.track(i).distance()
/ gpx.track(i).time()));
for (int i = 0; i < data.size(); i++)
max = qMax(max, data.at(i).y());
for (int j = 0; j < data.size(); j++)
max = qMax(max, data.at(j).y());
_max = qMax(_max, max);
addInfo();
@ -70,15 +72,15 @@ void SpeedGraph::clear()
void SpeedGraph::setUnits(enum Units units)
{
if (units == Metric) {
GraphView::setXUnits(tr("km"));
GraphView::setYUnits(tr("km/h"));
GraphView::setXScale(M2KM);
GraphView::setYScale(MS2KMH);
setXUnits(tr("km"));
setYUnits(tr("km/h"));
setXScale(M2KM);
setYScale(MS2KMH);
} else {
GraphView::setXUnits(tr("mi"));
GraphView::setYUnits(tr("mi/h"));
GraphView::setXScale(M2MI);
GraphView::setYScale(MS2MIH);
setXUnits(tr("mi"));
setYUnits(tr("mi/h"));
setXScale(M2MI);
setYScale(MS2MIH);
}
clearInfo();

View File

@ -6,6 +6,8 @@
#define WINDOW_EF 3
#define WINDOW_SE 11
#define WINDOW_SF 11
#define WINDOW_HE 7
#define WINDOW_HF 5
static bool lt(const QPointF &p1, const QPointF &p2)
{
@ -78,6 +80,18 @@ static QVector<QPointF> filter(const QVector<QPointF> &v, int window)
return ret;
}
Track::Track(const QVector<Trackpoint> &data) : _data(data)
{
_distance = 0;
for (int i = 1; i < _data.count(); i++)
_dd.append(llDistance(_data.at(i).coordinates,
_data.at(i-1).coordinates));
for (int i = 0; i < _dd.size(); i++)
_distance += _dd.at(i);
}
void Track::elevationGraph(QVector<QPointF> &graph) const
{
qreal dist = 0;
@ -86,12 +100,12 @@ void Track::elevationGraph(QVector<QPointF> &graph) const
if (!_data.size())
return;
if (isnan(_data.at(0).elevation))
if (std::isnan(_data.at(0).elevation))
return;
raw.append(QPointF(0, _data.at(0).elevation));
for (int i = 1; i < _data.size(); i++) {
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
if (isnan(_data.at(i).elevation))
dist += _dd.at(i-1);
if (std::isnan(_data.at(i).elevation))
return;
raw.append(QPointF(dist, _data.at(i).elevation
- _data.at(i).geoidheight));
@ -110,11 +124,11 @@ void Track::speedGraph(QVector<QPointF> &graph) const
raw.append(QPointF(0, 0));
for (int i = 1; i < _data.size(); i++) {
ds = llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
ds = _dd.at(i-1);
dt = _data.at(i-1).timestamp.msecsTo(_data.at(i).timestamp) / 1000.0;
dist += ds;
if (isnan(_data.at(i).speed)) {
if (std::isnan(_data.at(i).speed)) {
if (dt == 0)
continue;
v = ds / dt;
@ -127,22 +141,30 @@ void Track::speedGraph(QVector<QPointF> &graph) const
graph = filter(eliminate(raw, WINDOW_SE), WINDOW_SF);
}
void Track::heartRateGraph(QVector<QPointF> &graph) const
{
qreal dist = 0;
QVector<QPointF> raw;
if (std::isnan(_data.at(0).heartRate))
return;
raw.append(QPointF(0, _data.at(0).heartRate));
for (int i = 1; i < _data.count(); i++) {
if (std::isnan(_data.at(i).heartRate))
return;
dist += _dd.at(i-1);
raw.append(QPointF(dist, _data.at(i).heartRate));
}
graph = filter(eliminate(raw, WINDOW_HE), WINDOW_HF);
}
void Track::track(QVector<QPointF> &track) const
{
for (int i = 0; i < _data.size(); i++)
track.append(_data.at(i).coordinates);
}
qreal Track::distance() const
{
qreal dist = 0;
for (int i = 1; i < _data.size(); i++)
dist += llDistance(_data.at(i).coordinates, _data.at(i-1).coordinates);
return dist;
}
qreal Track::time() const
{
if (_data.size() < 2)

View File

@ -8,17 +8,20 @@
class Track
{
public:
Track(const QVector<Trackpoint> &data) : _data(data) {}
Track(const QVector<Trackpoint> &data);
void elevationGraph(QVector<QPointF> &graph) const;
void speedGraph(QVector<QPointF> &graph) const;
void heartRateGraph(QVector<QPointF> &graph) const;
void track(QVector<QPointF> &track) const;
qreal distance() const;
qreal distance() const {return _distance;}
qreal time() const;
QDateTime date() const;
private:
const QVector<Trackpoint> &_data;
QVector<qreal> _dd;
qreal _distance;
};
#endif // TRACK_H

View File

@ -12,8 +12,14 @@ struct Trackpoint
qreal elevation;
qreal geoidheight;
qreal speed;
qreal heartRate;
Trackpoint() {elevation = NAN; geoidheight = 0; speed = NAN;}
Trackpoint() {
elevation = NAN;
geoidheight = 0;
speed = NAN;
heartRate = NAN;
}
};
#endif // TRACKPOINT_H

View File

@ -34,7 +34,8 @@ TrackView::TrackView(QWidget *parent)
_zoom = ZOOM_MAX;
_scale = mapScale(_zoom);
_map = 0;
_maxLen = 0;
_maxPath = 0;
_maxDistance = 0;
}
TrackView::~TrackView()
@ -61,8 +62,7 @@ void TrackView::addTrack(const QVector<QPointF> &track)
path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
}
_maxLen = qMax(path.length(), _maxLen);
_maxPath = qMax(path.length(), _maxPath);
pi = new QGraphicsPathItem(path);
_paths.append(pi);
@ -108,6 +108,7 @@ void TrackView::loadGPX(const GPX &gpx)
QVector<QPointF> track;
gpx.track(i).track(track);
addTrack(track);
_maxDistance = qMax(gpx.track(i).distance(), _maxDistance);
}
addWaypoints(gpx.waypoints());
@ -403,7 +404,8 @@ void TrackView::clear()
_tracks.clear();
_waypoints.clear();
_maxLen = 0;
_maxPath = 0;
_maxDistance = 0;
_zoom = ZOOM_MAX;
_scale = mapScale(_zoom);
@ -412,11 +414,17 @@ void TrackView::clear()
void TrackView::movePositionMarker(qreal val)
{
qreal mp = val / _maxDistance;
for (int i = 0; i < _paths.size(); i++) {
qreal f = _maxLen / _paths.at(i)->path().length();
QPointF pos = _paths.at(i)->path().pointAtPercent(qMin(val * f,
1.0));
_markers.at(i)->setPos(pos);
qreal f = _maxPath / _paths.at(i)->path().length();
if (mp * f > 1.0)
_markers.at(i)->setVisible(false);
else {
QPointF pos = _paths.at(i)->path().pointAtPercent(mp * f);
_markers.at(i)->setPos(pos);
_markers.at(i)->setVisible(true);
}
}
}

View File

@ -75,7 +75,7 @@ private:
ScaleItem *_mapScale;
Palette _palette;
qreal _maxLen;
qreal _maxPath, _maxDistance;
qreal _scale;
int _zoom;