From: Soeren Apel Date: Wed, 20 Feb 2019 08:40:42 +0000 (+0100) Subject: Fix #1338 ("show time zero at the trigger" option) X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=fe68068b2f8f3ae69b762636e91de91e8996aa11;p=pulseview.git Fix #1338 ("show time zero at the trigger" option) Before, successive runs were shifting the zero point for no valid reason and markers created on the ruler/trace used the wrong time and thus showed up at the wrong location. --- diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index acea8a36..8e7e0b67 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -114,7 +114,12 @@ QString Ruler::format_time_with_distance( return pv::util::format_time_minutes(t, precision, sign); } -pv::util::Timestamp Ruler::get_time_from_x_pos(uint32_t x) const +pv::util::Timestamp Ruler::get_absolute_time_from_x_pos(uint32_t x) const +{ + return view_.offset() + ((double)x + 0.5) * view_.scale(); +} + +pv::util::Timestamp Ruler::get_ruler_time_from_x_pos(uint32_t x) const { return view_.ruler_offset() + ((double)x + 0.5) * view_.scale(); } @@ -177,7 +182,7 @@ shared_ptr Ruler::get_mouse_over_item(const QPoint &pt) void Ruler::mouseDoubleClickEvent(QMouseEvent *event) { - view_.add_flag(get_time_from_x_pos(event->x())); + view_.add_flag(get_ruler_time_from_x_pos(event->x())); } void Ruler::paintEvent(QPaintEvent*) @@ -330,12 +335,12 @@ void Ruler::invalidate_tick_position_cache() void Ruler::on_createMarker() { - view_.add_flag(get_time_from_x_pos(mouse_down_point_.x())); + view_.add_flag(get_absolute_time_from_x_pos(mouse_down_point_.x())); } void Ruler::on_setZeroPosition() { - view_.set_zero_position(get_time_from_x_pos(mouse_down_point_.x())); + view_.set_zero_position(get_absolute_time_from_x_pos(mouse_down_point_.x())); } void Ruler::on_toggleHoverMarker() diff --git a/pv/views/trace/ruler.hpp b/pv/views/trace/ruler.hpp index b1414872..5035bfc8 100644 --- a/pv/views/trace/ruler.hpp +++ b/pv/views/trace/ruler.hpp @@ -117,7 +117,8 @@ public: unsigned precision = 0, bool sign = true); - pv::util::Timestamp get_time_from_x_pos(uint32_t x) const; + 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; protected: virtual void contextMenuEvent(QContextMenuEvent *event) override; diff --git a/pv/views/trace/trace.cpp b/pv/views/trace/trace.cpp index 5c854aed..d7e02bca 100644 --- a/pv/views/trace/trace.cpp +++ b/pv/views/trace/trace.cpp @@ -411,7 +411,7 @@ void Trace::on_create_marker_here() const const Ruler *ruler = view->ruler(); QPoint p = ruler->mapFrom(view, QPoint(context_menu_x_pos_, 0)); - view->add_flag(ruler->get_time_from_x_pos(p.x())); + view->add_flag(ruler->get_absolute_time_from_x_pos(p.x())); } } // namespace trace diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 79277b4e..05e6da3e 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -362,12 +362,6 @@ void View::save_settings(QSettings &settings) const settings.setValue("splitter_state", splitter_->saveState()); settings.setValue("segment_display_mode", segment_display_mode_); - { - stringstream ss; - boost::archive::text_oarchive oa(ss); - oa << boost::serialization::make_nvp("ruler_shift", ruler_shift_); - settings.setValue("ruler_shift", QString::fromStdString(ss.str())); - } { stringstream ss; boost::archive::text_oarchive oa(ss); @@ -390,20 +384,6 @@ void View::restore_settings(QSettings &settings) if (settings.contains("scale")) set_scale(settings.value("scale").toDouble()); - if (settings.contains("ruler_shift")) { - util::Timestamp shift; - stringstream ss; - ss << settings.value("ruler_shift").toString().toStdString(); - - try { - boost::archive::text_iarchive ia(ss); - ia >> boost::serialization::make_nvp("ruler_shift", shift); - ruler_shift_ = shift; - } catch (boost::archive::archive_exception&) { - qDebug() << "Could not restore the view ruler shift"; - } - } - if (settings.contains("offset")) { util::Timestamp offset; stringstream ss; @@ -480,7 +460,7 @@ void View::set_offset(const pv::util::Timestamp& offset, bool force_update) { if ((offset_ != offset) || force_update) { offset_ = offset; - ruler_offset_ = offset_ + ruler_shift_; + ruler_offset_ = offset_ + zero_offset_; offset_changed(); } } @@ -497,10 +477,7 @@ const Timestamp& View::ruler_offset() const void View::set_zero_position(const pv::util::Timestamp& position) { - // ruler shift is a negative offset and the new zero position is relative - // to the current offset. Hence, we adjust the ruler shift only by the - // difference. - ruler_shift_ = -(position + (-ruler_shift_)); + zero_offset_ = -position; // Force an immediate update of the offsets set_offset(offset_, true); @@ -509,7 +486,7 @@ void View::set_zero_position(const pv::util::Timestamp& position) void View::reset_zero_position() { - ruler_shift_ = 0; + zero_offset_ = 0; // Force an immediate update of the offsets set_offset(offset_, true); @@ -1699,6 +1676,7 @@ void View::capture_state_updated(int state) set_time_unit(util::TimeUnit::Samples); trigger_markers_.clear(); + set_zero_position(0); scale_at_acq_start_ = scale_; offset_at_acq_start_ = offset_; diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index a6655d2f..e66f7d0e 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -507,6 +507,8 @@ private: pv::util::Timestamp offset_; /// The ruler version of the time offset in seconds. pv::util::Timestamp ruler_offset_; + /// The offset of the zero point in seconds. + pv::util::Timestamp zero_offset_; bool updating_scroll_; bool settings_restored_; diff --git a/pv/views/viewbase.cpp b/pv/views/viewbase.cpp index 3c9bc8c0..5e743bb7 100644 --- a/pv/views/viewbase.cpp +++ b/pv/views/viewbase.cpp @@ -57,7 +57,6 @@ ViewBase::ViewBase(Session &session, bool is_main_view, QWidget *parent) : void ViewBase::reset_view_state() { - ruler_shift_ = 0; current_segment_ = 0; } diff --git a/pv/views/viewbase.hpp b/pv/views/viewbase.hpp index b524c179..f44dbf98 100644 --- a/pv/views/viewbase.hpp +++ b/pv/views/viewbase.hpp @@ -116,7 +116,6 @@ protected: const bool is_main_view_; - util::Timestamp ruler_shift_; util::TimeUnit time_unit_; unordered_set< shared_ptr > signalbases_;