From: Soeren Apel Date: Wed, 3 Jul 2019 07:45:09 +0000 (+0200) Subject: Don't return valid time() for the cursor pair X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e4e951b7fcfa4c6bf36547d0106bfa730fceb92c;p=pulseview.git Don't return valid time() for the cursor pair --- diff --git a/pv/views/trace/cursorpair.cpp b/pv/views/trace/cursorpair.cpp index f58db8fa..ba65e6c1 100644 --- a/pv/views/trace/cursorpair.cpp +++ b/pv/views/trace/cursorpair.cpp @@ -86,7 +86,7 @@ void CursorPair::set_time(const pv::util::Timestamp& time) const pv::util::Timestamp CursorPair::time() const { - return (first_->time() + second_->time()) / 2.0f; + return 0; } float CursorPair::get_x() const diff --git a/pv/views/trace/ruler.cpp b/pv/views/trace/ruler.cpp index 33746ed6..bebf5291 100644 --- a/pv/views/trace/ruler.cpp +++ b/pv/views/trace/ruler.cpp @@ -194,10 +194,12 @@ void Ruler::item_hover(const shared_ptr &item, QPoint pos) shared_ptr Ruler::get_reference_item() const { + // Note: time() returns 0 if item returns no valid time + if (mouse_modifiers_ & Qt::ShiftModifier) return nullptr; - if (hover_item_) + if (hover_item_ && (hover_item_->time() != 0)) return hover_item_; shared_ptr ref_item; @@ -215,6 +217,9 @@ shared_ptr Ruler::get_reference_item() const } } + if (ref_item && (ref_item->time() == 0)) + ref_item.reset(); + return ref_item; } diff --git a/pv/views/trace/timeitem.hpp b/pv/views/trace/timeitem.hpp index c9b322c7..e0114a5a 100644 --- a/pv/views/trace/timeitem.hpp +++ b/pv/views/trace/timeitem.hpp @@ -49,6 +49,10 @@ public: */ virtual void set_time(const pv::util::Timestamp& time) = 0; + /** + * Returns the time this time item is set to. + * @return 0 in case there is no valid time (e.g. for a cursor pair) + */ virtual const pv::util::Timestamp time() const = 0; virtual float get_x() const = 0;