]> sigrok.org Git - pulseview.git/commitdiff
Moved default device functionality into SigSession
authorJoel Holdsworth <redacted>
Sat, 1 Mar 2014 08:51:37 +0000 (08:51 +0000)
committerJoel Holdsworth <redacted>
Sat, 1 Mar 2014 11:13:44 +0000 (11:13 +0000)
pv/mainwindow.cpp
pv/mainwindow.h
pv/sigsession.cpp
pv/sigsession.h
pv/view/view.cpp

index 57e9c51f8d51b647e8ea6164d61834c1d832d11a..2a74d5b292a40f8ac6ecaf42ba1dbdc791eef7a5 100644 (file)
@@ -287,34 +287,19 @@ void MainWindow::session_error(
                Q_ARG(QString, info_text));
 }
 
-void MainWindow::update_device_list(
-       shared_ptr<pv::device::DevInst> selected_device)
+void MainWindow::update_device_list()
 {
        assert(_sampling_bar);
 
+       shared_ptr<pv::device::DevInst> selected_device = _session.get_device();
        list< shared_ptr<device::DevInst> > 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<pv::device::DevInst> 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<device::DevInst> 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()
index 1acaf07227c7b8bd86a08d20ebda97e824f4115a..1f9dd528af7a22d152adace7342cb827882197da 100644 (file)
@@ -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<pv::device::DevInst> selected_device =
-                       boost::shared_ptr<pv::device::DevInst>());
+       void update_device_list();
 
 private slots:
        void load_file(QString file_name);
index 5cc999829f7bd1748aeb07b2732eed883f5d438c..cbb3192d6d2cffe92b24e97f15037b31d81e8ede 100644 (file)
@@ -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<pv::device::DevInst> default_device;
+       const list< shared_ptr<device::Device> > &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<pv::device::Device> 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<device::DevInst> dev_inst)
 {
        assert(dev_inst);
index da72015fc7935ffe03efbc846eec85368c92eec3..7e61d8dfab705f89c1277278b21a0c522cd53c45 100644 (file)
@@ -114,6 +114,8 @@ private:
 
        void update_signals(boost::shared_ptr<device::DevInst> dev_inst);
 
+       void set_default_device();
+
        boost::shared_ptr<view::Signal> signal_from_probe(
                const sr_probe *probe) const;
 
index 6970ec39adb49945f8dd292567e6ce5b32b03ed7..2b0f04a5952983ec3c4909fed12e112c4a34fc3e 100644 (file)
@@ -120,6 +120,8 @@ View::View(SigSession &session, QWidget *parent) :
        _viewport->installEventFilter(this);
        _ruler->installEventFilter(this);
        _header->installEventFilter(this);
+
+       signals_changed();
 }
 
 SigSession& View::session()