2015-10-22 00:05:45 +02:00
|
|
|
#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"
|
|
|
|
|
2015-10-22 00:05:45 +02:00
|
|
|
|
2016-06-24 00:55:44 +02:00
|
|
|
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
2015-10-12 01:12:12 +02:00
|
|
|
{
|
2016-03-27 15:04:58 +02:00
|
|
|
_units = Metric;
|
2017-02-13 20:12:48 +01:00
|
|
|
_timeType = Total;
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = true;
|
2016-03-27 15:04:58 +02:00
|
|
|
|
|
|
|
setYUnits();
|
2016-03-21 22:37:55 +01:00
|
|
|
setYLabel(tr("Speed"));
|
2016-03-27 15:04:58 +02:00
|
|
|
|
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) {
|
2016-03-21 22:37:55 +01:00
|
|
|
skipColor();
|
2016-03-03 09:15:15 +01:00
|
|
|
continue;
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
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()));
|
2017-02-12 19:57:55 +01:00
|
|
|
_avgM.append(QPointF(data.tracks().at(i)->distance(),
|
|
|
|
data.tracks().at(i)->distance() / data.tracks().at(i)->movingTime()));
|
2015-10-15 01:30:21 +02:00
|
|
|
|
2016-09-19 00:56:10 +02:00
|
|
|
GraphView::loadGraph(graph, paths.at(i));
|
2016-02-08 17:53:09 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2015-10-19 00:35:08 +02:00
|
|
|
qreal SpeedGraph::avg() const
|
|
|
|
{
|
|
|
|
qreal sum = 0, w = 0;
|
|
|
|
QList<QPointF>::const_iterator it;
|
2017-02-12 19:57:55 +01:00
|
|
|
const QList<QPointF> &list = (_timeType == Moving) ? _avgM : _avg;
|
2015-10-19 00:35:08 +02:00
|
|
|
|
2017-02-12 19:57:55 +01:00
|
|
|
for (it = list.begin(); it != list.end(); it++) {
|
2015-10-19 00:35:08 +02:00
|
|
|
sum += it->y() * it->x();
|
|
|
|
w += it->x();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (sum / w);
|
|
|
|
}
|
|
|
|
|
2015-10-12 01:12:12 +02:00
|
|
|
void SpeedGraph::clear()
|
|
|
|
{
|
|
|
|
_avg.clear();
|
2017-02-12 19:57:55 +01:00
|
|
|
_avgM.clear();
|
2015-10-12 01:12:12 +02:00
|
|
|
|
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 SpeedGraph::setYUnits()
|
2015-12-19 20:23:07 +01:00
|
|
|
{
|
2016-03-27 15:04:58 +02:00
|
|
|
if (_units == Metric) {
|
|
|
|
GraphView::setYUnits(tr("km/h"));
|
2016-03-21 22:37:55 +01:00
|
|
|
setYScale(MS2KMH);
|
2015-12-19 20:23:07 +01:00
|
|
|
} else {
|
2016-03-27 15:04:58 +02:00
|
|
|
GraphView::setYUnits(tr("mi/h"));
|
2016-03-21 22:37:55 +01:00
|
|
|
setYScale(MS2MIH);
|
2015-12-19 20:23:07 +01:00
|
|
|
}
|
2016-03-27 15:04:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpeedGraph::setUnits(enum Units units)
|
|
|
|
{
|
|
|
|
_units = units;
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2016-03-27 15:04:58 +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
|
|
|
}
|
2016-08-16 00:27:54 +02:00
|
|
|
|
2017-02-12 19:57:55 +01:00
|
|
|
void SpeedGraph::setTimeType(enum TimeType type)
|
|
|
|
{
|
|
|
|
_timeType = type;
|
|
|
|
|
|
|
|
setInfo();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2016-08-16 00:27:54 +02:00
|
|
|
void SpeedGraph::showTracks(bool show)
|
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = show;
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
showGraph(show);
|
2016-08-20 11:28:08 +02:00
|
|
|
setInfo();
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|