1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 15:23:22 +02:00
GPXSee/src/speedgraph.cpp

102 lines
1.7 KiB
C++
Raw Normal View History

#include "config.h"
2016-10-23 11:09:20 +02:00
#include "data.h"
2015-10-12 01:12:12 +02:00
#include "speedgraph.h"
2016-06-24 00:55:44 +02:00
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
2015-10-12 01:12:12 +02:00
{
_units = Metric;
2016-08-19 19:48:44 +02:00
_showTracks = true;
setYUnits();
setYLabel(tr("Speed"));
2016-03-27 13:23:00 +02:00
setSliderPrecision(1);
2015-10-12 01:12:12 +02:00
}
2016-08-09 01:16:19 +02:00
void SpeedGraph::setInfo()
2015-12-19 20:23:07 +01:00
{
2016-08-19 19:48:44 +02:00
if (_showTracks) {
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());
} else
clearInfo();
2015-12-19 20:23:07 +01:00
}
2016-10-23 11:09:20 +02:00
void SpeedGraph::loadData(const Data &data, const QList<PathItem *> &paths)
2015-10-12 01:12:12 +02:00
{
2016-10-23 11:09:20 +02:00
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->speed();
2016-09-19 23:35:04 +02:00
if (graph.size() < 2) {
skipColor();
continue;
}
2015-10-17 12:08:30 +02:00
2016-10-23 11:09:20 +02:00
_avg.append(QPointF(data.tracks().at(i)->distance(),
data.tracks().at(i)->distance() / data.tracks().at(i)->time()));
2016-09-19 00:56:10 +02:00
GraphView::loadGraph(graph, paths.at(i));
}
2016-03-27 13:23:00 +02:00
2016-10-23 11:09:20 +02:00
for (int i = 0; i < data.routes().count(); i++)
2016-08-09 01:16:19 +02:00
skipColor();
setInfo();
redraw();
2015-10-12 01:12:12 +02:00
}
qreal SpeedGraph::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);
}
2015-10-12 01:12:12 +02:00
void SpeedGraph::clear()
{
_avg.clear();
GraphView::clear();
2015-10-12 01:12:12 +02:00
}
2015-12-19 20:23:07 +01:00
void SpeedGraph::setYUnits()
2015-12-19 20:23:07 +01:00
{
if (_units == Metric) {
GraphView::setYUnits(tr("km/h"));
setYScale(MS2KMH);
2015-12-19 20:23:07 +01:00
} else {
GraphView::setYUnits(tr("mi/h"));
setYScale(MS2MIH);
2015-12-19 20:23:07 +01:00
}
}
void SpeedGraph::setUnits(enum Units units)
{
_units = units;
2016-08-09 01:16:19 +02:00
setYUnits();
2016-08-09 01:16:19 +02:00
setInfo();
2016-09-19 00:56:10 +02:00
GraphView::setUnits(units);
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
}
void SpeedGraph::showTracks(bool show)
{
2016-08-19 19:48:44 +02:00
_showTracks = show;
showGraph(show);
2016-08-20 11:28:08 +02:00
setInfo();
redraw();
}