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-06-24 00:55:44 +02:00
|
|
|
ElevationGraph::ElevationGraph(QWidget *parent) : GraphTab(parent)
|
2015-10-12 01:12:12 +02:00
|
|
|
{
|
|
|
|
_ascent = 0;
|
|
|
|
_descent = 0;
|
|
|
|
|
2016-03-27 15:04:58 +02:00
|
|
|
_units = Metric;
|
|
|
|
|
|
|
|
setYUnits();
|
2016-03-21 22:37:55 +01:00
|
|
|
setXLabel(tr("Distance"));
|
|
|
|
setYLabel(tr("Elevation"));
|
2016-03-27 15:04:58 +02:00
|
|
|
|
2016-03-27 13:23:00 +02:00
|
|
|
setMinYRange(50.0);
|
2015-12-19 20:23:07 +01:00
|
|
|
}
|
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
void ElevationGraph::setInfo()
|
2015-12-19 20:23:07 +01:00
|
|
|
{
|
2016-03-27 13:23:00 +02:00
|
|
|
GraphView::addInfo(tr("Ascent"), QString::number(_ascent * yScale(), 'f', 0)
|
|
|
|
+ UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Descent"), QString::number(_descent * yScale(), 'f',
|
|
|
|
0) + UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 0)
|
|
|
|
+ UNIT_SPACE + yUnits());
|
|
|
|
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale(), 'f', 0)
|
|
|
|
+ UNIT_SPACE + yUnits());
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
2016-03-27 13:23:00 +02:00
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
void ElevationGraph::loadPath(const QVector<QPointF> &data)
|
|
|
|
{
|
|
|
|
qreal ascent = 0, descent = 0;
|
|
|
|
|
|
|
|
if (data.count() < 2) {
|
|
|
|
skipColor();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (cur < prev)
|
|
|
|
descent += prev - cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
_ascent += ascent;
|
|
|
|
_descent += descent;
|
|
|
|
|
|
|
|
loadData(data);
|
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-08-09 23:08:49 +02:00
|
|
|
for (int i = 0; i < gpx.tracks().count(); i++)
|
|
|
|
loadPath(gpx.tracks().at(i)->elevation());
|
|
|
|
for (int i = 0; i < gpx.routes().count(); i++)
|
|
|
|
loadPath(gpx.routes().at(i)->elevation());
|
2016-03-27 13:23:00 +02:00
|
|
|
|
2016-03-27 15:04:58 +02:00
|
|
|
setXUnits();
|
2016-08-09 01:16:19 +02:00
|
|
|
setInfo();
|
|
|
|
|
|
|
|
redraw();
|
2015-10-12 01:12:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ElevationGraph::clear()
|
|
|
|
{
|
|
|
|
_ascent = 0;
|
|
|
|
_descent = 0;
|
|
|
|
|
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
|
|
|
|
2016-03-27 15:04:58 +02:00
|
|
|
void ElevationGraph::setXUnits()
|
|
|
|
{
|
|
|
|
if (_units == Metric) {
|
|
|
|
if (bounds().width() < KMINM) {
|
|
|
|
GraphView::setXUnits(tr("m"));
|
|
|
|
setXScale(1);
|
|
|
|
} else {
|
|
|
|
GraphView::setXUnits(tr("km"));
|
|
|
|
setXScale(M2KM);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (bounds().width() < MIINM) {
|
|
|
|
GraphView::setXUnits(tr("ft"));
|
|
|
|
setXScale(M2FT);
|
|
|
|
} else {
|
|
|
|
GraphView::setXUnits(tr("mi"));
|
|
|
|
setXScale(M2MI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ElevationGraph::setYUnits()
|
2015-12-19 20:23:07 +01:00
|
|
|
{
|
2016-03-27 15:04:58 +02:00
|
|
|
if (_units == Metric) {
|
|
|
|
GraphView::setYUnits(tr("m"));
|
2016-03-21 22:37:55 +01:00
|
|
|
setYScale(1);
|
2015-12-19 20:23:07 +01:00
|
|
|
} else {
|
2016-03-27 15:04:58 +02:00
|
|
|
GraphView::setYUnits(tr("ft"));
|
2016-03-21 22:37:55 +01:00
|
|
|
setYScale(M2FT);
|
2015-12-19 20:23:07 +01:00
|
|
|
}
|
2016-03-27 15:04:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ElevationGraph::setUnits(enum Units units)
|
|
|
|
{
|
|
|
|
_units = units;
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2016-03-27 15:04:58 +02:00
|
|
|
setXUnits();
|
|
|
|
setYUnits();
|
2016-08-09 01:16:19 +02:00
|
|
|
setInfo();
|
2015-12-19 20:23:07 +01:00
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
redraw();
|
2015-12-19 20:23:07 +01:00
|
|
|
}
|