]> sigrok.org Git - pulseview.git/commitdiff
Improve hover point signaling
authorSoeren Apel <redacted>
Sun, 23 Jul 2017 07:35:25 +0000 (09:35 +0200)
committerSoeren Apel <redacted>
Sun, 23 Jul 2017 07:35:25 +0000 (09:35 +0200)
Two issues here:
1) it's bad style to have an event handler for an event
that was triggered in the same class
2) supplying the current hover point along with the event
is a sensible thing to do

pv/views/trace/decodetrace.cpp
pv/views/trace/decodetrace.hpp
pv/views/trace/rowitem.cpp
pv/views/trace/rowitem.hpp
pv/views/trace/ruler.cpp
pv/views/trace/ruler.hpp
pv/views/trace/view.cpp
pv/views/trace/view.hpp

index b4857336f9e6e1e350bc73e91ef6409bcc3f7e2e..7bbc5a19b526cd5afa6856a578f1d03f989533df 100644 (file)
@@ -710,15 +710,13 @@ const QString DecodeTrace::get_annotation_at_point(const QPoint &point)
                QString() : annotations[0].annotations().front();
 }
 
-void DecodeTrace::hover_point_changed()
+void DecodeTrace::hover_point_changed(const QPoint &hp)
 {
        assert(owner_);
 
        const View *const view = owner_->view();
        assert(view);
 
-       QPoint hp = view->hover_point();
-
        if (hp.x() == 0) {
                QToolTip::hideText();
                return;
@@ -746,13 +744,14 @@ void DecodeTrace::hover_point_changed()
        // If it did, the tool tip would constantly hide and re-appear.
        // We also push it up by one row so that it appears above the
        // decode trace, not below.
-       hp.setX(hp.x() - (text_size.width() / 2) - padding);
+       QPoint p = hp;
+       p.setX(hp.x() - (text_size.width() / 2) - padding);
 
-       hp.setY(get_visual_y() - (row_height_ / 2) +
+       p.setY(get_visual_y() - (row_height_ / 2) +
                (hover_row * row_height_) -
                row_height_ - text_size.height() - padding);
 
-       QToolTip::showText(view->viewport()->mapToGlobal(hp), ann);
+       QToolTip::showText(view->viewport()->mapToGlobal(p), ann);
 }
 
 void DecodeTrace::create_decoder_form(int index,
index d6a1fbbeb2dd149780fcbcb4832e9930d25bdf2d..fe3503b6008817b4d47b9fc0b10ffe47d3ab9d01 100644 (file)
@@ -179,7 +179,7 @@ private:
                const data::DecodeChannel *ch);
 
 public:
-       void hover_point_changed();
+       void hover_point_changed(const QPoint &hp);
 
 private Q_SLOTS:
        void on_new_annotations();
index 11a02e9b4ebb1f1748fb1ef0f840f951365c7c46..c57043d47f309d801f3ed5e5b905584c56c3613d 100644 (file)
@@ -23,8 +23,9 @@ namespace pv {
 namespace views {
 namespace trace {
 
-void RowItem::hover_point_changed()
+void RowItem::hover_point_changed(const QPoint &hp)
 {
+       (void)hp;
 }
 
 } // namespace trace
index ae91d4bea486895d1e33587f5548f08a763b8d7d..d2a205fb6c3505acac0e492cee1d6f97d544660d 100644 (file)
@@ -31,7 +31,7 @@ class RowItem : public ViewItem
        Q_OBJECT
 
 public:
-       virtual void hover_point_changed();
+       virtual void hover_point_changed(const QPoint &hp);
 };
 
 } // namespace trace
index 5455b2099ba77abf7315a4e9fa11a98c5494d499..0526bb2ceb21646f8e49bb9c4e1c64dbb1b67f6c 100644 (file)
@@ -46,8 +46,8 @@ Ruler::Ruler(View &parent) :
 {
        setMouseTracking(true);
 
-       connect(&view_, SIGNAL(hover_point_changed()),
-               this, SLOT(hover_point_changed()));
+       connect(&view_, SIGNAL(hover_point_changed(QPoint)),
+               this, SLOT(hover_point_changed(QPoint)));
        connect(&view_, SIGNAL(offset_changed()),
                this, SLOT(invalidate_tick_position_cache()));
        connect(&view_, SIGNAL(scale_changed()),
@@ -256,8 +256,10 @@ int Ruler::calculate_text_height() const
        return QFontMetrics(font()).ascent();
 }
 
-void Ruler::hover_point_changed()
+void Ruler::hover_point_changed(const QPoint &hp)
 {
+       (void)hp;
+
        update();
 }
 
index 40aae48daa3faed09cb258b49f02599d5f942e02..661254a7280ebd3ce31d0aaac696db9cdc761031 100644 (file)
@@ -171,7 +171,7 @@ protected:
        void resizeEvent(QResizeEvent*) override;
 
 private Q_SLOTS:
-       void hover_point_changed();
+       void hover_point_changed(const QPoint &hp);
 
        // Resets the 'tick_position_cache_'.
        void invalidate_tick_position_cache();
index f8378d98204554305a32ba41516814da7a265012..bda056acbdec6c4a3a6521d22075507651b1dfde 100644 (file)
@@ -212,9 +212,6 @@ View::View(Session &session, bool is_main_view, QWidget *parent) :
        connect(splitter_, SIGNAL(splitterMoved(int, int)),
                this, SLOT(on_splitter_moved()));
 
-       connect(this, SIGNAL(hover_point_changed()),
-               this, SLOT(on_hover_point_changed()));
-
        connect(&lazy_event_handler_, SIGNAL(timeout()),
                this, SLOT(process_sticky_events()));
        lazy_event_handler_.setSingleShot(true);
@@ -1005,11 +1002,11 @@ bool View::eventFilter(QObject *object, QEvent *event)
                else
                        hover_point_ = QPoint(-1, -1);
 
-               hover_point_changed();
+               update_hover_point();
 
        } else if (type == QEvent::Leave) {
                hover_point_ = QPoint(-1, -1);
-               hover_point_changed();
+               update_hover_point();
        } else if (type == QEvent::Show) {
 
                // This is somewhat of a hack, unfortunately. We cannot use
@@ -1047,6 +1044,16 @@ void View::resizeEvent(QResizeEvent* event)
        update_layout();
 }
 
+void View::update_hover_point()
+{
+       const vector<shared_ptr<TraceTreeItem>> trace_tree_items(
+               list_by_type<TraceTreeItem>());
+       for (shared_ptr<TraceTreeItem> r : trace_tree_items)
+               r->hover_point_changed(hover_point_);
+
+       hover_point_changed(hover_point_);
+}
+
 void View::row_item_appearance_changed(bool label, bool content)
 {
        if (label)
@@ -1388,14 +1395,6 @@ void View::process_sticky_events()
        sticky_events_ = 0;
 }
 
-void View::on_hover_point_changed()
-{
-       const vector<shared_ptr<TraceTreeItem>> trace_tree_items(
-               list_by_type<TraceTreeItem>());
-       for (shared_ptr<TraceTreeItem> r : trace_tree_items)
-               r->hover_point_changed();
-}
-
 } // namespace trace
 } // namespace views
 } // namespace pv
index a42f964e0a173126b2cba892b7c803ae82cf8d89..f0aa491e585fa5f90998e9697a151404d2fb3275 100644 (file)
@@ -269,7 +269,7 @@ public:
        void restack_all_trace_tree_items();
 
 Q_SIGNALS:
-       void hover_point_changed();
+       void hover_point_changed(const QPoint &hp);
 
        void selection_changed();
 
@@ -347,6 +347,8 @@ private:
 
        void resizeEvent(QResizeEvent *event);
 
+       void update_hover_point();
+
 public:
        void row_item_appearance_changed(bool label, bool content);
        void time_item_appearance_changed(bool label, bool content);
@@ -367,8 +369,6 @@ private Q_SLOTS:
 
        void process_sticky_events();
 
-       void on_hover_point_changed();
-
        /**
         * Sets the 'offset_' member and emits the 'offset_changed'
         * signal if needed.