]> sigrok.org Git - pulseview.git/commitdiff
Fix #1338 ("show time zero at the trigger" option)
authorSoeren Apel <redacted>
Wed, 20 Feb 2019 08:40:42 +0000 (09:40 +0100)
committerSoeren Apel <redacted>
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 acea8a368b457469e44c11e758f95f935a56e68e..8e7e0b676d435c26d05e6dca9f1cfea142a6c469 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 b14148728c579b8c8f2885c8a76859fae976a3ca..5035bfc83bffc9962f8a7d06d782c1fae5dcd232 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 5c854aed17e2aa3db35f4b668ec6d5ad4b09662d..d7e02bcaae5603e9a55d27ff791d1ceb3ef00906 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 79277b4e17074708b0f1e3718ef6eeb4996d2c93..05e6da3e67000a75720595aba455697ac7d265d7 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 a6655d2f492ab941617fc95f7c694463b1aa6645..e66f7d0e8bd8a35f6d6bcb5aa4b0a830d83ea9ee 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 3c9bc8c0eebc045b034eb8088464f5a4e98d5547..5e743bb7ece0f55857dcbacff591b623e931fd7f 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 b524c1797d0d1478ba4bd1eac36ee538a400d69a..f44dbf98edb1c3b5a3a0023dd58f67740b911d46 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_;