2018-09-09 18:46:43 +02:00
|
|
|
#include <QLocale>
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "tooltip.h"
|
|
|
|
#include "elevationgraphitem.h"
|
|
|
|
|
2018-09-09 18:46:43 +02:00
|
|
|
|
2017-10-04 23:15:39 +02:00
|
|
|
ElevationGraphItem::ElevationGraphItem(const Graph &graph, GraphType type,
|
2020-03-25 23:08:26 +01:00
|
|
|
int width, const QColor &color, Qt::PenStyle style, QGraphicsItem *parent)
|
|
|
|
: GraphItem(graph, type, width, color, style, parent)
|
2017-09-24 19:54:13 +02:00
|
|
|
{
|
2019-02-11 23:28:08 +01:00
|
|
|
_min = GraphItem::min();
|
|
|
|
_max = GraphItem::max();
|
2017-09-24 19:54:13 +02:00
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
_ascent = _descent = 0;
|
|
|
|
for (int i = 0; i < graph.size(); i++) {
|
|
|
|
const GraphSegment &segment = graph.at(i);
|
|
|
|
|
|
|
|
for (int j = 1; j < segment.size(); j++) {
|
|
|
|
qreal cur = segment.at(j).y();
|
|
|
|
qreal prev = segment.at(j-1).y();
|
|
|
|
|
|
|
|
if (cur > prev)
|
|
|
|
_ascent += cur - prev;
|
|
|
|
if (cur < prev)
|
|
|
|
_descent += prev - cur;
|
|
|
|
}
|
2017-09-24 19:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 08:57:42 +02:00
|
|
|
ToolTip ElevationGraphItem::info() const
|
2017-09-24 19:54:13 +02:00
|
|
|
{
|
|
|
|
ToolTip tt;
|
2019-10-15 23:59:15 +02:00
|
|
|
qreal scale = (_units == Metric) ? 1.0 : M2FT;
|
|
|
|
QString su = (_units == Metric) ? tr("m") : tr("ft");
|
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("Ascent"), l.toString(ascent() * scale, 'f', 0)
|
2017-09-24 19:54:13 +02:00
|
|
|
+ UNIT_SPACE + su);
|
2018-09-09 18:46:43 +02:00
|
|
|
tt.insert(tr("Descent"), l.toString(descent() * scale, 'f', 0)
|
2017-09-24 19:54:13 +02:00
|
|
|
+ UNIT_SPACE + su);
|
2018-09-09 18:46:43 +02:00
|
|
|
tt.insert(tr("Maximum"), l.toString(max() * scale, 'f', 0)
|
2017-09-24 19:54:13 +02:00
|
|
|
+ UNIT_SPACE + su);
|
2018-09-09 18:46:43 +02:00
|
|
|
tt.insert(tr("Minimum"), l.toString(min() * scale, 'f', 0)
|
2017-09-24 19:54:13 +02:00
|
|
|
+ UNIT_SPACE + su);
|
|
|
|
|
2021-08-04 08:57:42 +02:00
|
|
|
return tt;
|
2017-09-24 19:54:13 +02:00
|
|
|
}
|