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