]> sigrok.org Git - pulseview.git/blame - pv/dialogs/deviceoptions.cpp
INSTALL: Refer to new Building wiki page.
[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
0740907f
JH
23#include <QListWidget>
24
cdb50f67
JH
25namespace pv {
26namespace dialogs {
27
d755562a 28DeviceOptions::DeviceOptions(QWidget *parent, struct sr_dev_inst *sdi) :
cdb50f67 29 QDialog(parent),
0740907f 30 _sdi(sdi),
497a5b8b 31 _layout(this),
0740907f
JH
32 _probes_box(tr("Probes"), this),
33 _probes(this),
34 _props_box(tr("Configuration"), this),
497a5b8b
JH
35 _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
36 Qt::Horizontal, this),
3820592a 37 _device_options_binding(sdi)
cdb50f67 38{
9c025ef3
JH
39 setWindowTitle(tr("Configure Device"));
40
497a5b8b
JH
41 connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept()));
42 connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject()));
43
44 setLayout(&_layout);
45
0740907f
JH
46 setup_probes();
47 _probes_box.setLayout(&_probes_box_layout);
48 _probes_box_layout.addWidget(&_probes);
49 _layout.addWidget(&_probes_box);
50
51 _props_box.setLayout(&_props_box_layout);
52 _props_box_layout.addWidget(_device_options_binding.get_form(this));
53 _layout.addWidget(&_props_box);
497a5b8b
JH
54
55 _layout.addWidget(&_button_box);
cdb50f67
JH
56}
57
d755562a 58void DeviceOptions::accept()
f23cd1e5 59{
0740907f
JH
60 using namespace Qt;
61
f23cd1e5 62 QDialog::accept();
0740907f
JH
63
64 // Commit the probes
65 for (int i = 0; i < _probes.count(); i++) {
66 const QListWidgetItem *const item = _probes.item(i);
67 assert(item);
68 sr_probe *const probe = (sr_probe*)
69 item->data(UserRole).value<void*>();
70 assert(probe);
71 probe->enabled = item->checkState() == Checked;
72 }
73
74 // Commit the properties
3820592a 75 _device_options_binding.commit();
f23cd1e5
JH
76}
77
0740907f
JH
78void DeviceOptions::setup_probes()
79{
80 using namespace Qt;
81
82 for (const GSList *l = _sdi->probes; l; l = l->next) {
83 sr_probe *const probe = (sr_probe*)l->data;
84 assert(probe);
85 QListWidgetItem *const item = new QListWidgetItem(
86 probe->name, &_probes);
87 assert(item);
88 item->setCheckState(probe->enabled ?
89 Checked : Unchecked);
90 item->setData(UserRole,
91 qVariantFromValue((void*)probe));
92 _probes.addItem(item);
93 }
94}
95
cdb50f67
JH
96} // namespace dialogs
97} // namespace pv