2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
23 #include <pv/sigsession.h>
24 #include <pv/view/signal.h>
26 using namespace boost;
33 Probes::Probes(SigSession &session, QWidget *parent) :
38 _updating_probes(false),
40 _enable_all_probes(this),
41 _disable_all_probes(this)
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()));
50 _layout.addWidget(&_probes);
52 _enable_all_probes.setText(tr("Enable All"));
53 _probes_bar.addWidget(&_enable_all_probes);
55 _disable_all_probes.setText(tr("Disable All"));
56 _probes_bar.addWidget(&_disable_all_probes);
58 _layout.addWidget(&_probes_bar);
60 connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)),
61 this, SLOT(item_changed(QListWidgetItem*)));
64 void Probes::set_all_probes(bool set)
66 using pv::view::Signal;
68 _updating_probes = true;
70 const vector< shared_ptr<pv::view::Signal> > sigs =
71 _session.get_signals();
72 for (unsigned int i = 0; i < sigs.size(); i++)
74 const shared_ptr<pv::view::Signal> &s = sigs[i];
78 QListWidgetItem *const item = _probes.item(i);
80 item->setCheckState(set ? Qt::Checked : Qt::Unchecked);
83 _updating_probes = false;
86 void Probes::showEvent(QShowEvent *e)
88 pv::widgets::Popup::showEvent(e);
90 _updating_probes = true;
94 const vector< shared_ptr<pv::view::Signal> > sigs =
95 _session.get_signals();
96 for (unsigned int i = 0; i < sigs.size(); i++)
98 const shared_ptr<pv::view::Signal> &s = sigs[i];
100 QListWidgetItem *const item = new QListWidgetItem(
101 s->get_name(), &_probes);
103 item->setCheckState(s->enabled() ? Checked : Unchecked);
104 item->setData(UserRole, qVariantFromValue(i));
105 _probes.addItem(item);
108 _updating_probes = false;
111 void Probes::item_changed(QListWidgetItem *item)
113 using pv::view::Signal;
115 if (_updating_probes)
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>()];
124 s->enable(item->checkState() == Checked);
127 void Probes::enable_all_probes()
129 set_all_probes(true);
132 void Probes::disable_all_probes()
134 set_all_probes(false);