]> sigrok.org Git - pulseview.git/commitdiff
Ruler: Add "Set as zero point" context menu entry
authorSoeren Apel <redacted>
Mon, 22 Oct 2018 20:01:22 +0000 (22:01 +0200)
committerSoeren Apel <redacted>
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 1204559c5c943d5838a968a1bd0d636c5617dfc1..6e74ddd0a29a272b2d1661b64d2054949767f040 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 d7cab4d74caa54f1ef4600d9d1bf37a9d1f0bef8..b14148728c579b8c8f2885c8a76859fae976a3ca 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 fa911f0b5ad92ae8a27c0f96b3d69de2de984aab..79277b4e17074708b0f1e3718ef6eeb4996d2c93 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 7e1122a44aaabab919aa64783eff1d707ef6ee19..a6655d2f492ab941617fc95f7c694463b1aa6645 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();