From: jaseg Date: Sun, 9 Jun 2019 11:07:55 +0000 (+0900) Subject: Show ruler timestamps in cursors and popups X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=39173000c5d0d164c52443d16a1dc434d538b198;ds=sidebyside Show ruler timestamps in cursors and popups Prior to this absolute timestamps would be shown, even with the zero point set somewhere else. --- diff --git a/pv/views/trace/cursor.cpp b/pv/views/trace/cursor.cpp index 7a375c7a..c218440e 100644 --- a/pv/views/trace/cursor.cpp +++ b/pv/views/trace/cursor.cpp @@ -59,7 +59,8 @@ QString Cursor::get_text() const const pv::util::Timestamp& diff = abs(time_ - other->time_); return Ruler::format_time_with_distance( - diff, time_, view_.tick_prefix(), view_.time_unit(), view_.tick_precision()); + diff, view_.absolute_to_ruler_time(time_), + view_.tick_prefix(), view_.time_unit(), view_.tick_precision()); } QRectF Cursor::label_rect(const QRectF &rect) const diff --git a/pv/views/trace/timemarker.cpp b/pv/views/trace/timemarker.cpp index 266007a5..c58aa08d 100644 --- a/pv/views/trace/timemarker.cpp +++ b/pv/views/trace/timemarker.cpp @@ -65,7 +65,7 @@ void TimeMarker::set_time(const pv::util::Timestamp& time) if (value_widget_) { updating_value_widget_ = true; - value_widget_->setValue(time); + value_widget_->setValue(view_.absolute_to_ruler_time(time)); updating_value_widget_ = false; } @@ -179,7 +179,7 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent) popup->setLayout(form); value_widget_ = new pv::widgets::TimestampSpinBox(parent); - value_widget_->setValue(time_); + value_widget_->setValue(view_.absolute_to_ruler_time(time_)); connect(value_widget_, SIGNAL(valueChanged(const pv::util::Timestamp&)), this, SLOT(on_value_changed(const pv::util::Timestamp&))); @@ -192,7 +192,7 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent) void TimeMarker::on_value_changed(const pv::util::Timestamp& value) { if (!updating_value_widget_) - set_time(value); + set_time(view_.ruler_to_absolute_time(value)); } } // namespace trace diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 7f77635d..8e2a2b32 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -456,6 +456,16 @@ void View::set_scale(double scale) } } +pv::util::Timestamp View::absolute_to_ruler_time(const pv::util::Timestamp& abs_time) const +{ + return abs_time + zero_offset_; +} + +pv::util::Timestamp View::ruler_to_absolute_time(const pv::util::Timestamp& ruler_time) const +{ + return ruler_time - zero_offset_; +} + void View::set_offset(const pv::util::Timestamp& offset, bool force_update) { if ((offset_ != offset) || force_update) { diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index c6a7c557..06b2cf2f 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -177,6 +177,9 @@ public: void reset_zero_position(); + pv::util::Timestamp absolute_to_ruler_time(const pv::util::Timestamp& abs_time) const; + pv::util::Timestamp ruler_to_absolute_time(const pv::util::Timestamp& ruler_time) const; + /** * Returns the vertical scroll offset. */