Fix #1338 ("show time zero at the trigger" option)
authorSoeren Apel <soeren@apelpie.net>
Wed, 20 Feb 2019 08:40:42 +0000 (09:40 +0100)
committerSoeren Apel <soeren@apelpie.net>
Tue, 26 Feb 2019 21:08:08 +0000 (22:08 +0100)
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.

pv/views/trace/ruler.cpp
pv/views/trace/ruler.hpp
pv/views/trace/trace.cpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp
pv/views/viewbase.cpp
pv/views/viewbase.hpp

index acea8a3..8e7e0b6 100644 (file)
@@ -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<ViewItem> 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()
index b141487..5035bfc 100644 (file)
@@ -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;
index 5c854ae..d7e02bc 100644 (file)
@@ -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
index 79277b4..05e6da3 100644 (file)
@@ -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_;
index a6655d2..e66f7d0 100644 (file)
@@ -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_;
index 3c9bc8c..5e743bb 100644 (file)
@@ -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;
 }
 
index b524c17..f44dbf9 100644 (file)
@@ -116,7 +116,6 @@ protected:
 
        const bool is_main_view_;
 
-       util::Timestamp ruler_shift_;
        util::TimeUnit time_unit_;
 
        unordered_set< shared_ptr<data::SignalBase> > signalbases_;