Merge remote-tracking branch 'weblate/master'
[GPXSee.git] / src / GUI / speedgraphitem.cpp
blob268505f4e093e271f50013bc63b8ecbb9a65e49a
1 #include <QLocale>
2 #include "tooltip.h"
3 #include "format.h"
4 #include "speedgraphitem.h"
7 SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type, int width,
8 const QColor &color, Qt::PenStyle style, qreal movingTime,
9 QGraphicsItem *parent) : GraphItem(graph, type, width, color, style, parent)
11 _timeType = Total;
13 _max = GraphItem::max();
14 _avg = graph.last().last().s() / graph.last().last().t();
15 _mavg = graph.last().last().s() / movingTime;
18 ToolTip SpeedGraphItem::info() const
20 ToolTip tt;
21 qreal scale = (_units == Imperial) ? MS2MIH : (_units == Nautical)
22 ? MS2KN : MS2KMH;
23 QString su = (_units == Imperial) ? tr("mi/h") : (_units == Nautical)
24 ? tr("kn") : tr("km/h");
25 QString pace = Format::timeSpan((3600.0 / ((_timeType == Total)
26 ? avg() * scale : mavg() * scale)), false);
27 QString pu = (_units == Metric) ? tr("min/km") : (_units == Imperial) ?
28 tr("min/mi") : tr("min/nmi");
29 QLocale l(QLocale::system());
31 tt.insert(tr("Maximum"), l.toString(max() * scale, 'f', 1)
32 + UNIT_SPACE + su);
33 tt.insert(tr("Average"), l.toString((_timeType == Total)
34 ? avg() * scale : mavg() * scale, 'f', 1) + UNIT_SPACE + su);
35 tt.insert(tr("Pace"), pace + UNIT_SPACE + pu);
37 return tt;
40 void SpeedGraphItem::setTimeType(TimeType type)
42 _timeType = type;