1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-25 12:15:54 +01:00
GPXSee/src/GUI/gearratiograph.cpp

95 lines
1.8 KiB
C++
Raw Normal View History

#include "data/data.h"
#include "gearratiographitem.h"
#include "gearratiograph.h"
GearRatioGraph::GearRatioGraph(QWidget *parent) : GraphTab(parent)
{
_showTracks = true;
GraphView::setYUnits("");
setYLabel(tr("Gear ratio"));
setSliderPrecision(2);
}
void GearRatioGraph::setInfo()
{
if (_showTracks) {
GraphView::addInfo(tr("Most used"), QString::number(top() * yScale(),
'f', 2) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale(), 'f',
2) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
2) + UNIT_SPACE + yUnits());
} else
clearInfo();
}
QList<GraphItem*> GearRatioGraph::loadData(const Data &data)
{
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->ratio();
if (graph.size() < 2) {
skipColor();
graphs.append(0);
} else {
GearRatioGraphItem *gi = new GearRatioGraphItem(graph, _graphType);
GraphView::addGraph(gi);
for (QMap<qreal, qreal>::const_iterator it = gi->map().constBegin();
it != gi->map().constEnd(); ++it)
_map.insert(it.key(), _map.value(it.key()) + it.value());
graphs.append(gi);
}
}
for (int i = 0; i < data.routes().count(); i++) {
skipColor();
graphs.append(0);
}
setInfo();
redraw();
return graphs;
}
qreal GearRatioGraph::top() const
{
2018-07-03 19:16:51 +02:00
qreal key = NAN, val = NAN;
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
it != _map.constEnd(); ++it) {
if (it == _map.constBegin()) {
val = it.value();
key = it.key();
} else if (it.value() > val) {
val = it.value();
key = it.key();
}
}
return key;
}
void GearRatioGraph::clear()
{
_map.clear();
GraphView::clear();
}
void GearRatioGraph::showTracks(bool show)
{
_showTracks = show;
showGraph(show);
setInfo();
redraw();
}