From: Joel Holdsworth Date: Thu, 7 Mar 2013 23:18:46 +0000 (+0000) Subject: Process selected device X-Git-Tag: pulseview-0.1.0~96 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5eb0fa13029207c45748ff572568542782e6d2a8;p=pulseview.git Process selected device --- diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp index f7a75da0..87fc451a 100644 --- a/pv/dialogs/connect.cpp +++ b/pv/dialogs/connect.cpp @@ -70,6 +70,15 @@ Connect::Connect(QWidget *parent) : _layout.addWidget(&_button_box); } +struct sr_dev_inst* Connect::get_selected_device() const +{ + const QListWidgetItem *const item = _device_list.currentItem(); + if (!item) + return NULL; + + return (sr_dev_inst*)item->data(Qt::UserRole).value(); +} + void Connect::populate_drivers() { const int *hwopts; @@ -150,7 +159,10 @@ void Connect::scan_pressed() g_slist_length(sdi->probes)); } - _device_list.addItem(text); + QListWidgetItem *const item = new QListWidgetItem(text, + &_device_list); + item->setData(Qt::UserRole, qVariantFromValue((void*)sdi)); + _device_list.addItem(item); } g_slist_free(devices); diff --git a/pv/dialogs/connect.h b/pv/dialogs/connect.h index 862184b8..eeb108c1 100644 --- a/pv/dialogs/connect.h +++ b/pv/dialogs/connect.h @@ -31,6 +31,7 @@ #include struct sr_config; +struct sr_dev_inst; namespace pv { namespace dialogs { @@ -42,6 +43,8 @@ class Connect : public QDialog public: Connect(QWidget *parent); + struct sr_dev_inst* get_selected_device() const; + private: void populate_drivers(); diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index c9fa4c1a..03562b8f 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -226,7 +226,17 @@ void MainWindow::on_actionOpen_triggered() void MainWindow::on_actionConnect_triggered() { dialogs::Connect dlg(this); - dlg.exec(); + if(!dlg.exec()) + return; + + struct sr_dev_inst *const sdi = dlg.get_selected_device(); + if (sdi) { + assert(_sampling_bar); + + _devices.push_back(sdi); + _sampling_bar->set_device_list(_devices); + _sampling_bar->set_selected_device(sdi); + } } void MainWindow::on_actionQuit_triggered()