]>
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 | |
aca00b1e JH |
23 | #include <pv/sigsession.h> |
24 | #include <pv/view/signal.h> | |
25 | ||
26 | using namespace boost; | |
51d4a9ab | 27 | using namespace Qt; |
aca00b1e | 28 | using namespace std; |
479bcabe | 29 | |
cdb50f67 | 30 | namespace pv { |
51d4a9ab | 31 | namespace popups { |
cdb50f67 | 32 | |
aca00b1e | 33 | Probes::Probes(SigSession &session, QWidget *parent) : |
51d4a9ab | 34 | Popup(parent), |
aca00b1e | 35 | _session(session), |
497a5b8b | 36 | _layout(this), |
0740907f | 37 | _probes(this), |
b7b659aa | 38 | _updating_probes(false), |
ed773982 JH |
39 | _probes_bar(this), |
40 | _enable_all_probes(this), | |
51d4a9ab | 41 | _disable_all_probes(this) |
cdb50f67 | 42 | { |
51d4a9ab | 43 | setLayout(&_layout); |
9c025ef3 | 44 | |
ed773982 JH |
45 | connect(&_enable_all_probes, SIGNAL(clicked()), |
46 | this, SLOT(enable_all_probes())); | |
47 | connect(&_disable_all_probes, SIGNAL(clicked()), | |
48 | this, SLOT(disable_all_probes())); | |
49 | ||
51d4a9ab | 50 | _layout.addWidget(&_probes); |
ed773982 JH |
51 | |
52 | _enable_all_probes.setText(tr("Enable All")); | |
53 | _probes_bar.addWidget(&_enable_all_probes); | |
54 | ||
55 | _disable_all_probes.setText(tr("Disable All")); | |
56 | _probes_bar.addWidget(&_disable_all_probes); | |
57 | ||
51d4a9ab | 58 | _layout.addWidget(&_probes_bar); |
0740907f | 59 | |
b7b659aa JH |
60 | connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)), |
61 | this, SLOT(item_changed(QListWidgetItem*))); | |
62 | } | |
63 | ||
64 | void Probes::set_all_probes(bool set) | |
65 | { | |
66 | using pv::view::Signal; | |
67 | ||
68 | _updating_probes = true; | |
69 | ||
aca00b1e JH |
70 | const vector< shared_ptr<pv::view::Signal> > sigs = |
71 | _session.get_signals(); | |
72 | for (unsigned int i = 0; i < sigs.size(); i++) | |
73 | { | |
74 | const shared_ptr<pv::view::Signal> &s = sigs[i]; | |
75 | assert(s); | |
b7b659aa JH |
76 | s->enable(set); |
77 | ||
78 | QListWidgetItem *const item = _probes.item(i); | |
0740907f | 79 | assert(item); |
b7b659aa | 80 | item->setCheckState(set ? Qt::Checked : Qt::Unchecked); |
0740907f | 81 | } |
51d4a9ab | 82 | |
b7b659aa | 83 | _updating_probes = false; |
0740907f JH |
84 | } |
85 | ||
b7b659aa | 86 | void Probes::showEvent(QShowEvent *e) |
ed773982 | 87 | { |
b7b659aa JH |
88 | pv::widgets::Popup::showEvent(e); |
89 | ||
90 | _updating_probes = true; | |
91 | ||
92 | _probes.clear(); | |
aca00b1e JH |
93 | |
94 | const vector< shared_ptr<pv::view::Signal> > sigs = | |
95 | _session.get_signals(); | |
96 | for (unsigned int i = 0; i < sigs.size(); i++) | |
97 | { | |
98 | const shared_ptr<pv::view::Signal> &s = sigs[i]; | |
99 | assert(s); | |
b7b659aa JH |
100 | QListWidgetItem *const item = new QListWidgetItem( |
101 | s->get_name(), &_probes); | |
ed773982 | 102 | assert(item); |
b7b659aa JH |
103 | item->setCheckState(s->enabled() ? Checked : Unchecked); |
104 | item->setData(UserRole, qVariantFromValue(i)); | |
105 | _probes.addItem(item); | |
ed773982 | 106 | } |
b7b659aa JH |
107 | |
108 | _updating_probes = false; | |
ed773982 JH |
109 | } |
110 | ||
51d4a9ab JH |
111 | void Probes::item_changed(QListWidgetItem *item) |
112 | { | |
aca00b1e JH |
113 | using pv::view::Signal; |
114 | ||
b7b659aa JH |
115 | if (_updating_probes) |
116 | return; | |
117 | ||
51d4a9ab | 118 | assert(item); |
aca00b1e JH |
119 | const vector< shared_ptr<pv::view::Signal> > sigs = |
120 | _session.get_signals(); | |
121 | const shared_ptr<pv::view::Signal> s = sigs[ | |
122 | item->data(UserRole).value<unsigned int>()]; | |
123 | assert(s); | |
124 | s->enable(item->checkState() == Checked); | |
51d4a9ab JH |
125 | } |
126 | ||
127 | void Probes::enable_all_probes() | |
ed773982 JH |
128 | { |
129 | set_all_probes(true); | |
130 | } | |
131 | ||
51d4a9ab | 132 | void Probes::disable_all_probes() |
ed773982 JH |
133 | { |
134 | set_all_probes(false); | |
135 | } | |
136 | ||
51d4a9ab JH |
137 | } // popups |
138 | } // pv |