1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-30 22:51:16 +01:00

Better (consistent) graph definition

This commit is contained in:
Martin Tůma 2017-05-22 18:42:23 +02:00
parent e96cee2ea8
commit dba6291f3e
3 changed files with 14 additions and 20 deletions

View File

@ -31,22 +31,6 @@ private:
Q_DECLARE_TYPEINFO(GraphPoint, Q_PRIMITIVE_TYPE);
QDebug operator<<(QDebug dbg, const GraphPoint &point);
class Graph : public QVector<GraphPoint>
{
public:
Graph() : QVector<GraphPoint>() {_time = true;}
void append(const GraphPoint &p)
{
if (std::isnan(p.t()))
_time = false;
QVector<GraphPoint>::append(p);
}
bool hasTime() const {return _time;}
private:
bool _time;
};
typedef QVector<GraphPoint> Graph;
#endif // GRAPH_H

View File

@ -14,6 +14,14 @@ GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
_graph = graph;
_sx = 1.0; _sy = 1.0;
_time = true;
for (int i = 0; i < _graph.size(); i++) {
if (std::isnan(_graph.at(i).t())) {
_time = false;
break;
}
}
setZValue(1.0);
updatePath();
@ -124,7 +132,7 @@ qreal GraphItem::distanceAtTime(qreal time)
void GraphItem::emitSliderPositionChanged(qreal pos)
{
if (_type == Time) {
if (_graph.hasTime()) {
if (_time) {
if (pos >= _graph.first().t() && pos <= _graph.last().t())
emit sliderPositionChanged(distanceAtTime(pos));
else
@ -163,7 +171,7 @@ void GraphItem::updatePath()
{
_path = QPainterPath();
if (_type == Time && !_graph.hasTime())
if (_type == Time && !_time)
return;
_path.moveTo(_graph.first().x(_type) * _sx, -_graph.first().y() * _sy);
@ -173,7 +181,7 @@ void GraphItem::updatePath()
void GraphItem::updateBounds()
{
if (_type == Time && !_graph.hasTime()) {
if (_type == Time && !_time) {
_bounds = QRectF();
return;
}

View File

@ -50,6 +50,8 @@ private:
QPainterPath _path;
QRectF _bounds;
qreal _sx, _sy;
bool _time;
};
#endif // GRAPHITEM_H