]> sigrok.org Git - pulseview.git/commitdiff
Update the SigSession device, when it is selected by the user
authorJoel Holdsworth <redacted>
Wed, 24 Apr 2013 19:09:15 +0000 (20:09 +0100)
committerJoel Holdsworth <redacted>
Wed, 24 Apr 2013 19:18:47 +0000 (20:18 +0100)
pv/mainwindow.cpp
pv/mainwindow.h
pv/sigsession.cpp
pv/sigsession.h
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h

index f95cd45123eb1345f56a65160ed7b6268d3b7d18..bd2f5fea99a112fcfa94e848b39cbe5e12d5a73a 100644 (file)
@@ -177,7 +177,7 @@ void MainWindow::setup_ui()
        setMenuBar(_menu_bar);
        QMetaObject::connectSlotsByName(this);
 
-       // Setup the toolbars
+       // Setup the toolbar
        _toolbar = new QToolBar(this);
        _toolbar->addAction(_action_open);
        _toolbar->addSeparator();
@@ -185,12 +185,24 @@ void MainWindow::setup_ui()
        _toolbar->addAction(_action_view_zoom_out);
        addToolBar(_toolbar);
 
+       // Setup the sampling bar
        _sampling_bar = new toolbars::SamplingBar(this);
+
+       // Populate the device list and select the initially selected device
        scan_devices();
+       if(!_devices.empty()) {
+               struct sr_dev_inst *const initial_sdi = _devices.front();
+               _sampling_bar->set_selected_device(initial_sdi);
+               _session.set_device(initial_sdi);
+       }
+
+       connect(_sampling_bar, SIGNAL(device_selected()), this,
+               SLOT(device_selected()));
        connect(_sampling_bar, SIGNAL(run_stop()), this,
                SLOT(run_stop()));
        addToolBar(_sampling_bar);
 
+       // Set the title
        setWindowTitle(QApplication::translate("MainWindow", "PulseView", 0,
                QApplication::UnicodeUTF8));
 
@@ -268,6 +280,8 @@ void MainWindow::on_actionConnect_triggered()
                _devices.push_back(sdi);
                _sampling_bar->set_device_list(_devices);
                _sampling_bar->set_selected_device(sdi);
+
+               _session.set_device(sdi);
        }
 }
 
@@ -303,11 +317,15 @@ void MainWindow::on_actionAbout_triggered()
        dlg.exec();
 }
 
+void MainWindow::device_selected()
+{
+       _session.set_device(_sampling_bar->get_selected_device());
+}
+
 void MainWindow::run_stop()
 {
        switch(_session.get_capture_state()) {
        case SigSession::Stopped:
-               _session.set_device(_sampling_bar->get_selected_device());
                _session.start_capture(_sampling_bar->get_record_length(),
                        boost::bind(&MainWindow::session_error, this,
                                QString("Capture failed"), _1));
index 47d3e66d0cad0efa131b7a72b4d796026966eb34..8129020348109ec6c395672f27bfa98995f9f9c3 100644 (file)
@@ -79,6 +79,8 @@ private slots:
 
        void on_actionAbout_triggered();
 
+       void device_selected();
+
        void run_stop();
 
        void capture_state_changed(int state);
index 131f057de5d881e72d442418dff4952ebef74a27..354082c7262c351a3fe09423761823e7beab302d 100644 (file)
@@ -59,11 +59,6 @@ SigSession::~SigSession()
        _session = NULL;
 }
 
-struct sr_dev_inst* SigSession::get_device() const
-{
-       return _sdi;
-}
-
 void SigSession::set_device(struct sr_dev_inst *sdi)
 {
        _sdi = sdi;
index fa2c7af413db55b174ad78ffa85593f409e69975..1978293481423b0dbae4645c6f57d38e98ceb2e1 100644 (file)
@@ -62,11 +62,6 @@ public:
 
        ~SigSession();
 
-       /**
-        * Gets device instance that will be used in the next capture session.
-        */
-       struct sr_dev_inst* get_device() const;
-
        /**
         * Sets device instance that will be used in the next capture session.
         */
index 401652cbe7b251eba52fe6bcd998cd2a98dd80d4..7e052f81cf6c16e77d91307fc956097fff410711 100644 (file)
@@ -283,6 +283,7 @@ void SamplingBar::commit_sample_rate()
 void SamplingBar::on_device_selected()
 {
        update_sample_rate_selector();
+       device_selected();
 }
 
 void SamplingBar::on_sample_rate_changed()
index a61a949eabc0ef8538d9c2ac0fa5343f81cfccf7..d24534bef185867883ec9657b5360011b1bafebb 100644 (file)
@@ -57,6 +57,8 @@ public:
        void set_sampling(bool sampling);
 
 signals:
+       void device_selected();
+
        void run_stop();
 
 private: