From: Joel Holdsworth Date: Sat, 1 Mar 2014 08:51:37 +0000 (+0000) Subject: Moved default device functionality into SigSession X-Git-Tag: pulseview-0.2.0~49 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d873f4d685e16c708a15fcde12fbbec66650511c;p=pulseview.git Moved default device functionality into SigSession --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 57e9c51f..2a74d5b2 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -287,34 +287,19 @@ void MainWindow::session_error( Q_ARG(QString, info_text)); } -void MainWindow::update_device_list( - shared_ptr selected_device) +void MainWindow::update_device_list() { assert(_sampling_bar); + shared_ptr selected_device = _session.get_device(); list< shared_ptr > devices; std::copy(_device_manager.devices().begin(), _device_manager.devices().end(), std::back_inserter(devices)); _sampling_bar->set_device_list(devices); - if (!selected_device && !devices.empty()) { - // Fall back to the first device in the list. - selected_device = devices.front(); - - // Try and find the demo device and select that by default - BOOST_FOREACH (shared_ptr dev_inst, devices) - if (strcmp(dev_inst->dev_inst()->driver->name, - "demo") == 0) { - selected_device = dev_inst; - } - } - - if (selected_device) { - // Setting the selected device in the sampling bar, generates - // an event which updates the selected device in the SigSession. + if (selected_device) _sampling_bar->set_selected_device(selected_device); - } } void MainWindow::load_file(QString file_name) @@ -382,10 +367,10 @@ void MainWindow::on_actionConnect_triggered() // If the user selected a device, select it in the device list. Select the // current device otherwise. - shared_ptr dev_inst = dlg.exec() ? - dlg.get_selected_device() : _session.get_device(); + if (dlg.exec()) + _session.set_device(dlg.get_selected_device()); - update_device_list(dev_inst); + update_device_list(); } void MainWindow::on_actionQuit_triggered() diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 1acaf072..1f9dd528 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -69,14 +69,9 @@ private: void session_error(const QString text, const QString info_text); /** - * Updates the device list in the sampling bar, and updates the - * selection. - * @param selected_device The device to select, or NULL if the - * first device in the device list should be selected. + * Updates the device list in the sampling bar */ - void update_device_list( - boost::shared_ptr selected_device = - boost::shared_ptr()); + void update_device_list(); private slots: void load_file(QString file_name); diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 5cc99982..cbb3192d 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -54,6 +54,7 @@ using boost::function; using boost::lock_guard; using boost::mutex; using boost::shared_ptr; +using std::list; using std::map; using std::set; using std::string; @@ -70,6 +71,8 @@ SigSession::SigSession(DeviceManager &device_manager) : { // TODO: This should not be necessary _session = this; + + set_default_device(); } SigSession::~SigSession() @@ -287,6 +290,28 @@ void SigSession::set_capture_state(capture_state state) capture_state_changed(state); } +void SigSession::set_default_device() +{ + shared_ptr default_device; + const list< shared_ptr > &devices = + _device_manager.devices(); + + if (!devices.empty()) { + // Fall back to the first device in the list. + default_device = devices.front(); + + // Try and find the demo device and select that by default + BOOST_FOREACH (shared_ptr dev, devices) + if (strcmp(dev->dev_inst()->driver->name, + "demo") == 0) { + default_device = dev; + break; + } + } + + set_device(default_device); +} + void SigSession::update_signals(shared_ptr dev_inst) { assert(dev_inst); diff --git a/pv/sigsession.h b/pv/sigsession.h index da72015f..7e61d8df 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -114,6 +114,8 @@ private: void update_signals(boost::shared_ptr dev_inst); + void set_default_device(); + boost::shared_ptr signal_from_probe( const sr_probe *probe) const; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 6970ec39..2b0f04a5 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -120,6 +120,8 @@ View::View(SigSession &session, QWidget *parent) : _viewport->installEventFilter(this); _ruler->installEventFilter(this); _header->installEventFilter(this); + + signals_changed(); } SigSession& View::session()