From: Joel Holdsworth Date: Sun, 13 Oct 2013 09:14:24 +0000 (+0100) Subject: Probes popup now live applies properly X-Git-Tag: pulseview-0.2.0~253 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=aca00b1e0d3483926c53dfd856483a397f1c29a5;p=pulseview.git Probes popup now live applies properly SamplingBar now has a reference to SigSession --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 97103ad5..f7b86120 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -214,13 +214,11 @@ void MainWindow::setup_ui() addToolBar(_toolbar); // Setup the sampling bar - _sampling_bar = new toolbars::SamplingBar(this); + _sampling_bar = new toolbars::SamplingBar(_session, this); // Populate the device list and select the initially selected device update_device_list(); - connect(_sampling_bar, SIGNAL(device_selected()), this, - SLOT(device_selected())); connect(_sampling_bar, SIGNAL(run_stop()), this, SLOT(run_stop())); addToolBar(_sampling_bar); @@ -370,11 +368,6 @@ void MainWindow::on_actionAbout_triggered() dlg.exec(); } -void MainWindow::device_selected() -{ - _session.set_device(_sampling_bar->get_selected_device()); -} - void MainWindow::add_decoder(QObject *action) { assert(action); diff --git a/pv/mainwindow.h b/pv/mainwindow.h index d34db1bf..47704c2f 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -97,8 +97,6 @@ private slots: void on_actionAbout_triggered(); - void device_selected(); - void add_decoder(QObject *action); void run_stop(); diff --git a/pv/popups/probes.cpp b/pv/popups/probes.cpp index 9684d435..5499df62 100644 --- a/pv/popups/probes.cpp +++ b/pv/popups/probes.cpp @@ -20,22 +20,25 @@ #include "probes.h" +#include +#include + +using namespace boost; using namespace Qt; +using namespace std; namespace pv { namespace popups { -Probes::Probes(sr_dev_inst *sdi, QWidget *parent) : +Probes::Probes(SigSession &session, QWidget *parent) : Popup(parent), - _sdi(sdi), + _session(session), _layout(this), _probes(this), _probes_bar(this), _enable_all_probes(this), _disable_all_probes(this) { - assert(_sdi); - setLayout(&_layout); connect(&_enable_all_probes, SIGNAL(clicked()), @@ -53,16 +56,17 @@ Probes::Probes(sr_dev_inst *sdi, QWidget *parent) : _layout.addWidget(&_probes_bar); - for (const GSList *l = _sdi->probes; l; l = l->next) { - sr_probe *const probe = (sr_probe*)l->data; - assert(probe); + 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( - probe->name, &_probes); + s->get_name(), &_probes); assert(item); - item->setData(UserRole, - qVariantFromValue((void*)probe)); - item->setCheckState(probe->enabled ? - Checked : Unchecked); + item->setData(UserRole, qVariantFromValue(i)); + item->setCheckState(s->enabled() ? Checked : Unchecked); _probes.addItem(item); } @@ -72,25 +76,33 @@ Probes::Probes(sr_dev_inst *sdi, QWidget *parent) : void Probes::set_all_probes(bool set) { - for (int i = 0; i < _probes.count(); i++) { + using pv::view::Signal; + + 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); + s->enable(set); + QListWidgetItem *const item = _probes.item(i); assert(item); item->setCheckState(set ? Qt::Checked : Qt::Unchecked); - - sr_probe *const probe = (sr_probe*) - item->data(UserRole).value(); - assert(probe); - probe->enabled = item->checkState() == Checked; } } void Probes::item_changed(QListWidgetItem *item) { + using pv::view::Signal; + assert(item); - sr_probe *const probe = (sr_probe*) - item->data(UserRole).value(); - assert(probe); - probe->enabled = item->checkState() == Checked; + const vector< shared_ptr > sigs = + _session.get_signals(); + const shared_ptr s = sigs[ + item->data(UserRole).value()]; + assert(s); + s->enable(item->checkState() == Checked); } void Probes::enable_all_probes() diff --git a/pv/popups/probes.h b/pv/popups/probes.h index 33f5d996..8a1fdd57 100644 --- a/pv/popups/probes.h +++ b/pv/popups/probes.h @@ -29,6 +29,9 @@ #include namespace pv { + +class SigSession; + namespace popups { class Probes : public pv::widgets::Popup @@ -36,7 +39,7 @@ class Probes : public pv::widgets::Popup Q_OBJECT public: - Probes(sr_dev_inst *sdi, QWidget *parent); + Probes(SigSession &_session, QWidget *parent); private: void set_all_probes(bool set); @@ -48,7 +51,7 @@ private slots: void disable_all_probes(); private: - sr_dev_inst *_sdi; + pv::SigSession &_session; QVBoxLayout _layout; diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index dacf65e5..1099ad46 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -378,8 +378,7 @@ void SigSession::update_signals(const sr_dev_inst *const sdi) if(sdi) { for (const GSList *l = sdi->probes; l; l = l->next) { - const sr_probe *const probe = - (const sr_probe *)l->data; + sr_probe *const probe = (sr_probe *)l->data; assert(probe); switch(probe->type) { diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index ae4f298b..24c5a420 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -64,8 +64,9 @@ const uint64_t SamplingBar::RecordLengths[20] = { const uint64_t SamplingBar::DefaultRecordLength = 1000000; -SamplingBar::SamplingBar(QWidget *parent) : +SamplingBar::SamplingBar(SigSession &session, QWidget *parent) : QToolBar("Sampling Bar", parent), + _session(session), _device_selector(this), _configure_button(this), _probes_button(this), @@ -299,11 +300,10 @@ void SamplingBar::on_device_selected() update_sample_rate_selector(); sr_dev_inst *const sdi = get_selected_device(); + _session.set_device(sdi); _configure_button.set_popup(new DeviceOptions(sdi, this)); - _probes_button.set_popup(new Probes(sdi, this)); - - device_selected(); + _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 0c1a0539..039e4e41 100644 --- a/pv/toolbars/samplingbar.h +++ b/pv/toolbars/samplingbar.h @@ -38,6 +38,9 @@ struct st_dev_inst; class QAction; namespace pv { + +class SigSession; + namespace toolbars { class SamplingBar : public QToolBar @@ -49,7 +52,7 @@ private: static const uint64_t DefaultRecordLength; public: - SamplingBar(QWidget *parent); + SamplingBar(SigSession &session, QWidget *parent); void set_device_list(const std::list &devices); @@ -61,8 +64,6 @@ public: void set_capture_state(pv::SigSession::capture_state state); signals: - void device_selected(); - void run_stop(); private: @@ -76,6 +77,8 @@ private slots: void on_run_stop(); private: + SigSession &_session; + QComboBox _device_selector; pv::widgets::PopupToolButton _configure_button; diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 53af2643..4304fd1e 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -42,7 +42,7 @@ const QColor AnalogSignal::SignalColours[4] = { const float AnalogSignal::EnvelopeThreshold = 256.0f; -AnalogSignal::AnalogSignal(pv::SigSession &session, const sr_probe *const probe, +AnalogSignal::AnalogSignal(pv::SigSession &session, sr_probe *const probe, shared_ptr data) : Signal(session, probe), _data(data), diff --git a/pv/view/analogsignal.h b/pv/view/analogsignal.h index 35db2ddc..64d138d8 100644 --- a/pv/view/analogsignal.h +++ b/pv/view/analogsignal.h @@ -42,7 +42,7 @@ private: static const float EnvelopeThreshold; public: - AnalogSignal(pv::SigSession &session, const sr_probe *const probe, + AnalogSignal(pv::SigSession &session, sr_probe *const probe, boost::shared_ptr data); virtual ~AnalogSignal(); diff --git a/pv/view/header.cpp b/pv/view/header.cpp index ba16247a..77a887f9 100644 --- a/pv/view/header.cpp +++ b/pv/view/header.cpp @@ -240,6 +240,8 @@ void Header::on_signals_changed() const vector< shared_ptr > traces(_view.get_traces()); BOOST_FOREACH(shared_ptr t, traces) { assert(t); + connect(t.get(), SIGNAL(visibility_changed()), + this, SLOT(update())); connect(t.get(), SIGNAL(text_changed()), this, SLOT(update())); connect(t.get(), SIGNAL(colour_changed()), diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index b0fe9513..a9484817 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -55,7 +55,7 @@ const QColor LogicSignal::SignalColours[10] = { QColor(0xEE, 0xEE, 0xEC), // White }; -LogicSignal::LogicSignal(pv::SigSession &session, const sr_probe *const probe, +LogicSignal::LogicSignal(pv::SigSession &session, sr_probe *const probe, shared_ptr data) : Signal(session, probe), _data(data), diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index 4dbd5e83..92d4cb0f 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -49,7 +49,7 @@ private: static const QColor SignalColours[10]; public: - LogicSignal(pv::SigSession &session, const sr_probe *const probe, + LogicSignal(pv::SigSession &session, sr_probe *const probe, boost::shared_ptr data); virtual ~LogicSignal(); diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index dadba05a..aee21416 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -48,7 +48,7 @@ const char *const ProbeNames[] = { "SCL" }; -Signal::Signal(pv::SigSession &session, const sr_probe *const probe) : +Signal::Signal(pv::SigSession &session, sr_probe *const probe) : Trace(session, probe->name), _probe(probe), _name_widget(NULL), @@ -70,6 +70,12 @@ bool Signal::enabled() const return _probe->enabled; } +void Signal::enable(bool enable) +{ + _probe->enabled = enable; + visibility_changed(); +} + const sr_probe* Signal::probe() const { return _probe; diff --git a/pv/view/signal.h b/pv/view/signal.h index 01f057fe..86d2f380 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -43,7 +43,7 @@ class Signal : public Trace Q_OBJECT protected: - Signal(pv::SigSession &session, const sr_probe *const probe); + Signal(pv::SigSession &session, sr_probe *const probe); public: /** @@ -56,12 +56,14 @@ public: */ bool enabled() const; + void enable(bool enable = true); + const sr_probe* probe() const; virtual void populate_popup_form(QWidget *parent, QFormLayout *form); protected: - const sr_probe *const _probe; + sr_probe *const _probe; QComboBox *_name_widget; bool _updating_name_widget; diff --git a/pv/view/trace.h b/pv/view/trace.h index 05adf6cf..ca4040d2 100644 --- a/pv/view/trace.h +++ b/pv/view/trace.h @@ -184,6 +184,7 @@ private slots: void on_colour_changed(const QColor &colour); signals: + void visibility_changed(); void text_changed(); void colour_changed(); diff --git a/pv/view/viewport.cpp b/pv/view/viewport.cpp index 8cf97ff5..a06c8888 100644 --- a/pv/view/viewport.cpp +++ b/pv/view/viewport.cpp @@ -42,6 +42,9 @@ Viewport::Viewport(View &parent) : setAutoFillBackground(true); setBackgroundRole(QPalette::Base); + connect(&_view.session(), SIGNAL(signals_changed()), + this, SLOT(on_signals_changed())); + connect(&_view, SIGNAL(signals_moved()), this, SLOT(on_signals_moved())); } @@ -123,6 +126,16 @@ void Viewport::wheelEvent(QWheelEvent *event) } } +void Viewport::on_signals_changed() +{ + const vector< shared_ptr > traces(_view.get_traces()); + BOOST_FOREACH(shared_ptr t, traces) { + assert(t); + connect(t.get(), SIGNAL(visibility_changed()), + this, SLOT(update())); + } +} + void Viewport::on_signals_moved() { update(); diff --git a/pv/view/viewport.h b/pv/view/viewport.h index c15ef0a4..4add1ccf 100644 --- a/pv/view/viewport.h +++ b/pv/view/viewport.h @@ -51,6 +51,7 @@ private: void wheelEvent(QWheelEvent *event); private slots: + void on_signals_changed(); void on_signals_moved(); private: