]> sigrok.org Git - pulseview.git/commitdiff
Probes popup now live applies properly
authorJoel Holdsworth <redacted>
Sun, 13 Oct 2013 09:14:24 +0000 (10:14 +0100)
committerJoel Holdsworth <redacted>
Sun, 13 Oct 2013 11:39:43 +0000 (12:39 +0100)
SamplingBar now has a reference to SigSession

17 files changed:
pv/mainwindow.cpp
pv/mainwindow.h
pv/popups/probes.cpp
pv/popups/probes.h
pv/sigsession.cpp
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h
pv/view/analogsignal.cpp
pv/view/analogsignal.h
pv/view/header.cpp
pv/view/logicsignal.cpp
pv/view/logicsignal.h
pv/view/signal.cpp
pv/view/signal.h
pv/view/trace.h
pv/view/viewport.cpp
pv/view/viewport.h

index 97103ad514724278debbcb3588c585c8534331b5..f7b8612054ff058997a8cd0f2cd3f75b8310f5a0 100644 (file)
@@ -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);
index d34db1bffaa6d4a4a53acf88f9b1d39617b2afdf..47704c2fc8f7abe1ab614c33f684ba4a87f1d513 100644 (file)
@@ -97,8 +97,6 @@ private slots:
 
        void on_actionAbout_triggered();
 
-       void device_selected();
-
        void add_decoder(QObject *action);
 
        void run_stop();
index 9684d435093cbcae8d6fc7a022eb02ab2bbc5f10..5499df62cd9496dc141ee3ef5cc2a45fb596b69a 100644 (file)
 
 #include "probes.h"
 
+#include <pv/sigsession.h>
+#include <pv/view/signal.h>
+
+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<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(
-                       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<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);
+               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<void*>();
-               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<void*>();
-       assert(probe);
-       probe->enabled = item->checkState() == Checked;
+       const vector< shared_ptr<pv::view::Signal> > sigs =
+               _session.get_signals();
+       const shared_ptr<pv::view::Signal> s = sigs[
+               item->data(UserRole).value<unsigned int>()];
+       assert(s);
+       s->enable(item->checkState() == Checked);
 }
 
 void Probes::enable_all_probes()
index 33f5d996722c42aa72c9567991eb423f74ae8c53..8a1fdd5753efa60a3cb6b89f7eef71efb9b962c4 100644 (file)
@@ -29,6 +29,9 @@
 #include <pv/widgets/popup.h>
 
 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;
 
index dacf65e56b55df4c8266d603928c86c0ce02a6fc..1099ad46704c77b1ba12fb38ad9a1d61cf645ee7 100644 (file)
@@ -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) {
index ae4f298b6f2eae30f744ce4636e344459b87b5c6..24c5a420e1782ce0834b172ecdaa60c0e6782d88 100644 (file)
@@ -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()
index 0c1a0539e4aaefca5e001469322f4d838e9a7769..039e4e41192e781dc4ddeff35503928c84d2b043 100644 (file)
@@ -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<struct sr_dev_inst*> &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;
index 53af2643132ee895c65e5bd8df10e4bc655a3061..4304fd1e5a9bfd7ec61fcf3e3a9c24594086fed0 100644 (file)
@@ -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::Analog> data) :
        Signal(session, probe),
        _data(data),
index 35db2ddc83f52055a11612fe3234c0f596543de7..64d138d84a19f0a13948c1fded2c4d125a98e4cf 100644 (file)
@@ -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<pv::data::Analog> data);
 
        virtual ~AnalogSignal();
index ba16247a8c8e5609245bc8233943295ff068b32b..77a887f9fe4c9b6b232fa78aaf31cd11b3b5ecd3 100644 (file)
@@ -240,6 +240,8 @@ void Header::on_signals_changed()
        const vector< shared_ptr<Trace> > traces(_view.get_traces());
        BOOST_FOREACH(shared_ptr<Trace> 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()),
index b0fe95135eb782e9231d98d63dadf398a9cb6fda..a9484817eb839da2e98f76b3985d8debce174951 100644 (file)
@@ -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::Logic> data) :
        Signal(session, probe),
        _data(data),
index 4dbd5e8389fe346d781e69c02317d4699766e217..92d4cb0f704777589cb1681f4bde61b9518fcd50 100644 (file)
@@ -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<pv::data::Logic> data);
 
        virtual ~LogicSignal();
index dadba05aec0ed607927142edeab0e7fac1ec7adc..aee214168aed2261b302dea197adcd0a7f65674a 100644 (file)
@@ -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;
index 01f057fec47c2fbcf80575ccd622e35348dca304..86d2f38007a5b14455c95caca358aec759f89c12 100644 (file)
@@ -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;
index 05adf6cf58b1b579d9b5e969bef33bb1175c8e21..ca4040d2aae5cee6d79a5f9b590b5dc54727e12b 100644 (file)
@@ -184,6 +184,7 @@ private slots:
        void on_colour_changed(const QColor &colour);
 
 signals:
+       void visibility_changed();
        void text_changed();    
        void colour_changed();
 
index 8cf97ff58020594b2e6c82290589a70112b260e0..a06c8888761f6c1237ffde3c5aecc8ceb2ff5df1 100644 (file)
@@ -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<Trace> > traces(_view.get_traces());
+       BOOST_FOREACH(shared_ptr<Trace> t, traces) {
+               assert(t);
+               connect(t.get(), SIGNAL(visibility_changed()),
+                       this, SLOT(update()));
+       }
+}
+
 void Viewport::on_signals_moved()
 {
        update();
index c15ef0a4d07ce30b894d49d0d1611be64eaa8872..4add1ccfbd4c1d1bb614993d84cf1f9270004ef9 100644 (file)
@@ -51,6 +51,7 @@ private:
        void wheelEvent(QWheelEvent *event);
 
 private slots:
+       void on_signals_changed();
        void on_signals_moved();
 
 private: