From: Joel Holdsworth Date: Wed, 5 Nov 2014 22:03:46 +0000 (+0000) Subject: RowItemOwner: Replaced parent notification scheme X-Git-Tag: pulseview-0.3.0~450 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=32218d3e708553b4508c3510d388aded58068381;p=pulseview.git RowItemOwner: Replaced parent notification scheme --- diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 5ca665e0..3b27cda3 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -780,7 +780,7 @@ void DecodeTrace::commit_channels() void DecodeTrace::on_new_decode_data() { if (_owner) - _owner->update_viewport(); + _owner->appearance_changed(false, true); } void DecodeTrace::delete_pressed() @@ -839,7 +839,8 @@ void DecodeTrace::on_show_hide_decoder(int index) assert(index < (int)_decoder_forms.size()); _decoder_forms[index]->set_decoder_visible(show); - _owner->update_viewport(); + if (_owner) + _owner->appearance_changed(false, true); } } // namespace view diff --git a/pv/view/header.cpp b/pv/view/header.cpp index 2264bc2c..ffdf79a6 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -84,15 +84,6 @@ void Header::clear_selection() update(); } -void Header::signals_updated() -{ - for (shared_ptr r : _view) { - assert(r); - connect(r.get(), SIGNAL(appearance_changed()), - this, SLOT(on_trace_changed())); - } -} - void Header::show_popup(const shared_ptr &item) { using pv::widgets::Popup; @@ -297,11 +288,5 @@ void Header::on_signals_moved() update(); } -void Header::on_trace_changed() -{ - update(); - geometry_updated(); -} - } // namespace view } // namespace pv diff --git a/pv/view/header.h b/pv/view/header.h index 808de5d5..909c04ae 100644 --- a/pv/view/header.h +++ b/pv/view/header.h @@ -51,8 +51,6 @@ public: */ static const int BaselineOffset; - void signals_updated(); - private: std::shared_ptr get_mouse_over_row_item( const QPoint &pt); @@ -82,8 +80,6 @@ private: private Q_SLOTS: void on_signals_moved(); - void on_trace_changed(); - Q_SIGNALS: void signals_moved(); diff --git a/pv/view/rowitem.cpp b/pv/view/rowitem.cpp index 120a00a3..b64294c4 100644 --- a/pv/view/rowitem.cpp +++ b/pv/view/rowitem.cpp @@ -45,6 +45,9 @@ void RowItem::set_layout_v_offset(int v_offset) return; _layout_v_offset = v_offset; + + if (_owner) + _owner->extents_changed(false, true); } int RowItem::visual_v_offset() const @@ -55,6 +58,9 @@ int RowItem::visual_v_offset() const void RowItem::set_visual_v_offset(int v_offset) { _visual_v_offset = v_offset; + + if (_owner) + _owner->appearance_changed(true, true); } void RowItem::force_to_v_offset(int v_offset) diff --git a/pv/view/rowitem.h b/pv/view/rowitem.h index aba7260b..d068848a 100644 --- a/pv/view/rowitem.h +++ b/pv/view/rowitem.h @@ -142,9 +142,6 @@ public: public: virtual void hover_point_changed(); -Q_SIGNALS: - void appearance_changed(); - protected: pv::view::RowItemOwner *_owner; diff --git a/pv/view/rowitemowner.cpp b/pv/view/rowitemowner.cpp index 03f0e68d..dd41af05 100644 --- a/pv/view/rowitemowner.cpp +++ b/pv/view/rowitemowner.cpp @@ -57,6 +57,8 @@ void RowItemOwner::add_child_item(std::shared_ptr item) assert(!item->owner()); item->set_owner(this); _items.push_back(item); + + extents_changed(true, true); } void RowItemOwner::remove_child_item(std::shared_ptr item) @@ -66,6 +68,8 @@ void RowItemOwner::remove_child_item(std::shared_ptr item) auto iter = std::find(_items.begin(), _items.end(), item); assert(iter != _items.end()); _items.erase(iter); + + extents_changed(true, true); } RowItemOwner::iterator RowItemOwner::begin() diff --git a/pv/view/rowitemowner.h b/pv/view/rowitemowner.h index 4b25a580..c2d38134 100644 --- a/pv/view/rowitemowner.h +++ b/pv/view/rowitemowner.h @@ -119,7 +119,10 @@ public: */ std::pair v_extents() const; - virtual void update_viewport() = 0; +public: + virtual void appearance_changed(bool label, bool content) = 0; + + virtual void extents_changed(bool horz, bool vert) = 0; private: item_list _items; diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index cbd5ac42..54c9c982 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -85,7 +85,9 @@ bool Signal::enabled() const void Signal::enable(bool enable) { _channel->set_enabled(enable); - appearance_changed(); + + if (_owner) + _owner->extents_changed(true, true); } shared_ptr Signal::channel() const diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 166fc1ab..9caa8f01 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -223,13 +223,17 @@ void Trace::on_popup_closed() void Trace::on_text_changed(const QString &text) { set_name(text); - appearance_changed(); + + if (_owner) + _owner->extents_changed(true, false); } void Trace::on_colour_changed(const QColor &colour) { set_colour(colour); - appearance_changed(); + + if (_owner) + _owner->appearance_changed(true, false); } } // namespace view diff --git a/pv/view/tracegroup.cpp b/pv/view/tracegroup.cpp index 4404b1cd..05a72dda 100644 --- a/pv/view/tracegroup.cpp +++ b/pv/view/tracegroup.cpp @@ -155,12 +155,6 @@ int TraceGroup::owner_v_offset() const return _owner ? layout_v_offset() + _owner->owner_v_offset() : 0; } -void TraceGroup::update_viewport() -{ - if (_owner) - _owner->update_viewport(); -} - void TraceGroup::on_ungroup() { const vector< shared_ptr > items( @@ -171,7 +165,18 @@ void TraceGroup::on_ungroup() _owner->add_child_item(r); _owner->remove_child_item(shared_from_this()); - appearance_changed(); +} + +void TraceGroup::appearance_changed(bool label, bool content) +{ + if (_owner) + _owner->appearance_changed(label, content); +} + +void TraceGroup::extents_changed(bool horz, bool vert) +{ + if (_owner) + _owner->extents_changed(horz, vert); } } // namespace view diff --git a/pv/view/tracegroup.h b/pv/view/tracegroup.h index 5171b7fc..218f42b1 100644 --- a/pv/view/tracegroup.h +++ b/pv/view/tracegroup.h @@ -110,7 +110,10 @@ public: */ int owner_v_offset() const; - void update_viewport(); +public: + void appearance_changed(bool label, bool content); + + void extents_changed(bool horz, bool vert); private Q_SLOTS: void on_ungroup(); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index d48bbabe..d8925c1a 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -105,8 +105,6 @@ View::View(SigSession &session, QWidget *parent) : connect(_cursors.second().get(), SIGNAL(time_changed()), this, SLOT(marker_time_changed())); - connect(_header, SIGNAL(geometry_updated()), - this, SLOT(on_geometry_updated())); connect(_header, SIGNAL(signals_moved()), this, SLOT(on_signals_moved())); @@ -123,6 +121,10 @@ View::View(SigSession &session, QWidget *parent) : 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); + setViewport(_viewport); _viewport->installEventFilter(this); @@ -454,6 +456,22 @@ void View::resizeEvent(QResizeEvent*) update_layout(); } +void View::appearance_changed(bool label, bool content) +{ + if (label) + _header->update(); + if (content) + _viewport->update(); +} + +void View::extents_changed(bool horz, bool vert) +{ + _sticky_events |= + (horz ? SelectableItemHExtentsChanged : 0) | + (vert ? SelectableItemVExtentsChanged : 0); + _lazy_event_handler.start(); +} + void View::h_scroll_value_changed(int value) { if (_updating_scroll) @@ -509,10 +527,6 @@ void View::signals_changed() } update_layout(); - - // Update the child widgets - _header->signals_updated(); - _viewport->signals_updated(); } void View::data_updated() @@ -536,9 +550,17 @@ void View::on_signals_moved() signals_moved(); } -void View::on_geometry_updated() +void View::process_sticky_events() { - update_layout(); + if (_sticky_events & SelectableItemHExtentsChanged) + update_layout(); + if (_sticky_events & SelectableItemVExtentsChanged) { + _viewport->update(); + _header->update(); + } + + // Clear the sticky events + _sticky_events = 0; } void View::on_hover_point_changed() diff --git a/pv/view/view.h b/pv/view/view.h index 07bd5d9c..71a38f11 100644 --- a/pv/view/view.h +++ b/pv/view/view.h @@ -29,6 +29,7 @@ #include #include +#include #include @@ -49,6 +50,12 @@ class Viewport; class View : public QAbstractScrollArea, public RowItemOwner { Q_OBJECT +private: + enum StickyEvents { + SelectableItemHExtentsChanged = 1, + SelectableItemVExtentsChanged = 2 + }; + private: static const double MaxScale; static const double MinScale; @@ -188,6 +195,11 @@ private: void resizeEvent(QResizeEvent *e); +public: + void appearance_changed(bool label, bool content); + + void extents_changed(bool horz, bool vert); + private Q_SLOTS: void h_scroll_value_changed(int value); @@ -200,7 +212,7 @@ private Q_SLOTS: void on_signals_moved(); - void on_geometry_updated(); + void process_sticky_events(); void on_hover_point_changed(); @@ -225,6 +237,9 @@ private: CursorPair _cursors; QPoint _hover_point; + + unsigned int _sticky_events; + QTimer _lazy_event_handler; }; } // namespace view diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index c85f915a..eeca690d 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -56,15 +56,6 @@ Viewport::Viewport(View &parent) : this, SLOT(on_signals_moved())); } -void Viewport::signals_updated() -{ - for (shared_ptr r : _view) { - assert(r); - connect(r.get(), SIGNAL(appearance_changed()), - this, SLOT(update())); - } -} - void Viewport::paintEvent(QPaintEvent*) { vector< shared_ptr > row_items(_view.begin(), _view.end()); diff --git a/pv/view/viewport.h b/pv/view/viewport.h index f88f4f10..1de9cd2a 100644 --- a/pv/view/viewport.h +++ b/pv/view/viewport.h @@ -41,8 +41,6 @@ class Viewport : public QWidget public: explicit Viewport(View &parent); - void signals_updated(); - protected: void paintEvent(QPaintEvent *event);