From: Soeren Apel Date: Wed, 26 Jun 2019 20:20:25 +0000 (+0200) Subject: Trace View: Move ruler time conversion from View to Ruler X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4468ee4246cd5e47845494e8b3b22a17d434ed5b;p=pulseview.git Trace View: Move ruler time conversion from View to Ruler --- diff --git a/pv/views/trace/cursor.cpp b/pv/views/trace/cursor.cpp index c218440e..0fcb6faf 100644 --- a/pv/views/trace/cursor.cpp +++ b/pv/views/trace/cursor.cpp @@ -59,7 +59,7 @@ QString Cursor::get_text() const const pv::util::Timestamp& diff = abs(time_ - other->time_); return Ruler::format_time_with_distance( - diff, view_.absolute_to_ruler_time(time_), + diff, view_.ruler()->get_ruler_time_from_absolute_time(time_), view_.tick_prefix(), view_.time_unit(), view_.tick_precision()); } diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index 401fc3da..5fa1be2f 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -129,6 +129,16 @@ pv::util::Timestamp Ruler::get_ruler_time_from_x_pos(uint32_t x) const return view_.ruler_offset() + ((double)x + 0.5) * view_.scale(); } +pv::util::Timestamp Ruler::get_ruler_time_from_absolute_time(const pv::util::Timestamp& abs_time) const +{ + return abs_time + view_.zero_offset(); +} + +pv::util::Timestamp Ruler::get_absolute_time_from_ruler_time(const pv::util::Timestamp& ruler_time) const +{ + return ruler_time - view_.zero_offset(); +} + void Ruler::contextMenuEvent(QContextMenuEvent *event) { MarginWidget::contextMenuEvent(event); diff --git a/pv/views/trace/ruler.hpp b/pv/views/trace/ruler.hpp index 5035bfc8..bfab7666 100644 --- a/pv/views/trace/ruler.hpp +++ b/pv/views/trace/ruler.hpp @@ -120,6 +120,9 @@ public: pv::util::Timestamp get_absolute_time_from_x_pos(uint32_t x) const; pv::util::Timestamp get_ruler_time_from_x_pos(uint32_t x) const; + pv::util::Timestamp get_ruler_time_from_absolute_time(const pv::util::Timestamp& abs_time) const; + pv::util::Timestamp get_absolute_time_from_ruler_time(const pv::util::Timestamp& ruler_time) const; + protected: virtual void contextMenuEvent(QContextMenuEvent *event) override; void resizeEvent(QResizeEvent*) override; diff --git a/pv/views/trace/timemarker.cpp b/pv/views/trace/timemarker.cpp index c58aa08d..ec4c97d7 100644 --- a/pv/views/trace/timemarker.cpp +++ b/pv/views/trace/timemarker.cpp @@ -25,6 +25,7 @@ #include "timemarker.hpp" #include "pv/widgets/timestampspinbox.hpp" +#include "ruler.hpp" #include "view.hpp" #include @@ -65,7 +66,7 @@ void TimeMarker::set_time(const pv::util::Timestamp& time) if (value_widget_) { updating_value_widget_ = true; - value_widget_->setValue(view_.absolute_to_ruler_time(time)); + value_widget_->setValue(view_.ruler()->get_ruler_time_from_absolute_time(time)); updating_value_widget_ = false; } @@ -179,7 +180,7 @@ pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent) popup->setLayout(form); value_widget_ = new pv::widgets::TimestampSpinBox(parent); - value_widget_->setValue(view_.absolute_to_ruler_time(time_)); + value_widget_->setValue(view_.ruler()->get_ruler_time_from_absolute_time(time_)); connect(value_widget_, SIGNAL(valueChanged(const pv::util::Timestamp&)), this, SLOT(on_value_changed(const pv::util::Timestamp&))); @@ -192,7 +193,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(view_.ruler_to_absolute_time(value)); + set_time(view_.ruler()->get_absolute_time_from_ruler_time(value)); } } // namespace trace diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 8e2a2b32..4b95a806 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -456,16 +456,6 @@ 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) { @@ -503,6 +493,11 @@ void View::reset_zero_position() ruler_->update(); } +pv::util::Timestamp View::zero_offset() const +{ + return zero_offset_; +} + int View::owner_visual_v_offset() const { return -scrollarea_->verticalScrollBar()->sliderPosition(); diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 06b2cf2f..8f59b029 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -177,8 +177,7 @@ 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; + pv::util::Timestamp zero_offset() const; /** * Returns the vertical scroll offset.