2018-09-09 18:46:43 +02:00
|
|
|
#include <QLocale>
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "tooltip.h"
|
2018-03-10 20:25:13 +01:00
|
|
|
#include "format.h"
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "speedgraphitem.h"
|
|
|
|
|
2018-09-09 18:46:43 +02:00
|
|
|
|
2019-08-25 10:54:25 +02:00
|
|
|
SpeedGraphItem::SpeedGraphItem(const Graph &graph, GraphType type, int width,
|
2020-03-25 23:08:26 +01:00
|
|
|
const QColor &color, Qt::PenStyle style, qreal movingTime,
|
|
|
|
QGraphicsItem *parent) : GraphItem(graph, type, width, color, style, parent)
|
2017-09-24 19:54:13 +02:00
|
|
|
{
|
2017-09-25 19:56:04 +02:00
|
|
|
_timeType = Total;
|
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
_max = GraphItem::max();
|
|
|
|
_avg = graph.last().last().s() / graph.last().last().t();
|
|
|
|
_mavg = graph.last().last().s() / movingTime;
|
2017-09-24 19:54:13 +02:00
|
|
|
}
|
|
|
|
|
2019-10-15 23:59:15 +02:00
|
|
|
QString SpeedGraphItem::info() const
|
2017-09-24 19:54:13 +02:00
|
|
|
{
|
|
|
|
ToolTip tt;
|
2019-10-15 23:59:15 +02:00
|
|
|
qreal scale = (_units == Imperial) ? MS2MIH : (_units == Nautical)
|
2018-02-11 23:51:57 +01:00
|
|
|
? MS2KN : MS2KMH;
|
2019-10-15 23:59:15 +02:00
|
|
|
QString su = (_units == Imperial) ? tr("mi/h") : (_units == Nautical)
|
2018-02-11 23:51:57 +01:00
|
|
|
? tr("kn") : tr("km/h");
|
2018-03-10 20:25:13 +01:00
|
|
|
QString pace = Format::timeSpan((3600.0 / ((_timeType == Total)
|
|
|
|
? avg() * scale : mavg() * scale)), false);
|
2019-10-15 23:59:15 +02:00
|
|
|
QString pu = (_units == Metric) ? tr("min/km") : (_units == Imperial) ?
|
2018-03-10 20:25:13 +01:00
|
|
|
tr("min/mi") : tr("min/nmi");
|
2018-09-09 18:46:43 +02:00
|
|
|
QLocale l(QLocale::system());
|
2017-09-24 19:54:13 +02:00
|
|
|
|
2018-09-09 18:46:43 +02:00
|
|
|
tt.insert(tr("Maximum"), l.toString(max() * scale, 'f', 1)
|
2017-09-24 19:54:13 +02:00
|
|
|
+ UNIT_SPACE + su);
|
2018-09-09 18:46:43 +02:00
|
|
|
tt.insert(tr("Average"), l.toString((_timeType == Total)
|
2017-09-25 19:56:04 +02:00
|
|
|
? avg() * scale : mavg() * scale, 'f', 1) + UNIT_SPACE + su);
|
2018-03-10 20:25:13 +01:00
|
|
|
tt.insert(tr("Pace"), pace + UNIT_SPACE + pu);
|
2017-09-24 19:54:13 +02:00
|
|
|
|
|
|
|
return tt.toString();
|
|
|
|
}
|
|
|
|
|
2017-09-25 19:56:04 +02:00
|
|
|
void SpeedGraphItem::setTimeType(TimeType type)
|
|
|
|
{
|
|
|
|
_timeType = type;
|
2017-09-24 19:54:13 +02:00
|
|
|
}
|