Merge remote-tracking branch 'weblate/master'
[GPXSee.git] / src / GUI / gearratiographitem.cpp
blobcb116c0f25e3570b319e11e9fb5508f0aaeda79a
1 #include <QMap>
2 #include <QLocale>
3 #include "tooltip.h"
4 #include "gearratiographitem.h"
7 GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type,
8 int width, const QColor &color, QGraphicsItem *parent)
9 : GraphItem(graph, type, width, color, Qt::SolidLine, parent)
11 for (int i = 0; i < graph.size(); i++) {
12 const GraphSegment &segment = graph.at(i);
13 for (int j = 1; j < segment.size(); j++) {
14 qreal dx = segment.at(j).s() - segment.at(j-1).s();
15 _map.insert(segment.at(j).y(), _map.value(segment.at(j).y()) + dx);
19 qreal key = NAN, val = NAN;
20 for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
21 it != _map.constEnd(); ++it) {
22 if (std::isnan(val) || it.value() > val) {
23 val = it.value();
24 key = it.key();
27 _top = key;
30 ToolTip GearRatioGraphItem::info() const
32 ToolTip tt;
33 QLocale l(QLocale::system());
35 tt.insert(tr("Minimum"), l.toString(min(), 'f', 2));
36 tt.insert(tr("Maximum"), l.toString(max(), 'f', 2));
37 tt.insert(tr("Most used"), l.toString(top(), 'f', 2));
39 return tt;