]>
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 | ||
51d4a9ab | 21 | #include "probes.h" |
cdb50f67 | 22 | |
51d4a9ab | 23 | using namespace Qt; |
479bcabe | 24 | |
cdb50f67 | 25 | namespace pv { |
51d4a9ab | 26 | namespace popups { |
cdb50f67 | 27 | |
51d4a9ab JH |
28 | Probes::Probes(sr_dev_inst *sdi, QWidget *parent) : |
29 | Popup(parent), | |
0740907f | 30 | _sdi(sdi), |
497a5b8b | 31 | _layout(this), |
0740907f | 32 | _probes(this), |
ed773982 JH |
33 | _probes_bar(this), |
34 | _enable_all_probes(this), | |
51d4a9ab | 35 | _disable_all_probes(this) |
cdb50f67 | 36 | { |
51d4a9ab JH |
37 | assert(_sdi); |
38 | ||
39 | setLayout(&_layout); | |
9c025ef3 | 40 | |
ed773982 JH |
41 | connect(&_enable_all_probes, SIGNAL(clicked()), |
42 | this, SLOT(enable_all_probes())); | |
43 | connect(&_disable_all_probes, SIGNAL(clicked()), | |
44 | this, SLOT(disable_all_probes())); | |
45 | ||
51d4a9ab | 46 | _layout.addWidget(&_probes); |
ed773982 JH |
47 | |
48 | _enable_all_probes.setText(tr("Enable All")); | |
49 | _probes_bar.addWidget(&_enable_all_probes); | |
50 | ||
51 | _disable_all_probes.setText(tr("Disable All")); | |
52 | _probes_bar.addWidget(&_disable_all_probes); | |
53 | ||
51d4a9ab | 54 | _layout.addWidget(&_probes_bar); |
0740907f JH |
55 | |
56 | for (const GSList *l = _sdi->probes; l; l = l->next) { | |
57 | sr_probe *const probe = (sr_probe*)l->data; | |
58 | assert(probe); | |
59 | QListWidgetItem *const item = new QListWidgetItem( | |
60 | probe->name, &_probes); | |
61 | assert(item); | |
0740907f JH |
62 | item->setData(UserRole, |
63 | qVariantFromValue((void*)probe)); | |
51d4a9ab JH |
64 | item->setCheckState(probe->enabled ? |
65 | Checked : Unchecked); | |
0740907f JH |
66 | _probes.addItem(item); |
67 | } | |
51d4a9ab JH |
68 | |
69 | connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)), | |
70 | this, SLOT(item_changed(QListWidgetItem*))); | |
0740907f JH |
71 | } |
72 | ||
51d4a9ab | 73 | void Probes::set_all_probes(bool set) |
ed773982 JH |
74 | { |
75 | for (int i = 0; i < _probes.count(); i++) { | |
76 | QListWidgetItem *const item = _probes.item(i); | |
77 | assert(item); | |
78 | item->setCheckState(set ? Qt::Checked : Qt::Unchecked); | |
51d4a9ab JH |
79 | |
80 | sr_probe *const probe = (sr_probe*) | |
81 | item->data(UserRole).value<void*>(); | |
82 | assert(probe); | |
83 | probe->enabled = item->checkState() == Checked; | |
ed773982 JH |
84 | } |
85 | } | |
86 | ||
51d4a9ab JH |
87 | void Probes::item_changed(QListWidgetItem *item) |
88 | { | |
89 | assert(item); | |
90 | sr_probe *const probe = (sr_probe*) | |
91 | item->data(UserRole).value<void*>(); | |
92 | assert(probe); | |
93 | probe->enabled = item->checkState() == Checked; | |
94 | } | |
95 | ||
96 | void Probes::enable_all_probes() | |
ed773982 JH |
97 | { |
98 | set_all_probes(true); | |
99 | } | |
100 | ||
51d4a9ab | 101 | void Probes::disable_all_probes() |
ed773982 JH |
102 | { |
103 | set_all_probes(false); | |
104 | } | |
105 | ||
51d4a9ab JH |
106 | } // popups |
107 | } // pv |