]>
Commit | Line | Data |
---|---|---|
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 |
25 | namespace pv { |
26 | namespace dialogs { | |
27 | ||
d755562a | 28 | DeviceOptions::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), | |
ed773982 JH |
34 | _probes_bar(this), |
35 | _enable_all_probes(this), | |
36 | _disable_all_probes(this), | |
0740907f | 37 | _props_box(tr("Configuration"), this), |
497a5b8b JH |
38 | _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, |
39 | Qt::Horizontal, this), | |
3820592a | 40 | _device_options_binding(sdi) |
cdb50f67 | 41 | { |
9c025ef3 JH |
42 | setWindowTitle(tr("Configure Device")); |
43 | ||
ed773982 JH |
44 | connect(&_enable_all_probes, SIGNAL(clicked()), |
45 | this, SLOT(enable_all_probes())); | |
46 | connect(&_disable_all_probes, SIGNAL(clicked()), | |
47 | this, SLOT(disable_all_probes())); | |
48 | ||
497a5b8b JH |
49 | connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); |
50 | connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); | |
51 | ||
52 | setLayout(&_layout); | |
53 | ||
0740907f JH |
54 | setup_probes(); |
55 | _probes_box.setLayout(&_probes_box_layout); | |
56 | _probes_box_layout.addWidget(&_probes); | |
ed773982 JH |
57 | |
58 | _enable_all_probes.setText(tr("Enable All")); | |
59 | _probes_bar.addWidget(&_enable_all_probes); | |
60 | ||
61 | _disable_all_probes.setText(tr("Disable All")); | |
62 | _probes_bar.addWidget(&_disable_all_probes); | |
63 | ||
64 | _probes_box_layout.addWidget(&_probes_bar); | |
0740907f JH |
65 | _layout.addWidget(&_probes_box); |
66 | ||
ed773982 | 67 | |
0740907f JH |
68 | _props_box.setLayout(&_props_box_layout); |
69 | _props_box_layout.addWidget(_device_options_binding.get_form(this)); | |
70 | _layout.addWidget(&_props_box); | |
497a5b8b JH |
71 | |
72 | _layout.addWidget(&_button_box); | |
cdb50f67 JH |
73 | } |
74 | ||
d755562a | 75 | void DeviceOptions::accept() |
f23cd1e5 | 76 | { |
0740907f JH |
77 | using namespace Qt; |
78 | ||
f23cd1e5 | 79 | QDialog::accept(); |
0740907f JH |
80 | |
81 | // Commit the probes | |
82 | for (int i = 0; i < _probes.count(); i++) { | |
83 | const QListWidgetItem *const item = _probes.item(i); | |
84 | assert(item); | |
85 | sr_probe *const probe = (sr_probe*) | |
86 | item->data(UserRole).value<void*>(); | |
87 | assert(probe); | |
88 | probe->enabled = item->checkState() == Checked; | |
89 | } | |
90 | ||
91 | // Commit the properties | |
3820592a | 92 | _device_options_binding.commit(); |
f23cd1e5 JH |
93 | } |
94 | ||
0740907f JH |
95 | void DeviceOptions::setup_probes() |
96 | { | |
97 | using namespace Qt; | |
98 | ||
99 | for (const GSList *l = _sdi->probes; l; l = l->next) { | |
100 | sr_probe *const probe = (sr_probe*)l->data; | |
101 | assert(probe); | |
102 | QListWidgetItem *const item = new QListWidgetItem( | |
103 | probe->name, &_probes); | |
104 | assert(item); | |
105 | item->setCheckState(probe->enabled ? | |
106 | Checked : Unchecked); | |
107 | item->setData(UserRole, | |
108 | qVariantFromValue((void*)probe)); | |
109 | _probes.addItem(item); | |
110 | } | |
111 | } | |
112 | ||
ed773982 JH |
113 | void DeviceOptions::set_all_probes(bool set) |
114 | { | |
115 | for (int i = 0; i < _probes.count(); i++) { | |
116 | QListWidgetItem *const item = _probes.item(i); | |
117 | assert(item); | |
118 | item->setCheckState(set ? Qt::Checked : Qt::Unchecked); | |
119 | } | |
120 | } | |
121 | ||
122 | void DeviceOptions::enable_all_probes() | |
123 | { | |
124 | set_all_probes(true); | |
125 | } | |
126 | ||
127 | void DeviceOptions::disable_all_probes() | |
128 | { | |
129 | set_all_probes(false); | |
130 | } | |
131 | ||
cdb50f67 JH |
132 | } // namespace dialogs |
133 | } // namespace pv |