1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-27 11:39:16 +02:00

Added support for gear ratio graphs

Added support for FIT files from Bryton Rider devices
This commit is contained in:
2018-07-03 01:29:14 +02:00
parent cb80389d74
commit 3424b3e265
12 changed files with 300 additions and 34 deletions

View File

@ -0,0 +1,94 @@
#include "data/data.h"
#include "gearratiographitem.h"
#include "gearratiograph.h"
GearRatioGraph::GearRatioGraph(QWidget *parent) : GraphTab(parent)
{
_showTracks = true;
GraphView::setYUnits("");
setYLabel(tr("Gear ratio"));
setSliderPrecision(2);
}
void GearRatioGraph::setInfo()
{
if (_showTracks) {
GraphView::addInfo(tr("Most used"), QString::number(top() * yScale(),
'f', 2) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale(), 'f',
2) + UNIT_SPACE + yUnits());
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
2) + UNIT_SPACE + yUnits());
} else
clearInfo();
}
QList<GraphItem*> GearRatioGraph::loadData(const Data &data)
{
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {
const Graph &graph = data.tracks().at(i)->ratio();
if (graph.size() < 2) {
skipColor();
graphs.append(0);
} else {
GearRatioGraphItem *gi = new GearRatioGraphItem(graph, _graphType);
GraphView::addGraph(gi);
for (QMap<qreal, qreal>::const_iterator it = gi->map().constBegin();
it != gi->map().constEnd(); ++it)
_map.insert(it.key(), _map.value(it.key()) + it.value());
graphs.append(gi);
}
}
for (int i = 0; i < data.routes().count(); i++) {
skipColor();
graphs.append(0);
}
setInfo();
redraw();
return graphs;
}
qreal GearRatioGraph::top() const
{
qreal key, val;
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
it != _map.constEnd(); ++it) {
if (it == _map.constBegin()) {
val = it.value();
key = it.key();
} else if (it.value() > val) {
val = it.value();
key = it.key();
}
}
return key;
}
void GearRatioGraph::clear()
{
_map.clear();
GraphView::clear();
}
void GearRatioGraph::showTracks(bool show)
{
_showTracks = show;
showGraph(show);
setInfo();
redraw();
}

30
src/GUI/gearratiograph.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef GEARRATIOGRAPH_H
#define GEARRATIOGRAPH_H
#include <QMap>
#include "graphtab.h"
class GearRatioGraph : public GraphTab
{
Q_OBJECT
public:
GearRatioGraph(QWidget *parent = 0);
QString label() const {return tr("Gear ratio");}
QList<GraphItem*> loadData(const Data &data);
void clear();
void showTracks(bool show);
private:
qreal top() const;
qreal min() const {return bounds().top();}
qreal max() const {return bounds().bottom();}
void setInfo();
QMap<qreal, qreal> _map;
bool _showTracks;
};
#endif // GEARRATIOGRAPH_H

View File

@ -0,0 +1,39 @@
#include <QMap>
#include "tooltip.h"
#include "gearratiographitem.h"
GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent) : GraphItem(graph, type, parent)
{
qreal val;
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();
}

View File

@ -0,0 +1,28 @@
#ifndef GEARRATIOGRAPHITEM_H
#define GEARRATIOGRAPHITEM_H
#include <QMap>
#include "graphitem.h"
class GearRatioGraphItem : public GraphItem
{
Q_OBJECT
public:
GearRatioGraphItem(const Graph &graph, GraphType type,
QGraphicsItem *parent = 0);
qreal min() const {return -bounds().bottom();}
qreal max() const {return -bounds().top();}
qreal top() const {return _top;}
const QMap<qreal, qreal> &map() const {return _map;}
private:
QString toolTip() const;
QMap<qreal, qreal> _map;
qreal _top;
};
#endif // GEARRATIOGRAPHITEM_H

View File

@ -81,12 +81,14 @@ GraphView::~GraphView()
void GraphView::createXLabel()
{
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel, _xUnits));
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel,
_xUnits.isEmpty() ? "-" : _xUnits));
}
void GraphView::createYLabel()
{
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel, _yUnits));
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel,
_yUnits.isEmpty() ? "-" : _yUnits));
}
void GraphView::setYLabel(const QString &label)

View File

@ -37,6 +37,7 @@
#include "temperaturegraph.h"
#include "cadencegraph.h"
#include "powergraph.h"
#include "gearratiograph.h"
#include "mapview.h"
#include "trackinfo.h"
#include "filebrowser.h"
@ -556,6 +557,7 @@ void GUI::createGraphTabs()
_tabs.append(new CadenceGraph(_graphTabWidget));
_tabs.append(new PowerGraph(_graphTabWidget));
_tabs.append(new TemperatureGraph(_graphTabWidget));
_tabs.append(new GearRatioGraph(_graphTabWidget));
for (int i = 0; i < _tabs.count(); i++)
connect(_tabs.at(i), SIGNAL(sliderPositionChanged(qreal)), this,