]> sigrok.org Git - pulseview.git/blobdiff - pv/samplingbar.cpp
Added pv::SamplingBar::set_selected_device
[pulseview.git] / pv / samplingbar.cpp
index d3b23c0f21a7586c8acc7cd9d43c3aced74d68f0..040700331f6c5aedae66f1175cf9fa1d699975db 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <assert.h>
 
+#include <boost/foreach.hpp>
+
 #include <libsigrok/libsigrok.h>
 
 #include <QAction>
@@ -104,15 +106,33 @@ SamplingBar::SamplingBar(QWidget *parent) :
        _sample_rate_value_action = addWidget(&_sample_rate_value);
        addWidget(&_run_stop_button);
 
-       update_device_selector();
-
-       update_sample_rate_selector();
        connect(&_sample_rate_list, SIGNAL(currentIndexChanged(int)),
                this, SLOT(on_sample_rate_changed()));
-       connect(&_sample_rate_value, SIGNAL(valueChanged(double)),
+       connect(&_sample_rate_value, SIGNAL(editingFinished()),
                this, SLOT(on_sample_rate_changed()));
 }
 
+void SamplingBar::set_device_list(
+       const std::list<struct sr_dev_inst*> &devices)
+{
+       _device_selector.clear();
+
+       BOOST_FOREACH (sr_dev_inst *sdi, devices) {
+               QString title;
+               if (sdi->vendor && sdi->vendor[0])
+                       title += sdi->vendor + QString(" ");
+               if (sdi->model && sdi->model[0])
+                       title += sdi->model + QString(" ");
+               if (sdi->version && sdi->version[0])
+                       title += sdi->version + QString(" ");
+
+               _device_selector.addItem(title, qVariantFromValue(
+                       (void*)sdi));
+       }
+
+       update_sample_rate_selector();
+}
+
 struct sr_dev_inst* SamplingBar::get_selected_device() const
 {
        const int index = _device_selector.currentIndex();
@@ -123,6 +143,15 @@ struct sr_dev_inst* SamplingBar::get_selected_device() const
                index).value<void*>();
 }
 
+void SamplingBar::set_selected_device(struct sr_dev_inst *const sdi)
+{
+       for(int i = 0; i < _device_selector.count(); i++)
+               if(sdi == _device_selector.itemData(i).value<void*>()) {
+                       _device_selector.setCurrentIndex(i);
+                       return;
+               }
+}
+
 uint64_t SamplingBar::get_record_length() const
 {
        const int index = _record_length_selector.currentIndex();
@@ -138,37 +167,6 @@ void SamplingBar::set_sampling(bool sampling)
        _run_stop_button.setText(sampling ? "Stop" : "Run");
 }
 
-void SamplingBar::update_device_selector()
-{
-       GSList *devices = NULL;
-
-       /* Scan all drivers for all devices. */
-       struct sr_dev_driver **const drivers = sr_driver_list();
-       for (struct sr_dev_driver **driver = drivers; *driver; driver++) {
-               GSList *tmpdevs = sr_driver_scan(*driver, NULL);
-               for (GSList *l = tmpdevs; l; l = l->next)
-                       devices = g_slist_append(devices, l->data);
-               g_slist_free(tmpdevs);
-       }
-
-       for (GSList *l = devices; l; l = l->next) {
-               sr_dev_inst *const sdi = (sr_dev_inst*)l->data;
-
-               QString title;
-               if (sdi->vendor && sdi->vendor[0])
-                       title += sdi->vendor + QString(" ");
-               if (sdi->model && sdi->model[0])
-                       title += sdi->model + QString(" ");
-               if (sdi->version && sdi->version[0])
-                       title += sdi->version + QString(" ");
-
-               _device_selector.addItem(title, qVariantFromValue(
-                       (void*)sdi));
-       }
-
-       g_slist_free(devices);
-}
-
 void SamplingBar::update_sample_rate_selector()
 {
        const sr_dev_inst *const sdi = get_selected_device();