2015-10-12 01:12:12 +02:00
|
|
|
#include <float.h>
|
2015-10-22 00:05:45 +02:00
|
|
|
#include "config.h"
|
2016-02-12 10:23:14 +01:00
|
|
|
#include "gpx.h"
|
2015-10-12 01:12:12 +02:00
|
|
|
#include "elevationgraph.h"
|
|
|
|
|
2015-11-25 23:58:46 +01:00
|
|
|
|
2016-02-11 20:58:52 +01:00
|
|
|
ElevationGraph::ElevationGraph(QWidget *parent) : GraphView(parent)
|
2015-10-12 01:12:12 +02:00
|
|
|
{
|
|
|
|
_ascent = 0;
|
|
|
|
_descent = 0;
|
|
|
|
_max = -FLT_MAX;
|
|
|
|
_min = FLT_MAX;
|
|
|
|
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::setXLabel(tr("Distance"));
|
|
|
|
GraphView::setYLabel(tr("Elevation"));
|
|
|
|
GraphView::setXUnits(tr("km"));
|
|
|
|
GraphView::setYUnits(tr("m"));
|
|
|
|
GraphView::setXScale(M2KM);
|
2015-12-19 20:23:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ElevationGraph::addInfo()
|
|
|
|
{
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::addInfo(tr("Ascent"), QString::number(_ascent * _yScale, 'f', 0)
|
2016-02-13 12:13:56 +01:00
|
|
|
+ UNIT_SPACE + _yUnits);
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::addInfo(tr("Descent"), QString::number(_descent * _yScale, 'f', 0)
|
2016-02-13 12:13:56 +01:00
|
|
|
+ UNIT_SPACE + _yUnits);
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::addInfo(tr("Maximum"), QString::number(_max * _yScale, 'f', 0)
|
2016-02-13 12:13:56 +01:00
|
|
|
+ UNIT_SPACE + _yUnits);
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::addInfo(tr("Minimum"), QString::number(_min * _yScale, 'f', 0)
|
2016-02-13 12:13:56 +01:00
|
|
|
+ UNIT_SPACE + _yUnits);
|
2015-10-12 01:12:12 +02:00
|
|
|
}
|
|
|
|
|
2015-10-17 12:08:30 +02:00
|
|
|
void ElevationGraph::loadGPX(const GPX &gpx)
|
2015-10-12 01:12:12 +02:00
|
|
|
{
|
2016-02-11 20:58:52 +01:00
|
|
|
for (int i = 0; i < gpx.trackCount(); i++) {
|
2016-02-08 17:53:09 +01:00
|
|
|
QVector<QPointF> data;
|
|
|
|
qreal min, max, ascent = 0, descent = 0;
|
|
|
|
|
2016-02-11 20:58:52 +01:00
|
|
|
gpx.track(i).elevationGraph(data);
|
2016-02-08 17:53:09 +01:00
|
|
|
if (data.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (cur > prev)
|
|
|
|
ascent += cur - prev;
|
|
|
|
if (cur < prev)
|
|
|
|
descent += prev - cur;
|
|
|
|
|
|
|
|
if (cur > max)
|
|
|
|
max = cur;
|
|
|
|
if (cur < min)
|
|
|
|
min = cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ascent += ascent;
|
|
|
|
_descent += descent;
|
|
|
|
_max = qMax(_max, max);
|
|
|
|
_min = qMin(_min, min);
|
|
|
|
|
|
|
|
addInfo();
|
|
|
|
loadData(data);
|
2015-10-12 01:12:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElevationGraph::clear()
|
|
|
|
{
|
|
|
|
_ascent = 0;
|
|
|
|
_descent = 0;
|
|
|
|
_max = -FLT_MAX;
|
|
|
|
_min = FLT_MAX;
|
|
|
|
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::clear();
|
2015-10-12 01:12:12 +02:00
|
|
|
}
|
2015-12-19 20:23:07 +01:00
|
|
|
|
|
|
|
void ElevationGraph::setUnits(enum Units units)
|
|
|
|
{
|
|
|
|
if (units == Metric) {
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::setXUnits(tr("km"));
|
|
|
|
GraphView::setYUnits(tr("m"));
|
|
|
|
GraphView::setXScale(M2KM);
|
|
|
|
GraphView::setYScale(1);
|
2015-12-19 20:23:07 +01:00
|
|
|
} else {
|
2016-02-11 20:58:52 +01:00
|
|
|
GraphView::setXUnits(tr("mi"));
|
|
|
|
GraphView::setYUnits(tr("ft"));
|
|
|
|
GraphView::setXScale(M2MI);
|
|
|
|
GraphView::setYScale(M2FT);
|
2015-12-19 20:23:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
clearInfo();
|
|
|
|
addInfo();
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|