]> sigrok.org Git - pulseview.git/blame_incremental - pv/popups/probes.cpp
Slightly offset the PopupToolButton popup
[pulseview.git] / pv / popups / probes.cpp
... / ...
CommitLineData
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
26using namespace boost;
27using namespace Qt;
28using namespace std;
29
30namespace pv {
31namespace popups {
32
33Probes::Probes(SigSession &session, QWidget *parent) :
34 Popup(parent),
35 _session(session),
36 _layout(this),
37 _probes(this),
38 _updating_probes(false),
39 _probes_bar(this),
40 _enable_all_probes(this),
41 _disable_all_probes(this)
42{
43 setLayout(&_layout);
44
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
50 _layout.addWidget(&_probes);
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
58 _layout.addWidget(&_probes_bar);
59
60 connect(&_probes, SIGNAL(itemChanged(QListWidgetItem*)),
61 this, SLOT(item_changed(QListWidgetItem*)));
62}
63
64void Probes::set_all_probes(bool set)
65{
66 using pv::view::Signal;
67
68 _updating_probes = true;
69
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);
76 s->enable(set);
77
78 QListWidgetItem *const item = _probes.item(i);
79 assert(item);
80 item->setCheckState(set ? Qt::Checked : Qt::Unchecked);
81 }
82
83 _updating_probes = false;
84}
85
86void Probes::showEvent(QShowEvent *e)
87{
88 pv::widgets::Popup::showEvent(e);
89
90 _updating_probes = true;
91
92 _probes.clear();
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);
100 QListWidgetItem *const item = new QListWidgetItem(
101 s->get_name(), &_probes);
102 assert(item);
103 item->setCheckState(s->enabled() ? Checked : Unchecked);
104 item->setData(UserRole, qVariantFromValue(i));
105 _probes.addItem(item);
106 }
107
108 _updating_probes = false;
109}
110
111void Probes::item_changed(QListWidgetItem *item)
112{
113 using pv::view::Signal;
114
115 if (_updating_probes)
116 return;
117
118 assert(item);
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);
125}
126
127void Probes::enable_all_probes()
128{
129 set_all_probes(true);
130}
131
132void Probes::disable_all_probes()
133{
134 set_all_probes(false);
135}
136
137} // popups
138} // pv