2018-09-09 18:46:43 +02:00
|
|
|
#include <QLocale>
|
2018-07-03 01:29:14 +02:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2019-08-25 10:54:25 +02:00
|
|
|
GearRatioGraph::~GearRatioGraph()
|
|
|
|
{
|
|
|
|
qDeleteAll(_tracks);
|
|
|
|
}
|
|
|
|
|
2018-07-03 01:29:14 +02:00
|
|
|
void GearRatioGraph::setInfo()
|
|
|
|
{
|
|
|
|
if (_showTracks) {
|
2018-09-09 18:46:43 +02:00
|
|
|
QLocale l(QLocale::system());
|
|
|
|
|
|
|
|
GraphView::addInfo(tr("Most used"), l.toString(top() * yScale(),
|
2018-07-03 01:29:14 +02:00
|
|
|
'f', 2) + UNIT_SPACE + yUnits());
|
2018-09-09 18:46:43 +02:00
|
|
|
GraphView::addInfo(tr("Minimum"), l.toString(min() * yScale(), 'f',
|
2018-07-03 01:29:14 +02:00
|
|
|
2) + UNIT_SPACE + yUnits());
|
2018-09-09 18:46:43 +02:00
|
|
|
GraphView::addInfo(tr("Maximum"), l.toString(max() * yScale(), 'f',
|
2018-07-03 01:29:14 +02:00
|
|
|
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++) {
|
2019-01-31 01:46:53 +01:00
|
|
|
const Graph &graph = data.tracks().at(i).ratio();
|
2018-07-03 01:29:14 +02:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
if (!graph.isValid()) {
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2018-07-03 01:29:14 +02:00
|
|
|
graphs.append(0);
|
|
|
|
} else {
|
2019-08-25 10:54:25 +02:00
|
|
|
GearRatioGraphItem *gi = new GearRatioGraphItem(graph, _graphType,
|
|
|
|
_width, _palette.nextColor());
|
|
|
|
|
|
|
|
_tracks.append(gi);
|
|
|
|
if (_showTracks)
|
|
|
|
addGraph(gi);
|
2018-07-03 01:29:14 +02:00
|
|
|
|
|
|
|
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++) {
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2018-07-03 01:29:14 +02:00
|
|
|
graphs.append(0);
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < data.areas().count(); i++)
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2019-01-31 01:46:53 +01:00
|
|
|
|
2018-07-03 01:29:14 +02:00
|
|
|
setInfo();
|
|
|
|
redraw();
|
|
|
|
|
|
|
|
return graphs;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal GearRatioGraph::top() const
|
|
|
|
{
|
2018-07-03 19:16:51 +02:00
|
|
|
qreal key = NAN, val = NAN;
|
2018-07-03 01:29:14 +02:00
|
|
|
|
|
|
|
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
|
|
|
|
it != _map.constEnd(); ++it) {
|
2019-08-25 10:54:25 +02:00
|
|
|
if (std::isnan(val) || it.value() > val) {
|
2018-07-03 01:29:14 +02:00
|
|
|
val = it.value();
|
|
|
|
key = it.key();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GearRatioGraph::clear()
|
|
|
|
{
|
2019-08-25 10:54:25 +02:00
|
|
|
qDeleteAll(_tracks);
|
|
|
|
_tracks.clear();
|
|
|
|
|
2018-07-03 01:29:14 +02:00
|
|
|
_map.clear();
|
|
|
|
|
2019-03-05 22:34:50 +01:00
|
|
|
GraphTab::clear();
|
2018-07-03 01:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GearRatioGraph::showTracks(bool show)
|
|
|
|
{
|
|
|
|
_showTracks = show;
|
|
|
|
|
2019-08-25 10:54:25 +02:00
|
|
|
for (int i = 0; i < _tracks.size(); i++) {
|
|
|
|
if (show)
|
|
|
|
addGraph(_tracks.at(i));
|
|
|
|
else
|
|
|
|
removeGraph(_tracks.at(i));
|
|
|
|
}
|
|
|
|
|
2018-07-03 01:29:14 +02:00
|
|
|
setInfo();
|
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|