X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fdialogs%2Fdeviceoptions.cpp;h=e6b2f847d12969f15d78ffa01cbd89e0a8ef337b;hb=8eb9d311acb7ca084b588ff20a40b145f7a8b0d5;hp=b8f4cabf2542af7175ac6819bdac77a86fe80488;hpb=d755562ad376fc95184ff996ff8f1391c5f32b6b;p=pulseview.git diff --git a/pv/dialogs/deviceoptions.cpp b/pv/dialogs/deviceoptions.cpp index b8f4cabf..e6b2f847 100644 --- a/pv/dialogs/deviceoptions.cpp +++ b/pv/dialogs/deviceoptions.cpp @@ -20,34 +20,114 @@ #include "deviceoptions.h" +#include + namespace pv { namespace dialogs { DeviceOptions::DeviceOptions(QWidget *parent, struct sr_dev_inst *sdi) : QDialog(parent), + _sdi(sdi), _layout(this), + _probes_box(tr("Probes"), this), + _probes(this), + _probes_bar(this), + _enable_all_probes(this), + _disable_all_probes(this), + _props_box(tr("Configuration"), this), _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this), _device_options_binding(sdi) { setWindowTitle(tr("Configure Device")); + connect(&_enable_all_probes, SIGNAL(clicked()), + this, SLOT(enable_all_probes())); + connect(&_disable_all_probes, SIGNAL(clicked()), + this, SLOT(disable_all_probes())); + connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); setLayout(&_layout); - QWidget *const form = _device_options_binding.get_form(this); - _layout.addWidget(form); + setup_probes(); + _probes_box.setLayout(&_probes_box_layout); + _probes_box_layout.addWidget(&_probes); + + _enable_all_probes.setText(tr("Enable All")); + _probes_bar.addWidget(&_enable_all_probes); + + _disable_all_probes.setText(tr("Disable All")); + _probes_bar.addWidget(&_disable_all_probes); + + _probes_box_layout.addWidget(&_probes_bar); + _layout.addWidget(&_probes_box); + + + _props_box.setLayout(&_props_box_layout); + _props_box_layout.addWidget(_device_options_binding.get_form(this)); + _layout.addWidget(&_props_box); _layout.addWidget(&_button_box); } void DeviceOptions::accept() { + using namespace Qt; + QDialog::accept(); + + // Commit the probes + for (int i = 0; i < _probes.count(); i++) { + const QListWidgetItem *const item = _probes.item(i); + assert(item); + sr_probe *const probe = (sr_probe*) + item->data(UserRole).value(); + assert(probe); + probe->enabled = item->checkState() == Checked; + } + + // Commit the properties _device_options_binding.commit(); } +void DeviceOptions::setup_probes() +{ + using namespace Qt; + + for (const GSList *l = _sdi->probes; l; l = l->next) { + sr_probe *const probe = (sr_probe*)l->data; + assert(probe); + QListWidgetItem *const item = new QListWidgetItem( + probe->name, &_probes); + assert(item); + item->setCheckState(probe->enabled ? + Checked : Unchecked); + item->setData(UserRole, + qVariantFromValue((void*)probe)); + _probes.addItem(item); + } +} + +void DeviceOptions::set_all_probes(bool set) +{ + for (int i = 0; i < _probes.count(); i++) { + QListWidgetItem *const item = _probes.item(i); + assert(item); + item->setCheckState(set ? Qt::Checked : Qt::Unchecked); + } +} + +void DeviceOptions::enable_all_probes() +{ + set_all_probes(true); +} + +void DeviceOptions::disable_all_probes() +{ + set_all_probes(false); +} + } // namespace dialogs } // namespace pv