From: Soeren Apel Date: Mon, 22 Oct 2018 20:01:22 +0000 (+0200) Subject: Ruler: Add "Set as zero point" context menu entry X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e23567ed84aa55e2a0c48252080058186f6b80e7;p=pulseview.git Ruler: Add "Set as zero point" context menu entry --- diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index 1204559c..6e74ddd0 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -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; diff --git a/pv/views/trace/ruler.hpp b/pv/views/trace/ruler.hpp index d7cab4d7..b1414872 100644 --- a/pv/views/trace/ruler.hpp +++ b/pv/views/trace/ruler.hpp @@ -176,6 +176,7 @@ private Q_SLOTS: void invalidate_tick_position_cache(); void on_createMarker(); + void on_setZeroPosition(); void on_toggleHoverMarker(); private: diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index fa911f0b..79277b4e 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -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); diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index 7e1122a4..a6655d2f 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -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();