1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/GUI/gearratiographitem.cpp

40 lines
955 B
C++
Raw Normal View History

#include <QMap>
#include "tooltip.h"
#include "gearratiographitem.h"
GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type,
2018-07-10 08:58:37 +02:00
QGraphicsItem *parent) : GraphItem(graph, type, parent), _top(NAN)
{
2018-07-03 19:16:51 +02:00
qreal val = NAN;
for (int j = 1; j < graph.size(); j++) {
const GraphPoint &p = graph.at(j);
qreal val = _map.value(p.y());
_map.insert(p.y(), val + (p.s() - graph.at(j-1).s()));
}
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
it != _map.constEnd(); ++it) {
if (it == _map.constBegin()) {
val = it.value();
_top = it.key();
} else if (it.value() > val) {
val = it.value();
_top = it.key();
}
}
setToolTip(toolTip());
}
QString GearRatioGraphItem::toolTip() const
{
ToolTip tt;
tt.insert(tr("Minimum"), QString::number(min(), 'f', 2));
tt.insert(tr("Maximum"), QString::number(max(), 'f', 2));
tt.insert(tr("Most used"), QString::number(top(), 'f', 2));
return tt.toString();
}