]> sigrok.org Git - pulseview.git/blame - pv/dialogs/deviceoptions.cpp
Made UNIX signals an optional feature
[pulseview.git] / pv / dialogs / deviceoptions.cpp
CommitLineData
cdb50f67
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
d755562a 21#include "deviceoptions.h"
cdb50f67 22
479bcabe
JH
23#include <boost/foreach.hpp>
24
25#include <QFormLayout>
0740907f
JH
26#include <QListWidget>
27
479bcabe
JH
28#include <pv/prop/property.h>
29
30using namespace boost;
31using namespace std;
32
cdb50f67
JH
33namespace pv {
34namespace dialogs {
35
d755562a 36DeviceOptions::DeviceOptions(QWidget *parent, struct sr_dev_inst *sdi) :
cdb50f67 37 QDialog(parent),
0740907f 38 _sdi(sdi),
497a5b8b 39 _layout(this),
0740907f
JH
40 _probes_box(tr("Probes"), this),
41 _probes(this),
ed773982
JH
42 _probes_bar(this),
43 _enable_all_probes(this),
44 _disable_all_probes(this),
0740907f 45 _props_box(tr("Configuration"), this),
497a5b8b
JH
46 _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
47 Qt::Horizontal, this),
3820592a 48 _device_options_binding(sdi)
cdb50f67 49{
9c025ef3
JH
50 setWindowTitle(tr("Configure Device"));
51
ed773982
JH
52 connect(&_enable_all_probes, SIGNAL(clicked()),
53 this, SLOT(enable_all_probes()));
54 connect(&_disable_all_probes, SIGNAL(clicked()),
55 this, SLOT(disable_all_probes()));
56
497a5b8b
JH
57 connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
58 connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
59
60 setLayout(&_layout);
61
0740907f
JH
62 setup_probes();
63 _probes_box.setLayout(&_probes_box_layout);
64 _probes_box_layout.addWidget(&_probes);
ed773982
JH
65
66 _enable_all_probes.setText(tr("Enable All"));
67 _probes_bar.addWidget(&_enable_all_probes);
68
69 _disable_all_probes.setText(tr("Disable All"));
70 _probes_bar.addWidget(&_disable_all_probes);
71
72 _probes_box_layout.addWidget(&_probes_bar);
0740907f
JH
73 _layout.addWidget(&_probes_box);
74
ed773982 75
0740907f 76 _props_box.setLayout(&_props_box_layout);
479bcabe 77 _props_box_layout.addWidget(get_property_form());
0740907f 78 _layout.addWidget(&_props_box);
497a5b8b
JH
79
80 _layout.addWidget(&_button_box);
cdb50f67
JH
81}
82
d755562a 83void DeviceOptions::accept()
f23cd1e5 84{
0740907f
JH
85 using namespace Qt;
86
f23cd1e5 87 QDialog::accept();
0740907f
JH
88
89 // Commit the probes
90 for (int i = 0; i < _probes.count(); i++) {
91 const QListWidgetItem *const item = _probes.item(i);
92 assert(item);
93 sr_probe *const probe = (sr_probe*)
94 item->data(UserRole).value<void*>();
95 assert(probe);
96 probe->enabled = item->checkState() == Checked;
97 }
98
99 // Commit the properties
479bcabe
JH
100 const vector< shared_ptr<pv::prop::Property> > &properties =
101 _device_options_binding.properties();
102 BOOST_FOREACH(shared_ptr<pv::prop::Property> p, properties) {
103 assert(p);
104 p->commit();
105 }
106}
107
108QWidget* DeviceOptions::get_property_form()
109{
110 QWidget *const form = new QWidget(this);
111 QFormLayout *const layout = new QFormLayout(form);
112 form->setLayout(layout);
113
114 const vector< shared_ptr<pv::prop::Property> > &properties =
115 _device_options_binding.properties();
116 BOOST_FOREACH(shared_ptr<pv::prop::Property> p, properties)
117 {
118 assert(p);
119 const QString label = p->labeled_widget() ? QString() : p->name();
120 layout->addRow(label, p->get_widget(form));
121 }
122
123 return form;
f23cd1e5
JH
124}
125
0740907f
JH
126void DeviceOptions::setup_probes()
127{
128 using namespace Qt;
129
130 for (const GSList *l = _sdi->probes; l; l = l->next) {
131 sr_probe *const probe = (sr_probe*)l->data;
132 assert(probe);
133 QListWidgetItem *const item = new QListWidgetItem(
134 probe->name, &_probes);
135 assert(item);
136 item->setCheckState(probe->enabled ?
137 Checked : Unchecked);
138 item->setData(UserRole,
139 qVariantFromValue((void*)probe));
140 _probes.addItem(item);
141 }
142}
143
ed773982
JH
144void DeviceOptions::set_all_probes(bool set)
145{
146 for (int i = 0; i < _probes.count(); i++) {
147 QListWidgetItem *const item = _probes.item(i);
148 assert(item);
149 item->setCheckState(set ? Qt::Checked : Qt::Unchecked);
150 }
151}
152
153void DeviceOptions::enable_all_probes()
154{
155 set_all_probes(true);
156}
157
158void DeviceOptions::disable_all_probes()
159{
160 set_all_probes(false);
161}
162
cdb50f67
JH
163} // namespace dialogs
164} // namespace pv