From dba6291f3e6c7521c4c12c09dea142786f4f8e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 22 May 2017 18:42:23 +0200 Subject: [PATCH] Better (consistent) graph definition --- src/graph.h | 18 +----------------- src/graphitem.cpp | 14 +++++++++++--- src/graphitem.h | 2 ++ 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/graph.h b/src/graph.h index 31a9d033..61cb4db1 100644 --- a/src/graph.h +++ b/src/graph.h @@ -31,22 +31,6 @@ private: Q_DECLARE_TYPEINFO(GraphPoint, Q_PRIMITIVE_TYPE); QDebug operator<<(QDebug dbg, const GraphPoint &point); - -class Graph : public QVector -{ -public: - Graph() : QVector() {_time = true;} - void append(const GraphPoint &p) - { - if (std::isnan(p.t())) - _time = false; - QVector::append(p); - } - - bool hasTime() const {return _time;} - -private: - bool _time; -}; +typedef QVector Graph; #endif // GRAPH_H diff --git a/src/graphitem.cpp b/src/graphitem.cpp index 08c9ca3e..a316d45b 100644 --- a/src/graphitem.cpp +++ b/src/graphitem.cpp @@ -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; } diff --git a/src/graphitem.h b/src/graphitem.h index 967b1db2..f4443bbd 100644 --- a/src/graphitem.h +++ b/src/graphitem.h @@ -50,6 +50,8 @@ private: QPainterPath _path; QRectF _bounds; qreal _sx, _sy; + + bool _time; }; #endif // GRAPHITEM_H