]> sigrok.org Git - pulseview.git/commitdiff
Made Probes popup reusable
authorJoel Holdsworth <redacted>
Sun, 13 Oct 2013 22:12:37 +0000 (23:12 +0100)
committerJoel Holdsworth <redacted>
Mon, 14 Oct 2013 12:00:26 +0000 (13:00 +0100)
pv/popups/probes.cpp
pv/popups/probes.h
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h
pv/widgets/popup.cpp
pv/widgets/popup.h

index 5499df62cd9496dc141ee3ef5cc2a45fb596b69a..51ba3ddca8b2744bfd60e89a109906ab741f60dd 100644 (file)
@@ -35,6 +35,7 @@ Probes::Probes(SigSession &session, QWidget *parent) :
        _session(session),
        _layout(this),
        _probes(this),
+       _updating_probes(false),
        _probes_bar(this),
        _enable_all_probes(this),
        _disable_all_probes(this)
@@ -56,27 +57,39 @@ Probes::Probes(SigSession &session, QWidget *parent) :
 
        _layout.addWidget(&_probes_bar);
 
+       connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)),
+               this, SLOT(item_changed(QListWidgetItem*)));
+}
+
+void Probes::set_all_probes(bool set)
+{
+       using pv::view::Signal;
+
+       _updating_probes = true;
+
        const vector< shared_ptr<pv::view::Signal> > sigs =
                _session.get_signals();
        for (unsigned int i = 0; i < sigs.size(); i++)
        {
                const shared_ptr<pv::view::Signal> &s = sigs[i];
                assert(s);
-               QListWidgetItem *const item = new QListWidgetItem(
-                       s->get_name(), &_probes);
+               s->enable(set);
+
+               QListWidgetItem *const item = _probes.item(i);
                assert(item);
-               item->setData(UserRole, qVariantFromValue(i));
-               item->setCheckState(s->enabled() ? Checked : Unchecked);
-               _probes.addItem(item);
+               item->setCheckState(set ? Qt::Checked : Qt::Unchecked);
        }
 
-       connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)),
-               this, SLOT(item_changed(QListWidgetItem*)));
+       _updating_probes = false;
 }
 
-void Probes::set_all_probes(bool set)
+void Probes::showEvent(QShowEvent *e)
 {
-       using pv::view::Signal;
+       pv::widgets::Popup::showEvent(e);
+
+       _updating_probes = true;
+
+       _probes.clear();
 
        const vector< shared_ptr<pv::view::Signal> > sigs =
                _session.get_signals();
@@ -84,18 +97,24 @@ void Probes::set_all_probes(bool set)
        {
                const shared_ptr<pv::view::Signal> &s = sigs[i];
                assert(s);
-               s->enable(set);
-
-               QListWidgetItem *const item = _probes.item(i);
+               QListWidgetItem *const item = new QListWidgetItem(
+                       s->get_name(), &_probes);
                assert(item);
-               item->setCheckState(set ? Qt::Checked : Qt::Unchecked);
+               item->setCheckState(s->enabled() ? Checked : Unchecked);
+               item->setData(UserRole, qVariantFromValue(i));
+               _probes.addItem(item);
        }
+
+       _updating_probes = false;
 }
 
 void Probes::item_changed(QListWidgetItem *item)
 {
        using pv::view::Signal;
 
+       if (_updating_probes)
+               return;
+
        assert(item);
        const vector< shared_ptr<pv::view::Signal> > sigs =
                _session.get_signals();
index 8a1fdd5753efa60a3cb6b89f7eef71efb9b962c4..b5eda58f3d9f5dd2c53a2286f4daa133765020b4 100644 (file)
@@ -44,6 +44,9 @@ public:
 private:
        void set_all_probes(bool set);
 
+private:
+       void showEvent(QShowEvent *e);
+
 private slots:
        void item_changed(QListWidgetItem *item);
 
@@ -56,6 +59,8 @@ private:
        QVBoxLayout _layout;
 
        QListWidget _probes;
+       bool _updating_probes;
+
        QToolBar _probes_bar;
        QToolButton _enable_all_probes;
        QToolButton _disable_all_probes;
index bafb9cd406bf05f9c76b54f2d91156e34d593e93..b80d6f80f0df737811aeb6c24c2132b11b77d613 100644 (file)
@@ -71,6 +71,7 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
        _updating_device_selector(false),
        _configure_button(this),
        _probes_button(this),
+       _probes_popup(_session, this),
        _record_length_selector(this),
        _sample_rate_list(this),
        _icon_red(":/icons/status-red.svg"),
@@ -102,8 +103,10 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) :
 
        _configure_button.setIcon(QIcon::fromTheme("configure",
                QIcon(":/icons/configure.png")));
+
        _probes_button.setIcon(QIcon::fromTheme("probes",
                QIcon(":/icons/probes.svg")));
+       _probes_button.set_popup(&_probes_popup);
 
        _run_stop_button.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
 
@@ -136,7 +139,7 @@ void SamplingBar::set_device_list(
 
        _updating_device_selector = false;
 
-       update_sample_rate_selector();
+       on_device_selected();
 }
 
 struct sr_dev_inst* SamplingBar::get_selected_device() const
@@ -311,7 +314,6 @@ void SamplingBar::on_device_selected()
        _session.set_device(sdi);
 
        _configure_button.set_popup(new DeviceOptions(sdi, this));
-       _probes_button.set_popup(new Probes(_session, this));
 }
 
 void SamplingBar::on_sample_rate_changed()
index 806a79a6c57547626d6175a9ec6c8ab0ba5fcecb..e4aa40d48a869e59c557ebd187fef13a0dab8df8 100644 (file)
@@ -83,7 +83,9 @@ private:
        bool _updating_device_selector;
 
        pv::widgets::PopupToolButton _configure_button;
+
        pv::widgets::PopupToolButton _probes_button;
+       pv::popups::Probes _probes_popup;
 
        QComboBox _record_length_selector;
 
index f89e38a6b1b84e3fdc9b923060f31688277c87f1..399f5e28b6d56d4d525b896a371208f304c7bb97 100644 (file)
@@ -198,11 +198,6 @@ void Popup::resizeEvent(QResizeEvent*)
        setMask(popup_region());
 }
 
-void Popup::showEvent(QShowEvent*)
-{
-       reposition_widget();
-}
-
 void Popup::mouseReleaseEvent(QMouseEvent *e)
 {
        assert(e);
@@ -213,6 +208,11 @@ void Popup::mouseReleaseEvent(QMouseEvent *e)
                close();
 }
 
+void Popup::showEvent(QShowEvent*)
+{
+       reposition_widget();
+}
+
 } // namespace widgets
 } // namespace pv
 
index 402fc6bda3d60944f7b087c4a99034133ef69d5e..1da09d85eb5965401205d459ccd038ab160e1fb0 100644 (file)
@@ -67,10 +67,11 @@ private:
 
        void resizeEvent(QResizeEvent*);
 
-       void showEvent(QShowEvent*);
-
        void mouseReleaseEvent(QMouseEvent *e);
 
+protected:
+       void showEvent(QShowEvent *e);
+
 private:
        QPoint _point;
        Position _pos;