]>
Commit | Line | Data |
---|---|---|
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 | ||
21 | #include "probes.h" | |
22 | ||
23 | #include <pv/sigsession.h> | |
24 | #include <pv/view/signal.h> | |
25 | ||
26 | using namespace boost; | |
27 | using namespace Qt; | |
28 | using namespace std; | |
29 | ||
30 | namespace pv { | |
31 | namespace popups { | |
32 | ||
33 | Probes::Probes(SigSession &session, QWidget *parent) : | |
34 | Popup(parent), | |
35 | _session(session), | |
36 | _layout(this), | |
37 | _probes(this), | |
38 | _probes_bar(this), | |
39 | _enable_all_probes(this), | |
40 | _disable_all_probes(this) | |
41 | { | |
42 | setLayout(&_layout); | |
43 | ||
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 | ||
49 | _layout.addWidget(&_probes); | |
50 | ||
51 | _enable_all_probes.setText(tr("Enable All")); | |
52 | _probes_bar.addWidget(&_enable_all_probes); | |
53 | ||
54 | _disable_all_probes.setText(tr("Disable All")); | |
55 | _probes_bar.addWidget(&_disable_all_probes); | |
56 | ||
57 | _layout.addWidget(&_probes_bar); | |
58 | ||
59 | const vector< shared_ptr<pv::view::Signal> > sigs = | |
60 | _session.get_signals(); | |
61 | for (unsigned int i = 0; i < sigs.size(); i++) | |
62 | { | |
63 | const shared_ptr<pv::view::Signal> &s = sigs[i]; | |
64 | assert(s); | |
65 | QListWidgetItem *const item = new QListWidgetItem( | |
66 | s->get_name(), &_probes); | |
67 | assert(item); | |
68 | item->setData(UserRole, qVariantFromValue(i)); | |
69 | item->setCheckState(s->enabled() ? Checked : Unchecked); | |
70 | _probes.addItem(item); | |
71 | } | |
72 | ||
73 | connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)), | |
74 | this, SLOT(item_changed(QListWidgetItem*))); | |
75 | } | |
76 | ||
77 | void Probes::set_all_probes(bool set) | |
78 | { | |
79 | using pv::view::Signal; | |
80 | ||
81 | const vector< shared_ptr<pv::view::Signal> > sigs = | |
82 | _session.get_signals(); | |
83 | for (unsigned int i = 0; i < sigs.size(); i++) | |
84 | { | |
85 | const shared_ptr<pv::view::Signal> &s = sigs[i]; | |
86 | assert(s); | |
87 | s->enable(set); | |
88 | ||
89 | QListWidgetItem *const item = _probes.item(i); | |
90 | assert(item); | |
91 | item->setCheckState(set ? Qt::Checked : Qt::Unchecked); | |
92 | } | |
93 | } | |
94 | ||
95 | void Probes::item_changed(QListWidgetItem *item) | |
96 | { | |
97 | using pv::view::Signal; | |
98 | ||
99 | assert(item); | |
100 | const vector< shared_ptr<pv::view::Signal> > sigs = | |
101 | _session.get_signals(); | |
102 | const shared_ptr<pv::view::Signal> s = sigs[ | |
103 | item->data(UserRole).value<unsigned int>()]; | |
104 | assert(s); | |
105 | s->enable(item->checkState() == Checked); | |
106 | } | |
107 | ||
108 | void Probes::enable_all_probes() | |
109 | { | |
110 | set_all_probes(true); | |
111 | } | |
112 | ||
113 | void Probes::disable_all_probes() | |
114 | { | |
115 | set_all_probes(false); | |
116 | } | |
117 | ||
118 | } // popups | |
119 | } // pv |