]> sigrok.org Git - pulseview.git/blobdiff - pv/dialogs/deviceoptions.cpp
Moved get_property_form out of pv::prop::binding::Binding
[pulseview.git] / pv / dialogs / deviceoptions.cpp
index 232e6f6f834e90aac50aad4824c150c77597f9d4..39e41b589acfea3b110623cbf7cc310c7ef7ef5c 100644 (file)
 
 #include "deviceoptions.h"
 
+#include <boost/foreach.hpp>
+
+#include <QFormLayout>
 #include <QListWidget>
 
+#include <pv/prop/property.h>
+
+using namespace boost;
+using namespace std;
+
 namespace pv {
 namespace dialogs {
 
@@ -31,6 +39,9 @@ DeviceOptions::DeviceOptions(QWidget *parent, struct sr_dev_inst *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),
@@ -38,6 +49,11 @@ DeviceOptions::DeviceOptions(QWidget *parent, struct sr_dev_inst *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()));
 
@@ -46,10 +62,19 @@ DeviceOptions::DeviceOptions(QWidget *parent, struct sr_dev_inst *sdi) :
        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));
+       _props_box_layout.addWidget(get_property_form());
        _layout.addWidget(&_props_box);
 
        _layout.addWidget(&_button_box);
@@ -72,7 +97,30 @@ void DeviceOptions::accept()
        }
 
        // Commit the properties
-       _device_options_binding.commit();
+       const vector< shared_ptr<pv::prop::Property> > &properties =
+               _device_options_binding.properties();
+       BOOST_FOREACH(shared_ptr<pv::prop::Property> p, properties) {
+               assert(p);
+               p->commit();
+       }
+}
+
+QWidget* DeviceOptions::get_property_form()
+{
+       QWidget *const form = new QWidget(this);
+       QFormLayout *const layout = new QFormLayout(form);
+       form->setLayout(layout);
+
+       const vector< shared_ptr<pv::prop::Property> > &properties =
+               _device_options_binding.properties();
+       BOOST_FOREACH(shared_ptr<pv::prop::Property> p, properties)
+       {
+               assert(p);
+               const QString label = p->labeled_widget() ? QString() : p->name();
+               layout->addRow(label, p->get_widget(form));
+       }
+
+       return form;
 }
 
 void DeviceOptions::setup_probes()
@@ -93,5 +141,24 @@ void DeviceOptions::setup_probes()
        }
 }
 
+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