1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/GUI/cadencegraph.cpp

88 lines
1.6 KiB
C++
Raw Normal View History

#include <QLocale>
2017-11-26 18:54:03 +01:00
#include "data/data.h"
#include "cadencegraphitem.h"
2016-11-06 03:28:08 +01:00
#include "cadencegraph.h"
CadenceGraph::CadenceGraph(QWidget *parent) : GraphTab(parent)
{
_showTracks = true;
GraphView::setYUnits(tr("rpm"));
2016-11-06 03:28:08 +01:00
setYLabel(tr("Cadence"));
setSliderPrecision(1);
}
void CadenceGraph::setInfo()
{
if (_showTracks) {
QLocale l(QLocale::system());
GraphView::addInfo(tr("Average"), l.toString(avg() * yScale()
2016-11-06 03:28:08 +01:00
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), l.toString(max() * yScale()
2016-11-06 03:28:08 +01:00
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
} else
clearInfo();
}
QList<GraphItem*> CadenceGraph::loadData(const Data &data)
2016-11-06 03:28:08 +01:00
{
QList<GraphItem*> graphs;
2016-11-06 03:28:08 +01:00
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->cadence();
if (graph.size() < 2) {
skipColor();
graphs.append(0);
} else {
CadenceGraphItem *gi = new CadenceGraphItem(graph, _graphType);
GraphView::addGraph(gi);
_avg.append(QPointF(data.tracks().at(i)->distance(), gi->avg()));
graphs.append(gi);
2016-11-06 03:28:08 +01:00
}
}
for (int i = 0; i < data.routes().count(); i++) {
2016-11-06 03:28:08 +01:00
skipColor();
graphs.append(0);
}
2016-11-06 03:28:08 +01:00
setInfo();
redraw();
return graphs;
2016-11-06 03:28:08 +01:00
}
qreal CadenceGraph::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 CadenceGraph::clear()
{
_avg.clear();
GraphView::clear();
}
void CadenceGraph::showTracks(bool show)
{
_showTracks = show;
showGraph(show);
setInfo();
redraw();
}