]> sigrok.org Git - pulseview.git/commitdiff
RowItemOwner: Replaced parent notification scheme
authorJoel Holdsworth <redacted>
Wed, 5 Nov 2014 22:03:46 +0000 (22:03 +0000)
committerJoel Holdsworth <redacted>
Wed, 19 Nov 2014 10:23:31 +0000 (10:23 +0000)
15 files changed:
pv/view/decodetrace.cpp
pv/view/header.cpp
pv/view/header.h
pv/view/rowitem.cpp
pv/view/rowitem.h
pv/view/rowitemowner.cpp
pv/view/rowitemowner.h
pv/view/signal.cpp
pv/view/trace.cpp
pv/view/tracegroup.cpp
pv/view/tracegroup.h
pv/view/view.cpp
pv/view/view.h
pv/view/viewport.cpp
pv/view/viewport.h

index 5ca665e0dff947f17ebbcbd0a5a77aa8802d1b98..3b27cda311d41b9860ec7ad93f451ee52ffd5f0f 100644 (file)
@@ -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
index 2264bc2c945f96b41ea88d387af4c5221d3a8cb9..ffdf79a6cce9f29e8bf6d105d65a399a6dd3e124 100644 (file)
@@ -84,15 +84,6 @@ void Header::clear_selection()
        update();
 }
 
-void Header::signals_updated()
-{
-       for (shared_ptr<RowItem> r : _view) {
-               assert(r);
-               connect(r.get(), SIGNAL(appearance_changed()),
-                       this, SLOT(on_trace_changed()));
-       }
-}
-
 void Header::show_popup(const shared_ptr<RowItem> &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
index 808de5d5c966aed905da5f2e06a88d5714e3c80a..909c04ae353b55c6825d3e9b6d0735e67e516392 100644 (file)
@@ -51,8 +51,6 @@ public:
         */
        static const int BaselineOffset;
 
-       void signals_updated();
-
 private:
        std::shared_ptr<pv::view::RowItem> 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();
 
index 120a00a39d1cd0a1fb478c5facf446d86e8722ad..b64294c48907f564540c8edb91b33be01affdc95 100644 (file)
@@ -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)
index aba7260b0a814797c9ec689bedd16e663216056f..d068848a54be6faf30488187516354f7d650fdc0 100644 (file)
@@ -142,9 +142,6 @@ public:
 public:
        virtual void hover_point_changed();
 
-Q_SIGNALS:
-       void appearance_changed();
-
 protected:
        pv::view::RowItemOwner *_owner;
 
index 03f0e68d3ae52e5a0451f80c66683052b470e460..dd41af05b6e900ce9a6c2dc25d34181be3d81836 100644 (file)
@@ -57,6 +57,8 @@ void RowItemOwner::add_child_item(std::shared_ptr<RowItem> item)
        assert(!item->owner());
        item->set_owner(this);
        _items.push_back(item);
+
+       extents_changed(true, true);
 }
 
 void RowItemOwner::remove_child_item(std::shared_ptr<RowItem> item)
@@ -66,6 +68,8 @@ void RowItemOwner::remove_child_item(std::shared_ptr<RowItem> 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()
index 4b25a580da685bf6bd8de62ff3d3167db72612bc..c2d38134e2080027d4b12bafa8faea4874851513 100644 (file)
@@ -119,7 +119,10 @@ public:
         */
        std::pair<int, int> 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;
index cbd5ac423b9b23d94bf27cbd0b02c5c5ed381db3..54c9c9828e5c52fd691e63e117a2eddd03e6f68b 100644 (file)
@@ -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<Channel> Signal::channel() const
index 166fc1abc6831beb966adf001f7bdc92024a1356..9caa8f012adf57310f4ca65fe29c3254380b7c38 100644 (file)
@@ -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
index 4404b1cd866fe9e160e05a676b9fd3423c3fddd4..05a72dda021633fa4479dc6e292a390dc2ca3771 100644 (file)
@@ -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<RowItem> > 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
index 5171b7fc880c23f5e2d390ba2bc1d06c553e3399..218f42b11d3df54d548f1c3e4cf41f49d2bdf411 100644 (file)
@@ -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();
index d48bbabebd4088e0b49128e00f5152577350b6b6..d8925c1aaa2acc1f2d3f0b4bc5a39bf3d420d3c0 100644 (file)
@@ -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()
index 07bd5d9caeade08c0f75b90da5003c423f8dde7a..71a38f11888b0034ce3c916a6a19d5939107459d 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <QAbstractScrollArea>
 #include <QSizeF>
+#include <QTimer>
 
 #include <pv/data/signaldata.h>
 
@@ -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
index c85f915a591eba05e36791f870509da3b943eebe..eeca690da0e45cb4efb96bbfc619082ab9d6234b 100644 (file)
@@ -56,15 +56,6 @@ Viewport::Viewport(View &parent) :
                this, SLOT(on_signals_moved()));
 }
 
-void Viewport::signals_updated()
-{
-       for (shared_ptr<RowItem> r : _view) {
-               assert(r);
-               connect(r.get(), SIGNAL(appearance_changed()),
-                       this, SLOT(update()));
-       }
-}
-
 void Viewport::paintEvent(QPaintEvent*)
 {
        vector< shared_ptr<RowItem> > row_items(_view.begin(), _view.end());
index f88f4f108a5a0d630709b21ca100f3c2798e1329..1de9cd2a5d1ac51e1e40f6de101baa40754b05f8 100644 (file)
@@ -41,8 +41,6 @@ class Viewport : public QWidget
 public:
        explicit Viewport(View &parent);
 
-       void signals_updated();
-
 protected:
        void paintEvent(QPaintEvent *event);