Ruler: Add "Set as zero point" context menu entry
authorSoeren Apel <soeren@apelpie.net>
Mon, 22 Oct 2018 20:01:22 +0000 (22:01 +0200)
committerSoeren Apel <soeren@apelpie.net>
Mon, 22 Oct 2018 20:01:22 +0000 (22:01 +0200)
pv/views/trace/ruler.cpp
pv/views/trace/ruler.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index 1204559..6e74ddd 100644 (file)
@@ -129,6 +129,10 @@ void Ruler::contextMenuEvent(QContextMenuEvent *event)
        connect(create_marker, SIGNAL(triggered()), this, SLOT(on_createMarker()));
        menu->addAction(create_marker);
 
+       QAction *const set_zero_position = new QAction(tr("Set as zero point"), this);
+       connect(set_zero_position, SIGNAL(triggered()), this, SLOT(on_setZeroPosition()));
+       menu->addAction(set_zero_position);
+
        QAction *const toggle_hover_marker = new QAction(this);
        connect(toggle_hover_marker, SIGNAL(triggered()), this, SLOT(on_toggleHoverMarker()));
        menu->addAction(toggle_hover_marker);
@@ -322,6 +326,11 @@ void Ruler::on_createMarker()
        view_.add_flag(get_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()));
+}
+
 void Ruler::on_toggleHoverMarker()
 {
        GlobalSettings settings;
index d7cab4d..b141487 100644 (file)
@@ -176,6 +176,7 @@ private Q_SLOTS:
        void invalidate_tick_position_cache();
 
        void on_createMarker();
+       void on_setZeroPosition();
        void on_toggleHoverMarker();
 
 private:
index fa911f0..79277b4 100644 (file)
@@ -495,9 +495,12 @@ const Timestamp& View::ruler_offset() const
        return ruler_offset_;
 }
 
-void View::set_zero_position(pv::util::Timestamp& position)
+void View::set_zero_position(const pv::util::Timestamp& position)
 {
-       ruler_shift_ = -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_));
 
        // Force an immediate update of the offsets
        set_offset(offset_, true);
index 7e1122a..a6655d2 100644 (file)
@@ -173,7 +173,7 @@ public:
         */
        const pv::util::Timestamp& ruler_offset() const;
 
-       void set_zero_position(pv::util::Timestamp& position);
+       void set_zero_position(const pv::util::Timestamp& position);
 
        void reset_zero_position();