diff --git a/src/GUI/graphitem.cpp b/src/GUI/graphitem.cpp index dd820713..2c076b79 100644 --- a/src/GUI/graphitem.cpp +++ b/src/GUI/graphitem.cpp @@ -224,6 +224,12 @@ qreal GraphItem::timeAtDistance(qreal distance) const return l.pointAt((distance - l.p1().x()) / (l.p2().x() - l.p1().x())).y(); } +GraphItem::SegmentTime GraphItem::date(qreal x) +{ + const GraphSegment *seg = segment(x, _type); + return seg ? SegmentTime(seg->start(), seg->first().t()) : SegmentTime(); +} + void GraphItem::hover(bool hover) { if (hover) { diff --git a/src/GUI/graphitem.h b/src/GUI/graphitem.h index cfa6bdd9..79d5b82c 100644 --- a/src/GUI/graphitem.h +++ b/src/GUI/graphitem.h @@ -12,6 +12,16 @@ class GraphItem : public QObject, public GraphicsItem Q_OBJECT public: + struct SegmentTime + { + SegmentTime() : time(NAN) {} + SegmentTime(const QDateTime &date, qreal time) + : date(date), time(time) {} + + QDateTime date; + qreal time; + }; + GraphItem(const Graph &graph, GraphType type, int width, const QColor &color, Qt::PenStyle style, QGraphicsItem *parent = 0); virtual ~GraphItem() {} @@ -43,6 +53,7 @@ public: qreal yAtX(qreal x) const; qreal distanceAtTime(qreal time) const; qreal timeAtDistance(qreal distance) const; + SegmentTime date(qreal x); void redraw(); diff --git a/src/GUI/pathitem.cpp b/src/GUI/pathitem.cpp index c8e1da36..6d00e50e 100644 --- a/src/GUI/pathitem.cpp +++ b/src/GUI/pathitem.cpp @@ -334,12 +334,18 @@ void PathItem::setMarkerPosition(qreal pos) void PathItem::setMarkerInfo(qreal pos) { if (_markerInfoType == MarkerInfoItem::Date) { - qreal time = _graph - ? (_graph->graphType() == Time) ? pos : _graph->timeAtDistance(pos) - : NAN; - QDateTime d(date()); - if (!std::isnan(time) && d.isValid()) - _markerInfo->setDate(d.addSecs(time).toTimeZone(_timeZone)); + QDateTime date; + + if (_graph) { + qreal time = (_graph->graphType() == Time) + ? pos : _graph->timeAtDistance(pos); + GraphItem::SegmentTime st(_graph->date(pos)); + if (st.date.isValid() && !std::isnan(time)) + date = st.date.addSecs(time - st.time); + } + + if (date.isValid()) + _markerInfo->setDate(date.toTimeZone(_timeZone)); else _markerInfo->setDate(QDateTime()); } else if (_markerInfoType == MarkerInfoItem::Position) diff --git a/src/data/graph.h b/src/data/graph.h index f5177596..52b0fe65 100644 --- a/src/data/graph.h +++ b/src/data/graph.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -41,7 +42,19 @@ inline QDebug operator<<(QDebug dbg, const GraphPoint &point) } #endif // QT_NO_DEBUG -typedef QVector GraphSegment; +class GraphSegment : public QVector +{ +public: + GraphSegment(const QDateTime &start) + : _start(start) {} + GraphSegment(int size, const QDateTime &start) + : QVector(size), _start(start) {} + + const QDateTime &start() const {return _start;} + +private: + QDateTime _start; +}; class Graph : public QList { diff --git a/src/data/route.cpp b/src/data/route.cpp index 7fb85619..9d83cc8c 100644 --- a/src/data/route.cpp +++ b/src/data/route.cpp @@ -33,7 +33,7 @@ Path Route::path() const Graph Route::gpsElevation() const { Graph graph; - graph.append(GraphSegment()); + graph.append(GraphSegment(QDateTime())); GraphSegment &gs = graph.last(); for (int i = 0; i < _data.size(); i++) @@ -49,7 +49,7 @@ Graph Route::gpsElevation() const Graph Route::demElevation() const { Graph graph; - graph.append(GraphSegment()); + graph.append(GraphSegment(QDateTime())); GraphSegment &gs = graph.last(); for (int i = 0; i < _data.size(); i++) { diff --git a/src/data/track.cpp b/src/data/track.cpp index 331584af..63a53c66 100644 --- a/src/data/track.cpp +++ b/src/data/track.cpp @@ -66,10 +66,10 @@ static QSet eliminate(const QVector &v) static GraphSegment filter(const GraphSegment &g, int window) { if (g.size() < window || window < 2) - return GraphSegment(g); + return g; qreal acc = 0; - GraphSegment ret(g.size()); + GraphSegment ret(g.size(), g.start()); for (int i = 0; i < window; i++) acc += g.at(i).y(); @@ -131,6 +131,7 @@ Track::Track(const TrackData &data) : _pause(0) Segment &seg = _segments.last(); + seg.start = sd.first().timestamp(); seg.distance.append(lastDistance(i)); seg.time.append(sd.first().hasTimestamp() ? lastTime(i) : NAN); seg.speed.append(sd.first().hasTimestamp() ? 0 : NAN); @@ -257,7 +258,7 @@ Graph Track::gpsElevation() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); for (int j = 0; j < sd.size(); j++) { if (!sd.at(j).hasElevation() || seg.outliers.contains(j)) @@ -285,7 +286,7 @@ Graph Track::demElevation() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); for (int j = 0; j < sd.size(); j++) { qreal dem = DEM::elevation(sd.at(j).coordinates()); @@ -328,7 +329,7 @@ Graph Track::computedSpeed() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); QList stop; qreal v; @@ -368,7 +369,7 @@ Graph Track::reportedSpeed() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); QList stop; qreal v; @@ -423,7 +424,7 @@ Graph Track::heartRate() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); for (int j = 0; j < sd.size(); j++) if (sd.at(j).hasHeartRate() && !seg.outliers.contains(j)) @@ -449,7 +450,7 @@ Graph Track::temperature() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); for (int j = 0; j < sd.count(); j++) { if (sd.at(j).hasTemperature() && !seg.outliers.contains(j)) @@ -476,7 +477,7 @@ Graph Track::ratio() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); for (int j = 0; j < sd.size(); j++) if (sd.at(j).hasRatio() && !seg.outliers.contains(j)) @@ -502,7 +503,7 @@ Graph Track::cadence() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); QList stop; qreal c; @@ -545,7 +546,7 @@ Graph Track::power() const if (sd.size() < 2) continue; const Segment &seg = _segments.at(i); - GraphSegment gs; + GraphSegment gs(seg.start); for (int j = 0; j < sd.size(); j++) { if (sd.at(j).hasPower() && seg.stop.contains(j)) { diff --git a/src/data/track.h b/src/data/track.h index ab16b37d..f54991b9 100644 --- a/src/data/track.h +++ b/src/data/track.h @@ -56,6 +56,7 @@ public: private: struct Segment { + QDateTime start; QVector distance; QVector time; QVector speed;