mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Some more graph handling improvements
This commit is contained in:
parent
d48a2aac93
commit
0ee0bd882e
@ -87,7 +87,8 @@ SOURCES += src/main.cpp \
|
|||||||
src/trackitem.cpp \
|
src/trackitem.cpp \
|
||||||
src/tooltip.cpp \
|
src/tooltip.cpp \
|
||||||
src/route.cpp \
|
src/route.cpp \
|
||||||
src/routeitem.cpp
|
src/routeitem.cpp \
|
||||||
|
src/graphitem.cpp
|
||||||
RESOURCES += gpxsee.qrc
|
RESOURCES += gpxsee.qrc
|
||||||
TRANSLATIONS = lang/gpxsee_cs.ts
|
TRANSLATIONS = lang/gpxsee_cs.ts
|
||||||
macx {
|
macx {
|
||||||
|
@ -536,48 +536,48 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>HeartRateGraph</name>
|
<name>HeartRateGraph</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="10"/>
|
<location filename="../src/heartrategraph.cpp" line="11"/>
|
||||||
<source>Distance</source>
|
<source>Distance</source>
|
||||||
<translation>Vzdálenost</translation>
|
<translation>Vzdálenost</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="11"/>
|
<location filename="../src/heartrategraph.cpp" line="12"/>
|
||||||
<location filename="../src/heartrategraph.h" line="15"/>
|
<location filename="../src/heartrategraph.h" line="15"/>
|
||||||
<source>Heart rate</source>
|
<source>Heart rate</source>
|
||||||
<translation>Tep</translation>
|
<translation>Tep</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="80"/>
|
<location filename="../src/heartrategraph.cpp" line="84"/>
|
||||||
<source>km</source>
|
<source>km</source>
|
||||||
<translation>km</translation>
|
<translation>km</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="9"/>
|
<location filename="../src/heartrategraph.cpp" line="10"/>
|
||||||
<source>1/min</source>
|
<source>1/min</source>
|
||||||
<translation>1/min</translation>
|
<translation>1/min</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="18"/>
|
<location filename="../src/heartrategraph.cpp" line="20"/>
|
||||||
<source>Average</source>
|
<source>Average</source>
|
||||||
<translation>Průměr</translation>
|
<translation>Průměr</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="20"/>
|
<location filename="../src/heartrategraph.cpp" line="22"/>
|
||||||
<source>Maximum</source>
|
<source>Maximum</source>
|
||||||
<translation>Maximum</translation>
|
<translation>Maximum</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="77"/>
|
<location filename="../src/heartrategraph.cpp" line="81"/>
|
||||||
<source>m</source>
|
<source>m</source>
|
||||||
<translation>m</translation>
|
<translation>m</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="85"/>
|
<location filename="../src/heartrategraph.cpp" line="89"/>
|
||||||
<source>ft</source>
|
<source>ft</source>
|
||||||
<translation>ft</translation>
|
<translation>ft</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/heartrategraph.cpp" line="88"/>
|
<location filename="../src/heartrategraph.cpp" line="92"/>
|
||||||
<source>mi</source>
|
<source>mi</source>
|
||||||
<translation>mi</translation>
|
<translation>mi</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -633,53 +633,53 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>SpeedGraph</name>
|
<name>SpeedGraph</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="11"/>
|
<location filename="../src/speedgraph.cpp" line="12"/>
|
||||||
<source>Distance</source>
|
<source>Distance</source>
|
||||||
<translation>Vzdálenost</translation>
|
<translation>Vzdálenost</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="12"/>
|
<location filename="../src/speedgraph.cpp" line="13"/>
|
||||||
<location filename="../src/speedgraph.h" line="16"/>
|
<location filename="../src/speedgraph.h" line="16"/>
|
||||||
<source>Speed</source>
|
<source>Speed</source>
|
||||||
<translation>Rychlost</translation>
|
<translation>Rychlost</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="73"/>
|
<location filename="../src/speedgraph.cpp" line="77"/>
|
||||||
<source>m</source>
|
<source>m</source>
|
||||||
<translation>m</translation>
|
<translation>m</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="76"/>
|
<location filename="../src/speedgraph.cpp" line="80"/>
|
||||||
<source>km</source>
|
<source>km</source>
|
||||||
<translation></translation>
|
<translation></translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="81"/>
|
<location filename="../src/speedgraph.cpp" line="85"/>
|
||||||
<source>ft</source>
|
<source>ft</source>
|
||||||
<translation>ft</translation>
|
<translation>ft</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="93"/>
|
<location filename="../src/speedgraph.cpp" line="97"/>
|
||||||
<source>km/h</source>
|
<source>km/h</source>
|
||||||
<translation>km/h</translation>
|
<translation>km/h</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="19"/>
|
<location filename="../src/speedgraph.cpp" line="21"/>
|
||||||
<source>Average</source>
|
<source>Average</source>
|
||||||
<translation>Průměr</translation>
|
<translation>Průměr</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="21"/>
|
<location filename="../src/speedgraph.cpp" line="23"/>
|
||||||
<source>Maximum</source>
|
<source>Maximum</source>
|
||||||
<translation>Maximum</translation>
|
<translation>Maximum</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="84"/>
|
<location filename="../src/speedgraph.cpp" line="88"/>
|
||||||
<source>mi</source>
|
<source>mi</source>
|
||||||
<translation>mi</translation>
|
<translation>mi</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/speedgraph.cpp" line="96"/>
|
<location filename="../src/speedgraph.cpp" line="100"/>
|
||||||
<source>mi/h</source>
|
<source>mi/h</source>
|
||||||
<translation>mi/h</translation>
|
<translation>mi/h</translation>
|
||||||
</message>
|
</message>
|
||||||
@ -687,58 +687,58 @@
|
|||||||
<context>
|
<context>
|
||||||
<name>TemperatureGraph</name>
|
<name>TemperatureGraph</name>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="10"/>
|
<location filename="../src/temperaturegraph.cpp" line="11"/>
|
||||||
<source>Distance</source>
|
<source>Distance</source>
|
||||||
<translation>Vzdálenost</translation>
|
<translation>Vzdálenost</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="11"/>
|
<location filename="../src/temperaturegraph.cpp" line="12"/>
|
||||||
<location filename="../src/temperaturegraph.h" line="15"/>
|
<location filename="../src/temperaturegraph.h" line="15"/>
|
||||||
<source>Temperature</source>
|
<source>Temperature</source>
|
||||||
<translation>Teplota</translation>
|
<translation>Teplota</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="18"/>
|
<location filename="../src/temperaturegraph.cpp" line="20"/>
|
||||||
<source>Average</source>
|
<source>Average</source>
|
||||||
<translation>Průměr</translation>
|
<translation>Průměr</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="20"/>
|
<location filename="../src/temperaturegraph.cpp" line="22"/>
|
||||||
<source>Minimum</source>
|
<source>Minimum</source>
|
||||||
<translation>Minimum</translation>
|
<translation>Minimum</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="22"/>
|
<location filename="../src/temperaturegraph.cpp" line="24"/>
|
||||||
<source>Maximum</source>
|
<source>Maximum</source>
|
||||||
<translation>Maximum</translation>
|
<translation>Maximum</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="79"/>
|
<location filename="../src/temperaturegraph.cpp" line="83"/>
|
||||||
<source>m</source>
|
<source>m</source>
|
||||||
<translation>m</translation>
|
<translation>m</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="82"/>
|
<location filename="../src/temperaturegraph.cpp" line="86"/>
|
||||||
<source>km</source>
|
<source>km</source>
|
||||||
<translation>km</translation>
|
<translation>km</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="87"/>
|
<location filename="../src/temperaturegraph.cpp" line="91"/>
|
||||||
<source>ft</source>
|
<source>ft</source>
|
||||||
<translation>ft</translation>
|
<translation>ft</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="90"/>
|
<location filename="../src/temperaturegraph.cpp" line="94"/>
|
||||||
<source>mi</source>
|
<source>mi</source>
|
||||||
<translation>mi</translation>
|
<translation>mi</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="99"/>
|
<location filename="../src/temperaturegraph.cpp" line="103"/>
|
||||||
<source>C</source>
|
<source>C</source>
|
||||||
<translation>C</translation>
|
<translation>C</translation>
|
||||||
</message>
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<location filename="../src/temperaturegraph.cpp" line="103"/>
|
<location filename="../src/temperaturegraph.cpp" line="107"/>
|
||||||
<source>F</source>
|
<source>F</source>
|
||||||
<translation>F</translation>
|
<translation>F</translation>
|
||||||
</message>
|
</message>
|
||||||
|
@ -184,6 +184,7 @@ void ElevationGraph::showTracks(bool show)
|
|||||||
|
|
||||||
setInfo();
|
setInfo();
|
||||||
showGraph(show, Track);
|
showGraph(show, Track);
|
||||||
|
setXUnits();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
@ -194,6 +195,7 @@ void ElevationGraph::showRoutes(bool show)
|
|||||||
|
|
||||||
setInfo();
|
setInfo();
|
||||||
showGraph(show, Route);
|
showGraph(show, Route);
|
||||||
|
setXUnits();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
10
src/graphitem.cpp
Normal file
10
src/graphitem.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <QBrush>
|
||||||
|
#include <QPen>
|
||||||
|
#include "graphitem.h"
|
||||||
|
|
||||||
|
void GraphItem::setColor(const QColor &color)
|
||||||
|
{
|
||||||
|
QBrush brush(color, Qt::SolidPattern);
|
||||||
|
QPen pen(brush, 0);
|
||||||
|
setPen(pen);
|
||||||
|
}
|
@ -9,8 +9,9 @@ public:
|
|||||||
GraphItem(const QPainterPath &path, QGraphicsItem * parent = 0)
|
GraphItem(const QPainterPath &path, QGraphicsItem * parent = 0)
|
||||||
: QGraphicsPathItem(path, parent) {_id = 0;}
|
: QGraphicsPathItem(path, parent) {_id = 0;}
|
||||||
|
|
||||||
int id() {return _id;}
|
int id() const {return _id;}
|
||||||
void setId(int id) {_id = id;}
|
void setId(int id) {_id = id;}
|
||||||
|
void setColor(const QColor &color);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _id;
|
int _id;
|
||||||
|
@ -39,6 +39,11 @@ GraphView::GraphView(QWidget *parent)
|
|||||||
_sliderInfo->setZValue(2.0);
|
_sliderInfo->setZValue(2.0);
|
||||||
_info = new InfoItem();
|
_info = new InfoItem();
|
||||||
|
|
||||||
|
_scene->addItem(_xAxis);
|
||||||
|
_scene->addItem(_yAxis);
|
||||||
|
_scene->addItem(_slider);
|
||||||
|
_scene->addItem(_info);
|
||||||
|
|
||||||
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
connect(_slider, SIGNAL(positionChanged(const QPointF&)), this,
|
||||||
SLOT(emitSliderPositionChanged(const QPointF&)));
|
SLOT(emitSliderPositionChanged(const QPointF&)));
|
||||||
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
|
connect(_scene, SIGNAL(mouseClicked(const QPointF&)), this,
|
||||||
@ -54,30 +59,6 @@ GraphView::GraphView(QWidget *parent)
|
|||||||
_sliderPos = 0;
|
_sliderPos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphView::~GraphView()
|
|
||||||
{
|
|
||||||
if (_xAxis->scene() != _scene)
|
|
||||||
delete _xAxis;
|
|
||||||
if (_yAxis->scene() != _scene)
|
|
||||||
delete _yAxis;
|
|
||||||
if (_slider->scene() != _scene)
|
|
||||||
delete _slider;
|
|
||||||
if (_info->scene() != _scene)
|
|
||||||
delete _info;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphView::updateBounds(const QPointF &point)
|
|
||||||
{
|
|
||||||
if (point.x() < _bounds.left())
|
|
||||||
_bounds.setLeft(point.x());
|
|
||||||
if (point.x() > _bounds.right())
|
|
||||||
_bounds.setRight(point.x());
|
|
||||||
if (point.y() > _bounds.bottom())
|
|
||||||
_bounds.setBottom(point.y());
|
|
||||||
if (point.y() < _bounds.top())
|
|
||||||
_bounds.setTop(point.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphView::createXLabel()
|
void GraphView::createXLabel()
|
||||||
{
|
{
|
||||||
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel).arg(_xUnits));
|
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel).arg(_xUnits));
|
||||||
@ -121,44 +102,68 @@ void GraphView::loadData(const QVector<QPointF> &data, int id)
|
|||||||
if (data.size() < 2)
|
if (data.size() < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_graphs.size())
|
|
||||||
_bounds.moveTo(data.at(0));
|
|
||||||
|
|
||||||
updateBounds(data.at(0));
|
|
||||||
path.moveTo(data.at(0).x(), -data.at(0).y());
|
path.moveTo(data.at(0).x(), -data.at(0).y());
|
||||||
for (int i = 1; i < data.size(); i++) {
|
for (int i = 1; i < data.size(); i++) {
|
||||||
const QPointF &p = data.at(i);
|
const QPointF &p = data.at(i);
|
||||||
path.lineTo(p.x(), -p.y());
|
path.lineTo(p.x(), -p.y());
|
||||||
updateBounds(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pi = new GraphItem(path);
|
pi = new GraphItem(path);
|
||||||
QBrush brush(_palette.color(), Qt::SolidPattern);
|
|
||||||
QPen pen(brush, 0);
|
|
||||||
pi->setPen(pen);
|
|
||||||
pi->setId(id);
|
pi->setId(id);
|
||||||
if (_hide.contains(id))
|
pi->setColor(_palette.color());
|
||||||
pi->hide();
|
|
||||||
_scene->addItem(pi);
|
|
||||||
_graphs.append(pi);
|
_graphs.append(pi);
|
||||||
|
|
||||||
|
if (!_hide.contains(id)) {
|
||||||
|
_visible.append(pi);
|
||||||
|
_scene->addItem(pi);
|
||||||
|
updateBounds(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::showGraph(bool show, int id)
|
void GraphView::showGraph(bool show, int id)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _graphs.count(); i++)
|
|
||||||
if (_graphs.at(i)->id() == id)
|
|
||||||
_graphs.at(i)->setVisible(show);
|
|
||||||
|
|
||||||
if (show)
|
if (show)
|
||||||
_hide.remove(id);
|
_hide.remove(id);
|
||||||
else
|
else
|
||||||
_hide.insert(id);
|
_hide.insert(id);
|
||||||
|
|
||||||
|
_visible.clear();
|
||||||
|
_bounds = QRectF();
|
||||||
|
for (int i = 0; i < _graphs.count(); i++) {
|
||||||
|
GraphItem* gi = _graphs.at(i);
|
||||||
|
if (_hide.contains(gi->id())) {
|
||||||
|
if (gi->scene() == _scene)
|
||||||
|
_scene->removeItem(gi);
|
||||||
|
} else {
|
||||||
|
if (gi->scene() != _scene)
|
||||||
|
_scene->addItem(gi);
|
||||||
|
_visible.append(gi);
|
||||||
|
updateBounds(gi->path());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::redraw()
|
void GraphView::redraw()
|
||||||
{
|
{
|
||||||
if (!_graphs.isEmpty())
|
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
||||||
redraw(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
}
|
||||||
|
|
||||||
|
void GraphView::updateBounds(const QPainterPath &path)
|
||||||
|
{
|
||||||
|
QRectF br = path.boundingRect();
|
||||||
|
br.moveTopLeft(QPointF(br.left(), -br.top() - br.height()));
|
||||||
|
_bounds |= br;
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF GraphView::graphsBoundingRect() const
|
||||||
|
{
|
||||||
|
QRectF rect;
|
||||||
|
|
||||||
|
for (int i = 0; i < _visible.count(); i++)
|
||||||
|
rect |= _visible.at(i)->boundingRect();
|
||||||
|
|
||||||
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::redraw(const QSizeF &size)
|
void GraphView::redraw(const QSizeF &size)
|
||||||
@ -170,18 +175,6 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
qreal xs, ys;
|
qreal xs, ys;
|
||||||
|
|
||||||
|
|
||||||
if (_xAxis->scene() == _scene)
|
|
||||||
_scene->removeItem(_xAxis);
|
|
||||||
if (_yAxis->scene() == _scene)
|
|
||||||
_scene->removeItem(_yAxis);
|
|
||||||
if (_slider->scene() == _scene)
|
|
||||||
_scene->removeItem(_slider);
|
|
||||||
if (_info->scene() == _scene)
|
|
||||||
_scene->removeItem(_info);
|
|
||||||
|
|
||||||
for (int i = 0; i < _graphs.size(); i++)
|
|
||||||
_graphs.at(i)->resetTransform();
|
|
||||||
|
|
||||||
rx = RangeF(_bounds.left() * _xScale, _bounds.right() * _xScale);
|
rx = RangeF(_bounds.left() * _xScale, _bounds.right() * _xScale);
|
||||||
ry = RangeF(_bounds.top() * _yScale + _yOffset, _bounds.bottom() * _yScale
|
ry = RangeF(_bounds.top() * _yScale + _yOffset, _bounds.bottom() * _yScale
|
||||||
+ _yOffset);
|
+ _yOffset);
|
||||||
@ -193,7 +186,7 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
mx = _xAxis->margin();
|
mx = _xAxis->margin();
|
||||||
my = _yAxis->margin();
|
my = _yAxis->margin();
|
||||||
|
|
||||||
r = _scene->itemsBoundingRect();
|
r = graphsBoundingRect();
|
||||||
if (r.height() < _minYRange)
|
if (r.height() < _minYRange)
|
||||||
r.adjust(0, -(_minYRange/2 - r.height()/2), 0,
|
r.adjust(0, -(_minYRange/2 - r.height()/2), 0,
|
||||||
_minYRange/2 - r.height()/2);
|
_minYRange/2 - r.height()/2);
|
||||||
@ -203,10 +196,12 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
- _info->boundingRect().height()) / r.height();
|
- _info->boundingRect().height()) / r.height();
|
||||||
transform.scale(xs, ys);
|
transform.scale(xs, ys);
|
||||||
|
|
||||||
for (int i = 0; i < _graphs.size(); i++)
|
for (int i = 0; i < _visible.size(); i++)
|
||||||
_graphs.at(i)->setTransform(transform);
|
_visible.at(i)->setTransform(transform);
|
||||||
|
|
||||||
r = _scene->itemsBoundingRect();
|
QPointF p(r.left() * xs, r.top() * ys);
|
||||||
|
QSizeF s(r.width() * xs, r.height() * ys);
|
||||||
|
r = QRectF(p, s);
|
||||||
if (r.height() < _minYRange * ys)
|
if (r.height() < _minYRange * ys)
|
||||||
r.adjust(0, -(_minYRange/2 * ys - r.height()/2), 0,
|
r.adjust(0, -(_minYRange/2 * ys - r.height()/2), 0,
|
||||||
(_minYRange/2) * ys - r.height()/2);
|
(_minYRange/2) * ys - r.height()/2);
|
||||||
@ -215,25 +210,21 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
_yAxis->setSize(r.height());
|
_yAxis->setSize(r.height());
|
||||||
_xAxis->setPos(r.bottomLeft());
|
_xAxis->setPos(r.bottomLeft());
|
||||||
_yAxis->setPos(r.bottomLeft());
|
_yAxis->setPos(r.bottomLeft());
|
||||||
_scene->addItem(_xAxis);
|
|
||||||
_scene->addItem(_yAxis);
|
|
||||||
|
|
||||||
_slider->setArea(r);
|
_slider->setArea(r);
|
||||||
updateSliderPosition();
|
updateSliderPosition();
|
||||||
_scene->addItem(_slider);
|
|
||||||
|
|
||||||
r = _scene->itemsBoundingRect();
|
r |= _xAxis->sceneBoundingRect();
|
||||||
|
r |= _yAxis->sceneBoundingRect();
|
||||||
_info->setPos(r.topLeft() + QPointF(r.width()/2
|
_info->setPos(r.topLeft() + QPointF(r.width()/2
|
||||||
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
|
- _info->boundingRect().width()/2, -_info->boundingRect().height()));
|
||||||
_scene->addItem(_info);
|
|
||||||
|
|
||||||
_scene->setSceneRect(_scene->itemsBoundingRect());
|
_scene->setSceneRect(_scene->itemsBoundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::resizeEvent(QResizeEvent *)
|
void GraphView::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
if (!_graphs.empty())
|
redraw();
|
||||||
redraw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::plot(QPainter *painter, const QRectF &target)
|
void GraphView::plot(QPainter *painter, const QRectF &target)
|
||||||
@ -254,19 +245,14 @@ void GraphView::plot(QPainter *painter, const QRectF &target)
|
|||||||
|
|
||||||
void GraphView::clear()
|
void GraphView::clear()
|
||||||
{
|
{
|
||||||
if (_xAxis->scene() == _scene)
|
|
||||||
_scene->removeItem(_xAxis);
|
|
||||||
if (_yAxis->scene() == _scene)
|
|
||||||
_scene->removeItem(_yAxis);
|
|
||||||
if (_slider->scene() == _scene)
|
|
||||||
_scene->removeItem(_slider);
|
|
||||||
if (_info->scene() == _scene)
|
|
||||||
_scene->removeItem(_info);
|
|
||||||
|
|
||||||
_slider->clear();
|
_slider->clear();
|
||||||
_info->clear();
|
_info->clear();
|
||||||
_scene->clear();
|
|
||||||
|
for (int i = 0; i < _graphs.count(); i++)
|
||||||
|
delete _graphs[i];
|
||||||
|
|
||||||
_graphs.clear();
|
_graphs.clear();
|
||||||
|
_visible.clear();
|
||||||
_palette.reset();
|
_palette.reset();
|
||||||
|
|
||||||
_bounds = QRectF();
|
_bounds = QRectF();
|
||||||
@ -308,26 +294,28 @@ static qreal yAtX(const QPainterPath &path, qreal x)
|
|||||||
|
|
||||||
void GraphView::updateSliderPosition()
|
void GraphView::updateSliderPosition()
|
||||||
{
|
{
|
||||||
Q_ASSERT(_bounds.width() > 0);
|
if (_bounds.width() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (_sliderPos <= _bounds.right() && _sliderPos >= _bounds.left()) {
|
if (_sliderPos <= _bounds.right() && _sliderPos >= _bounds.left()) {
|
||||||
_slider->setPos((_sliderPos / _bounds.width()) * _slider->area().width(),
|
_slider->setPos((_sliderPos / _bounds.width()) * _slider->area().width(),
|
||||||
_slider->area().bottom());
|
_slider->area().bottom());
|
||||||
_slider->setVisible(true);
|
_slider->setVisible(!_visible.isEmpty());
|
||||||
} else
|
} else {
|
||||||
|
_slider->setPos(_slider->area().left(), _slider->area().bottom());
|
||||||
_slider->setVisible(false);
|
_slider->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
updateSliderInfo();
|
updateSliderInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::updateSliderInfo()
|
void GraphView::updateSliderInfo()
|
||||||
{
|
{
|
||||||
_sliderInfo->setVisible(_graphs.size() == 1);
|
_sliderInfo->setVisible(_visible.count() == 1);
|
||||||
|
|
||||||
if (!_sliderInfo->isVisible())
|
if (!_sliderInfo->isVisible())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QPainterPath &path = _graphs.at(0)->path();
|
const QPainterPath &path = _visible.first()->path();
|
||||||
QRectF br = path.boundingRect();
|
QRectF br = path.boundingRect();
|
||||||
if (br.height() < _minYRange)
|
if (br.height() < _minYRange)
|
||||||
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
||||||
@ -348,17 +336,18 @@ void GraphView::updateSliderInfo()
|
|||||||
|
|
||||||
void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
||||||
{
|
{
|
||||||
Q_ASSERT(_slider->area().width() > 0);
|
if (_slider->area().width() <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
_sliderPos = (pos.x() / _slider->area().width()) * _bounds.width();
|
_sliderPos = (pos.x() / _slider->area().width()) * _bounds.width();
|
||||||
|
|
||||||
updateSliderPosition();
|
updateSliderPosition();
|
||||||
|
|
||||||
emit sliderPositionChanged(_sliderPos);
|
emit sliderPositionChanged(_sliderPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::setSliderPosition(qreal pos)
|
void GraphView::setSliderPosition(qreal pos)
|
||||||
{
|
{
|
||||||
if (_graphs.isEmpty())
|
if (_visible.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_sliderPos = pos;
|
_sliderPos = pos;
|
||||||
@ -368,7 +357,7 @@ void GraphView::setSliderPosition(qreal pos)
|
|||||||
void GraphView::newSliderPosition(const QPointF &pos)
|
void GraphView::newSliderPosition(const QPointF &pos)
|
||||||
{
|
{
|
||||||
if (_slider->area().contains(pos))
|
if (_slider->area().contains(pos))
|
||||||
emitSliderPositionChanged(pos);
|
_slider->setPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::addInfo(const QString &key, const QString &value)
|
void GraphView::addInfo(const QString &key, const QString &value)
|
||||||
|
@ -33,7 +33,6 @@ class GraphView : public QGraphicsView
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
GraphView(QWidget *parent = 0);
|
GraphView(QWidget *parent = 0);
|
||||||
~GraphView();
|
|
||||||
|
|
||||||
void loadData(const QVector<QPointF> &data, int id = 0);
|
void loadData(const QVector<QPointF> &data, int id = 0);
|
||||||
int count() const {return _graphs.count();}
|
int count() const {return _graphs.count();}
|
||||||
@ -84,9 +83,10 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void createXLabel();
|
void createXLabel();
|
||||||
void createYLabel();
|
void createYLabel();
|
||||||
void updateBounds(const QPointF &point);
|
|
||||||
void updateSliderPosition();
|
void updateSliderPosition();
|
||||||
void updateSliderInfo();
|
void updateSliderInfo();
|
||||||
|
void updateBounds(const QPainterPath &path);
|
||||||
|
QRectF graphsBoundingRect() const;
|
||||||
|
|
||||||
qreal _xScale, _yScale;
|
qreal _xScale, _yScale;
|
||||||
qreal _yOffset;
|
qreal _yOffset;
|
||||||
@ -104,8 +104,8 @@ private:
|
|||||||
InfoItem *_info;
|
InfoItem *_info;
|
||||||
|
|
||||||
QList<GraphItem*> _graphs;
|
QList<GraphItem*> _graphs;
|
||||||
|
QList<GraphItem*> _visible;
|
||||||
QSet<int> _hide;
|
QSet<int> _hide;
|
||||||
bool _hideAll;
|
|
||||||
QRectF _bounds;
|
QRectF _bounds;
|
||||||
Palette _palette;
|
Palette _palette;
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
||||||
{
|
{
|
||||||
_units = Metric;
|
_units = Metric;
|
||||||
|
_showTracks = true;
|
||||||
|
|
||||||
GraphView::setYUnits(tr("1/min"));
|
GraphView::setYUnits(tr("1/min"));
|
||||||
setXLabel(tr("Distance"));
|
setXLabel(tr("Distance"));
|
||||||
@ -15,10 +16,13 @@ HeartRateGraph::HeartRateGraph(QWidget *parent) : GraphTab(parent)
|
|||||||
|
|
||||||
void HeartRateGraph::setInfo()
|
void HeartRateGraph::setInfo()
|
||||||
{
|
{
|
||||||
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 0)
|
if (_showTracks) {
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f',
|
||||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 0)
|
0) + UNIT_SPACE + yUnits());
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
|
||||||
|
0) + UNIT_SPACE + yUnits());
|
||||||
|
} else
|
||||||
|
clearInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeartRateGraph::loadGPX(const GPX &gpx)
|
void HeartRateGraph::loadGPX(const GPX &gpx)
|
||||||
@ -103,12 +107,11 @@ void HeartRateGraph::setUnits(enum Units units)
|
|||||||
|
|
||||||
void HeartRateGraph::showTracks(bool show)
|
void HeartRateGraph::showTracks(bool show)
|
||||||
{
|
{
|
||||||
if (show)
|
_showTracks = show;
|
||||||
setInfo();
|
|
||||||
else
|
|
||||||
clearInfo();
|
|
||||||
|
|
||||||
|
setInfo();
|
||||||
showGraph(show);
|
showGraph(show);
|
||||||
|
setXUnits();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,9 @@ private:
|
|||||||
void setInfo();
|
void setInfo();
|
||||||
|
|
||||||
QList<QPointF> _avg;
|
QList<QPointF> _avg;
|
||||||
|
|
||||||
enum Units _units;
|
enum Units _units;
|
||||||
|
bool _showTracks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HEARTRATEGRAPH_H
|
#endif // HEARTRATEGRAPH_H
|
||||||
|
@ -24,7 +24,7 @@ void SliderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
|||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
painter->drawLine(0, 0, 0, -_area.height());
|
painter->drawLine(0, 0, 0, -_area.height());
|
||||||
|
|
||||||
//painter->drawRect(boundingRect());
|
// painter->drawRect(boundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
QVariant SliderItem::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
||||||
{
|
{
|
||||||
_units = Metric;
|
_units = Metric;
|
||||||
|
_showTracks = true;
|
||||||
|
|
||||||
setYUnits();
|
setYUnits();
|
||||||
setXLabel(tr("Distance"));
|
setXLabel(tr("Distance"));
|
||||||
@ -16,10 +17,13 @@ SpeedGraph::SpeedGraph(QWidget *parent) : GraphTab(parent)
|
|||||||
|
|
||||||
void SpeedGraph::setInfo()
|
void SpeedGraph::setInfo()
|
||||||
{
|
{
|
||||||
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f', 1)
|
if (_showTracks) {
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale(), 'f',
|
||||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f', 1)
|
1) + UNIT_SPACE + yUnits());
|
||||||
+ UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
|
||||||
|
1) + UNIT_SPACE + yUnits());
|
||||||
|
} else
|
||||||
|
clearInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedGraph::loadGPX(const GPX &gpx)
|
void SpeedGraph::loadGPX(const GPX &gpx)
|
||||||
@ -111,12 +115,11 @@ void SpeedGraph::setUnits(enum Units units)
|
|||||||
|
|
||||||
void SpeedGraph::showTracks(bool show)
|
void SpeedGraph::showTracks(bool show)
|
||||||
{
|
{
|
||||||
if (show)
|
_showTracks = show;
|
||||||
setInfo();
|
|
||||||
else
|
|
||||||
clearInfo();
|
|
||||||
|
|
||||||
|
setInfo();
|
||||||
showGraph(show);
|
showGraph(show);
|
||||||
|
setXUnits();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ private:
|
|||||||
void setInfo();
|
void setInfo();
|
||||||
|
|
||||||
QList<QPointF> _avg;
|
QList<QPointF> _avg;
|
||||||
|
|
||||||
enum Units _units;
|
enum Units _units;
|
||||||
|
bool _showTracks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPEEDGRAPH_H
|
#endif // SPEEDGRAPH_H
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
|
TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
|
||||||
{
|
{
|
||||||
_units = Metric;
|
_units = Metric;
|
||||||
|
_showTracks = true;
|
||||||
|
|
||||||
setYUnits();
|
setYUnits();
|
||||||
setXLabel(tr("Distance"));
|
setXLabel(tr("Distance"));
|
||||||
@ -15,12 +16,15 @@ TemperatureGraph::TemperatureGraph(QWidget *parent) : GraphTab(parent)
|
|||||||
|
|
||||||
void TemperatureGraph::setInfo()
|
void TemperatureGraph::setInfo()
|
||||||
{
|
{
|
||||||
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
|
if (_showTracks) {
|
||||||
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Average"), QString::number(avg() * yScale()
|
||||||
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale()
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
||||||
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale()
|
||||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
||||||
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale()
|
||||||
|
+ yOffset(), 'f', 1) + UNIT_SPACE + yUnits());
|
||||||
|
} else
|
||||||
|
clearInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TemperatureGraph::loadGPX(const GPX &gpx)
|
void TemperatureGraph::loadGPX(const GPX &gpx)
|
||||||
@ -119,12 +123,11 @@ void TemperatureGraph::setUnits(enum Units units)
|
|||||||
|
|
||||||
void TemperatureGraph::showTracks(bool show)
|
void TemperatureGraph::showTracks(bool show)
|
||||||
{
|
{
|
||||||
if (show)
|
_showTracks = show;
|
||||||
setInfo();
|
|
||||||
else
|
|
||||||
clearInfo();
|
|
||||||
|
|
||||||
|
setInfo();
|
||||||
showGraph(show);
|
showGraph(show);
|
||||||
|
setXUnits();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,9 @@ private:
|
|||||||
void setInfo();
|
void setInfo();
|
||||||
|
|
||||||
QList<QPointF> _avg;
|
QList<QPointF> _avg;
|
||||||
|
|
||||||
enum Units _units;
|
enum Units _units;
|
||||||
|
bool _showTracks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TEMPERATUREGRAPH_H
|
#endif // TEMPERATUREGRAPH_H
|
||||||
|
Loading…
Reference in New Issue
Block a user