From b7b659aa72851df2d34d4c1e5fd5636fbd9176d1 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 13 Oct 2013 23:12:37 +0100 Subject: [PATCH] Made Probes popup reusable --- pv/popups/probes.cpp | 45 ++++++++++++++++++++++++++----------- pv/popups/probes.h | 5 +++++ pv/toolbars/samplingbar.cpp | 6 +++-- pv/toolbars/samplingbar.h | 2 ++ pv/widgets/popup.cpp | 10 ++++----- pv/widgets/popup.h | 5 +++-- 6 files changed, 51 insertions(+), 22 deletions(-) diff --git a/pv/popups/probes.cpp b/pv/popups/probes.cpp index 5499df62..51ba3ddc 100644 --- a/pv/popups/probes.cpp +++ b/pv/popups/probes.cpp @@ -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 > sigs = _session.get_signals(); for (unsigned int i = 0; i < sigs.size(); i++) { const shared_ptr &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 > sigs = _session.get_signals(); @@ -84,18 +97,24 @@ void Probes::set_all_probes(bool set) { const shared_ptr &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 > sigs = _session.get_signals(); diff --git a/pv/popups/probes.h b/pv/popups/probes.h index 8a1fdd57..b5eda58f 100644 --- a/pv/popups/probes.h +++ b/pv/popups/probes.h @@ -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; diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index bafb9cd4..b80d6f80 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -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() diff --git a/pv/toolbars/samplingbar.h b/pv/toolbars/samplingbar.h index 806a79a6..e4aa40d4 100644 --- a/pv/toolbars/samplingbar.h +++ b/pv/toolbars/samplingbar.h @@ -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; diff --git a/pv/widgets/popup.cpp b/pv/widgets/popup.cpp index f89e38a6..399f5e28 100644 --- a/pv/widgets/popup.cpp +++ b/pv/widgets/popup.cpp @@ -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 diff --git a/pv/widgets/popup.h b/pv/widgets/popup.h index 402fc6bd..1da09d85 100644 --- a/pv/widgets/popup.h +++ b/pv/widgets/popup.h @@ -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; -- 2.30.2