]>
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 | ||
488f068c JH |
21 | #include <map> |
22 | ||
bfc9f61e | 23 | #include <QCheckBox> |
488f068c JH |
24 | #include <QFormLayout> |
25 | #include <QGridLayout> | |
bfc9f61e | 26 | #include <QLabel> |
488f068c | 27 | |
51d4a9ab | 28 | #include "probes.h" |
cdb50f67 | 29 | |
94574501 | 30 | #include <pv/device/devinst.h> |
488f068c | 31 | #include <pv/prop/binding/deviceoptions.h> |
aca00b1e JH |
32 | #include <pv/sigsession.h> |
33 | #include <pv/view/signal.h> | |
34 | ||
51d4a9ab | 35 | using namespace Qt; |
488f068c | 36 | |
488f068c JH |
37 | using std::map; |
38 | using std::set; | |
f9abf97e | 39 | using std::shared_ptr; |
819f4c25 | 40 | using std::vector; |
479bcabe | 41 | |
488f068c JH |
42 | using pv::view::Signal; |
43 | ||
cdb50f67 | 44 | namespace pv { |
51d4a9ab | 45 | namespace popups { |
cdb50f67 | 46 | |
aca00b1e | 47 | Probes::Probes(SigSession &session, QWidget *parent) : |
51d4a9ab | 48 | Popup(parent), |
aca00b1e | 49 | _session(session), |
b7b659aa | 50 | _updating_probes(false), |
65cbcf46 JH |
51 | _enable_all_probes(tr("Enable All"), this), |
52 | _disable_all_probes(tr("Disable All"), this), | |
488f068c | 53 | _check_box_mapper(this) |
cdb50f67 | 54 | { |
488f068c | 55 | // Create the layout |
51d4a9ab | 56 | setLayout(&_layout); |
9c025ef3 | 57 | |
94574501 | 58 | shared_ptr<device::DevInst> dev_inst = _session.get_device(); |
19adbc2c JH |
59 | assert(dev_inst); |
60 | const sr_dev_inst *const sdi = dev_inst->dev_inst(); | |
488f068c JH |
61 | assert(sdi); |
62 | ||
63 | // Collect a set of signals | |
4871ed92 | 64 | map<const sr_channel*, shared_ptr<Signal> > signal_map; |
488f068c | 65 | const vector< shared_ptr<Signal> > sigs = _session.get_signals(); |
d9aecf1f | 66 | for (const shared_ptr<Signal> &sig : sigs) |
488f068c JH |
67 | signal_map[sig->probe()] = sig; |
68 | ||
2445160a UH |
69 | // Populate channel groups |
70 | for (const GSList *g = sdi->channel_groups; g; g = g->next) | |
488f068c | 71 | { |
2445160a UH |
72 | const sr_channel_group *const group = |
73 | (const sr_channel_group*)g->data; | |
488f068c JH |
74 | assert(group); |
75 | ||
76 | // Make a set of signals, and removed this signals from the | |
77 | // signal map. | |
78 | vector< shared_ptr<Signal> > group_sigs; | |
4871ed92 | 79 | for (const GSList *p = group->channels; p; p = p->next) |
488f068c | 80 | { |
4871ed92 | 81 | const sr_channel *const probe = (const sr_channel*)p->data; |
488f068c JH |
82 | assert(probe); |
83 | ||
f46e495e | 84 | const auto iter = signal_map.find(probe); |
488f068c JH |
85 | assert(iter != signal_map.end()); |
86 | ||
87 | group_sigs.push_back((*iter).second); | |
88 | signal_map.erase(iter); | |
89 | } | |
90 | ||
91 | populate_group(group, group_sigs); | |
92 | } | |
93 | ||
94 | // Make a vector of the remaining probes | |
95 | vector< shared_ptr<Signal> > global_sigs; | |
4871ed92 | 96 | for (const GSList *p = sdi->channels; p; p = p->next) |
488f068c | 97 | { |
4871ed92 | 98 | const sr_channel *const probe = (const sr_channel*)p->data; |
488f068c JH |
99 | assert(probe); |
100 | ||
4871ed92 | 101 | const map<const sr_channel*, shared_ptr<Signal> >:: |
488f068c JH |
102 | const_iterator iter = signal_map.find(probe); |
103 | if (iter != signal_map.end()) | |
104 | global_sigs.push_back((*iter).second); | |
105 | } | |
106 | ||
107 | // Create a group | |
108 | populate_group(NULL, global_sigs); | |
109 | ||
110 | // Create the enable/disable all buttons | |
ed773982 JH |
111 | connect(&_enable_all_probes, SIGNAL(clicked()), |
112 | this, SLOT(enable_all_probes())); | |
113 | connect(&_disable_all_probes, SIGNAL(clicked()), | |
114 | this, SLOT(disable_all_probes())); | |
115 | ||
65cbcf46 JH |
116 | _enable_all_probes.setFlat(true); |
117 | _disable_all_probes.setFlat(true); | |
ed773982 | 118 | |
65cbcf46 JH |
119 | _buttons_bar.addWidget(&_enable_all_probes); |
120 | _buttons_bar.addWidget(&_disable_all_probes); | |
121 | _buttons_bar.addStretch(1); | |
ed773982 | 122 | |
65cbcf46 | 123 | _layout.addRow(&_buttons_bar); |
0740907f | 124 | |
488f068c JH |
125 | // Connect the check-box signal mapper |
126 | connect(&_check_box_mapper, SIGNAL(mapped(QWidget*)), | |
127 | this, SLOT(on_probe_checked(QWidget*))); | |
b7b659aa JH |
128 | } |
129 | ||
130 | void Probes::set_all_probes(bool set) | |
131 | { | |
b7b659aa JH |
132 | _updating_probes = true; |
133 | ||
488f068c JH |
134 | for (map<QCheckBox*, shared_ptr<Signal> >::const_iterator i = |
135 | _check_box_signal_map.begin(); | |
136 | i != _check_box_signal_map.end(); i++) | |
aca00b1e | 137 | { |
488f068c JH |
138 | const shared_ptr<Signal> sig = (*i).second; |
139 | assert(sig); | |
b7b659aa | 140 | |
488f068c JH |
141 | sig->enable(set); |
142 | (*i).first->setChecked(set); | |
0740907f | 143 | } |
51d4a9ab | 144 | |
b7b659aa | 145 | _updating_probes = false; |
0740907f JH |
146 | } |
147 | ||
2445160a | 148 | void Probes::populate_group(const sr_channel_group *group, |
488f068c JH |
149 | const vector< shared_ptr<pv::view::Signal> > sigs) |
150 | { | |
151 | using pv::prop::binding::DeviceOptions; | |
152 | ||
153 | // Only bind options if this is a group. We don't do it for general | |
154 | // options, because these properties are shown in the device config | |
155 | // popup. | |
156 | shared_ptr<DeviceOptions> binding; | |
157 | if (group) | |
158 | binding = shared_ptr<DeviceOptions>(new DeviceOptions( | |
159 | _session.get_device(), group)); | |
160 | ||
161 | // Create a title if the group is going to have any content | |
162 | if ((!sigs.empty() || (binding && !binding->properties().empty())) && | |
163 | group && group->name) | |
164 | _layout.addRow(new QLabel( | |
165 | QString("<h3>%1</h3>").arg(group->name))); | |
166 | ||
2445160a | 167 | // Create the channel group grid |
488f068c | 168 | QGridLayout *const probe_grid = |
2445160a | 169 | create_channel_group_grid(sigs); |
488f068c JH |
170 | _layout.addRow(probe_grid); |
171 | ||
2445160a | 172 | // Create the channel group options |
488f068c JH |
173 | if (binding) |
174 | { | |
175 | binding->add_properties_to_form(&_layout, true); | |
176 | _group_bindings.push_back(binding); | |
177 | } | |
178 | } | |
179 | ||
2445160a | 180 | QGridLayout* Probes::create_channel_group_grid( |
488f068c JH |
181 | const vector< shared_ptr<pv::view::Signal> > sigs) |
182 | { | |
183 | int row = 0, col = 0; | |
184 | QGridLayout *const grid = new QGridLayout(); | |
185 | ||
d9aecf1f | 186 | for (const shared_ptr<pv::view::Signal>& sig : sigs) |
488f068c JH |
187 | { |
188 | assert(sig); | |
189 | ||
190 | QCheckBox *const checkbox = new QCheckBox(sig->get_name()); | |
191 | _check_box_mapper.setMapping(checkbox, checkbox); | |
192 | connect(checkbox, SIGNAL(toggled(bool)), | |
193 | &_check_box_mapper, SLOT(map())); | |
194 | ||
195 | grid->addWidget(checkbox, row, col); | |
196 | ||
197 | _check_box_signal_map[checkbox] = sig; | |
198 | ||
199 | if(++col >= 8) | |
200 | col = 0, row++; | |
201 | } | |
202 | ||
203 | return grid; | |
204 | } | |
205 | ||
b7b659aa | 206 | void Probes::showEvent(QShowEvent *e) |
ed773982 | 207 | { |
b7b659aa JH |
208 | pv::widgets::Popup::showEvent(e); |
209 | ||
210 | _updating_probes = true; | |
211 | ||
488f068c JH |
212 | for (map<QCheckBox*, shared_ptr<Signal> >::const_iterator i = |
213 | _check_box_signal_map.begin(); | |
214 | i != _check_box_signal_map.end(); i++) | |
aca00b1e | 215 | { |
488f068c JH |
216 | const shared_ptr<Signal> sig = (*i).second; |
217 | assert(sig); | |
218 | ||
219 | (*i).first->setChecked(sig->enabled()); | |
ed773982 | 220 | } |
b7b659aa JH |
221 | |
222 | _updating_probes = false; | |
ed773982 JH |
223 | } |
224 | ||
488f068c | 225 | void Probes::on_probe_checked(QWidget *widget) |
51d4a9ab | 226 | { |
b7b659aa JH |
227 | if (_updating_probes) |
228 | return; | |
229 | ||
488f068c JH |
230 | QCheckBox *const check_box = (QCheckBox*)widget; |
231 | assert(check_box); | |
232 | ||
233 | // Look up the signal of this check-box | |
234 | map< QCheckBox*, shared_ptr<Signal> >::const_iterator iter = | |
235 | _check_box_signal_map.find((QCheckBox*)check_box); | |
236 | assert(iter != _check_box_signal_map.end()); | |
237 | ||
238 | const shared_ptr<pv::view::Signal> s = (*iter).second; | |
aca00b1e | 239 | assert(s); |
488f068c JH |
240 | |
241 | s->enable(check_box->isChecked()); | |
51d4a9ab JH |
242 | } |
243 | ||
244 | void Probes::enable_all_probes() | |
ed773982 JH |
245 | { |
246 | set_all_probes(true); | |
247 | } | |
248 | ||
51d4a9ab | 249 | void Probes::disable_all_probes() |
ed773982 JH |
250 | { |
251 | set_all_probes(false); | |
252 | } | |
253 | ||
51d4a9ab JH |
254 | } // popups |
255 | } // pv |