2018-09-09 18:46:43 +02:00
|
|
|
#include <QLocale>
|
2017-11-26 18:54:03 +01:00
|
|
|
#include "data/data.h"
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "heartrategraphitem.h"
|
2016-03-21 22:37:55 +01:00
|
|
|
#include "heartrategraph.h"
|
|
|
|
|
|
|
|
|
2016-06-24 00:55:44 +02:00
|
|
|
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
2016-03-21 22:37:55 +01:00
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = true;
|
2016-03-27 15:04:58 +02:00
|
|
|
|
2018-09-09 15:27:44 +02:00
|
|
|
GraphView::setYUnits(tr("bpm"));
|
2016-03-21 22:37:55 +01:00
|
|
|
setYLabel(tr("Heart rate"));
|
2016-03-27 15:04:58 +02:00
|
|
|
|
2016-03-27 13:23:00 +02:00
|
|
|
setSliderPrecision(0);
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
2019-08-25 10:54:25 +02:00
|
|
|
HeartRateGraph::~HeartRateGraph()
|
|
|
|
{
|
|
|
|
qDeleteAll(_tracks);
|
|
|
|
}
|
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
void HeartRateGraph::setInfo()
|
2016-03-21 22:37:55 +01:00
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
if (_showTracks) {
|
2018-09-09 18:46:43 +02:00
|
|
|
QLocale l(QLocale::system());
|
|
|
|
|
|
|
|
GraphView::addInfo(tr("Average"), l.toString(avg() * yScale(), 'f',
|
2016-08-19 19:48:44 +02:00
|
|
|
0) + UNIT_SPACE + yUnits());
|
2018-09-09 18:46:43 +02:00
|
|
|
GraphView::addInfo(tr("Maximum"), l.toString(max() * yScale(), 'f',
|
2016-08-19 19:48:44 +02:00
|
|
|
0) + UNIT_SPACE + yUnits());
|
|
|
|
} else
|
|
|
|
clearInfo();
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
2018-05-04 19:36:37 +02:00
|
|
|
QList<GraphItem*> HeartRateGraph::loadData(const Data &data)
|
2016-03-21 22:37:55 +01:00
|
|
|
{
|
2018-05-04 19:36:37 +02:00
|
|
|
QList<GraphItem*> graphs;
|
|
|
|
|
2016-10-23 11:09:20 +02:00
|
|
|
for (int i = 0; i < data.tracks().count(); i++) {
|
2019-01-31 01:46:53 +01:00
|
|
|
const Track &track = data.tracks().at(i);
|
|
|
|
const Graph &graph = track.heartRate();
|
2016-03-21 22:37:55 +01:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
if (!graph.isValid()) {
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
} else {
|
2019-08-25 10:54:25 +02:00
|
|
|
HeartRateGraphItem *gi = new HeartRateGraphItem(graph, _graphType,
|
|
|
|
_width, _palette.nextColor());
|
|
|
|
|
|
|
|
_tracks.append(gi);
|
|
|
|
if (_showTracks)
|
|
|
|
addGraph(gi);
|
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
_avg.append(QPointF(track.distance(), gi->avg()));
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(gi);
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-27 13:23:00 +02:00
|
|
|
|
2018-05-04 19:36:37 +02:00
|
|
|
for (int i = 0; i < data.routes().count(); i++) {
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2018-05-04 19:36:37 +02:00
|
|
|
graphs.append(0);
|
|
|
|
}
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2019-01-31 01:46:53 +01:00
|
|
|
for (int i = 0; i < data.areas().count(); i++)
|
2019-08-25 10:54:25 +02:00
|
|
|
_palette.nextColor();
|
2019-01-31 01:46:53 +01:00
|
|
|
|
2016-08-09 01:16:19 +02:00
|
|
|
setInfo();
|
|
|
|
redraw();
|
2018-05-04 19:36:37 +02:00
|
|
|
|
|
|
|
return graphs;
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal HeartRateGraph::avg() const
|
|
|
|
{
|
|
|
|
qreal sum = 0, w = 0;
|
|
|
|
|
2019-03-15 19:43:17 +01:00
|
|
|
for (int i = 0; i < _avg.size(); i++) {
|
|
|
|
const QPointF &p = _avg.at(i);
|
|
|
|
sum += p.y() * p.x();
|
|
|
|
w += p.x();
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (sum / w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HeartRateGraph::clear()
|
|
|
|
{
|
2019-08-25 10:54:25 +02:00
|
|
|
qDeleteAll(_tracks);
|
|
|
|
_tracks.clear();
|
|
|
|
|
2016-03-21 22:37:55 +01:00
|
|
|
_avg.clear();
|
|
|
|
|
2019-03-05 22:34:50 +01:00
|
|
|
GraphTab::clear();
|
2016-03-21 22:37:55 +01:00
|
|
|
}
|
|
|
|
|
2016-08-16 00:27:54 +02:00
|
|
|
void HeartRateGraph::showTracks(bool show)
|
|
|
|
{
|
2016-08-19 19:48:44 +02:00
|
|
|
_showTracks = show;
|
2016-08-16 00:27:54 +02:00
|
|
|
|
2019-08-25 10:54:25 +02:00
|
|
|
for (int i = 0; i < _tracks.size(); i++) {
|
|
|
|
if (show)
|
|
|
|
addGraph(_tracks.at(i));
|
|
|
|
else
|
|
|
|
removeGraph(_tracks.at(i));
|
|
|
|
}
|
|
|
|
|
2016-08-20 11:28:08 +02:00
|
|
|
setInfo();
|
2016-08-16 00:27:54 +02:00
|
|
|
|
|
|
|
redraw();
|
|
|
|
}
|