Added Israleli grid projection
[GPXSee.git] / src / GUI / gearratiograph.cpp
blob4e731ebd028cfcd4505ed9d42e1763dd9179c4ed
1 #include <QLocale>
2 #include "data/data.h"
3 #include "gearratiographitem.h"
4 #include "gearratiograph.h"
7 GearRatioGraph::GearRatioGraph(QWidget *parent) : GraphTab(parent)
9 _showTracks = false;
11 GraphView::setYUnits("");
12 setYLabel(tr("Gear ratio"));
14 setSliderPrecision(2);
17 GearRatioGraph::~GearRatioGraph()
19 qDeleteAll(_tracks);
22 void GearRatioGraph::setInfo()
24 if (_showTracks) {
25 QLocale l(QLocale::system());
27 #ifdef Q_OS_ANDROID
28 GraphView::addInfo(tr("Top"), l.toString(top() * yScale(), 'f', 2)
29 + UNIT_SPACE + yUnits());
30 GraphView::addInfo(tr("Min"), l.toString(min() * yScale(), 'f', 2)
31 + UNIT_SPACE + yUnits());
32 GraphView::addInfo(tr("Max"), l.toString(max() * yScale(), 'f', 2)
33 + UNIT_SPACE + yUnits());
34 #else // Q_OS_ANDROID
35 GraphView::addInfo(tr("Most used"), l.toString(top() * yScale(),
36 'f', 2) + UNIT_SPACE + yUnits());
37 GraphView::addInfo(tr("Minimum"), l.toString(min() * yScale(), 'f',
38 2) + UNIT_SPACE + yUnits());
39 GraphView::addInfo(tr("Maximum"), l.toString(max() * yScale(), 'f',
40 2) + UNIT_SPACE + yUnits());
41 #endif // Q_OS_ANDROID
42 } else
43 clearInfo();
46 QList<GraphItem*> GearRatioGraph::loadData(const Data &data, Map *map)
48 Q_UNUSED(map);
49 QList<GraphItem*> graphs;
51 for (int i = 0; i < data.tracks().count(); i++) {
52 const Graph &graph = data.tracks().at(i).ratio();
54 if (graph.isEmpty()) {
55 _palette.nextColor();
56 graphs.append(0);
57 } else {
58 GearRatioGraphItem *gi = new GearRatioGraphItem(graph, _graphType,
59 _width, _palette.nextColor());
61 _tracks.append(gi);
62 if (_showTracks)
63 addGraph(gi);
65 for (QMap<qreal, qreal>::const_iterator it = gi->map().constBegin();
66 it != gi->map().constEnd(); ++it)
67 _map.insert(it.key(), _map.value(it.key()) + it.value());
68 graphs.append(gi);
72 for (int i = 0; i < data.routes().count(); i++) {
73 _palette.nextColor();
74 graphs.append(0);
77 for (int i = 0; i < data.areas().count(); i++)
78 _palette.nextColor();
80 setInfo();
81 redraw();
83 return graphs;
86 qreal GearRatioGraph::top() const
88 qreal key = NAN, val = NAN;
90 for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
91 it != _map.constEnd(); ++it) {
92 if (std::isnan(val) || it.value() > val) {
93 val = it.value();
94 key = it.key();
98 return key;
101 void GearRatioGraph::clear()
103 qDeleteAll(_tracks);
104 _tracks.clear();
106 _map.clear();
108 GraphTab::clear();
111 void GearRatioGraph::showTracks(bool show)
113 _showTracks = show;
115 for (int i = 0; i < _tracks.size(); i++) {
116 if (show)
117 addGraph(_tracks.at(i));
118 else
119 removeGraph(_tracks.at(i));
122 setInfo();
124 redraw();