]> sigrok.org Git - pulseview.git/blame - pv/views/trace/signal.cpp
DecodeTrace: Allow row hiding
[pulseview.git] / pv / views / trace / signal.cpp
CommitLineData
28a4c9c5 1/*
b3f22de0 2 * This file is part of the PulseView project.
28a4c9c5
JH
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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28a4c9c5
JH
18 */
19
cef18fc6 20#include <extdef.h>
28a4c9c5 21
eb8269e3 22#include <cassert>
d9e71737 23#include <cmath>
b47d951e 24
e3374498 25#include <QApplication>
b213ef09 26#include <QFormLayout>
3c100123 27#include <QKeyEvent>
b9b7854e 28#include <QLineEdit>
b213ef09 29#include <QMenu>
e3374498 30
fe3a1c21 31#include <libsigrokcxx/libsigrokcxx.hpp>
8d3e0764 32
bf0edd2b
SA
33#include "pv/data/signalbase.hpp"
34
2acdb232
JH
35#include "signal.hpp"
36#include "view.hpp"
3e46726a 37
f9abf97e 38using std::shared_ptr;
8d3e0764 39
51e77110 40namespace pv {
f4e57597 41namespace views {
1573bf16 42namespace trace {
51e77110 43
6ac6242b 44const char *const ChannelNames[] = {
9e40e83d
JH
45 "CLK",
46 "DATA",
47 "IN",
48 "OUT",
49 "RST",
fae4a2e6
UH
50 "TX",
51 "RX",
9e40e83d
JH
52 "EN",
53 "SCLK",
54 "MOSI",
55 "MISO",
56 "/SS",
57 "SDA",
58 "SCL"
59};
60
2b81ae46 61Signal::Signal(pv::Session &session,
6f925ba9 62 shared_ptr<data::SignalBase> channel) :
bf0edd2b 63 Trace(channel),
8dbbc7f0 64 session_(session),
2749b858 65 name_widget_(nullptr)
28a4c9c5 66{
73a25a6e 67 assert(base_);
a45b9b9e
SA
68
69 connect(base_.get(), SIGNAL(enabled_changed(bool)),
70 this, SLOT(on_enabled_changed(bool)));
ef8311a4
JH
71}
72
49f8ff3f
JH
73void Signal::set_name(QString name)
74{
0acf629d 75 base_->set_name(name);
fcb97d77
SA
76
77 if (name != name_widget_->currentText())
78 name_widget_->setEditText(name);
49f8ff3f
JH
79}
80
931f20b0 81bool Signal::enabled() const
2e575351 82{
73a25a6e 83 return base_->enabled();
a29bb7fb
JH
84}
85
73a25a6e 86shared_ptr<data::SignalBase> Signal::base() const
632ba77e 87{
73a25a6e 88 return base_;
632ba77e
JH
89}
90
3a21afa6
SA
91void Signal::save_settings(QSettings &settings) const
92{
0a952555
SA
93 std::map<QString, QVariant> settings_map = save_settings();
94
95 for (auto& entry : settings_map)
96 settings.setValue(entry.first, entry.second);
97}
98
99std::map<QString, QVariant> Signal::save_settings() const
100{
101 return std::map<QString, QVariant>();
3a21afa6
SA
102}
103
104void Signal::restore_settings(QSettings &settings)
0a952555
SA
105{
106 std::map<QString, QVariant> settings_map;
107
108 QStringList keys = settings.allKeys();
109 for (int i = 0; i < keys.size(); i++)
110 settings_map[keys.at(i)] = settings.value(keys.at(i));
111
112 restore_settings(settings_map);
113}
114
115void Signal::restore_settings(std::map<QString, QVariant> settings)
3a21afa6
SA
116{
117 (void)settings;
118}
119
0a952555 120
60938e04 121void Signal::paint_back(QPainter &p, ViewItemPaintParams &pp)
99af6802 122{
73a25a6e 123 if (base_->enabled())
99af6802
SA
124 Trace::paint_back(p, pp);
125}
126
0c0218fd
JH
127void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
128{
8dbbc7f0
JH
129 name_widget_ = new QComboBox(parent);
130 name_widget_->setEditable(true);
f74015db 131 name_widget_->setCompleter(nullptr);
0c0218fd 132
f3290553 133 for (unsigned int i = 0; i < countof(ChannelNames); i++)
8dbbc7f0 134 name_widget_->insertItem(i, ChannelNames[i]);
3c100123 135
73a25a6e 136 const int index = name_widget_->findText(base_->name(), Qt::MatchExactly);
3c100123
SA
137
138 if (index == -1) {
73a25a6e 139 name_widget_->insertItem(0, base_->name());
8dbbc7f0 140 name_widget_->setCurrentIndex(0);
3c100123 141 } else {
8dbbc7f0 142 name_widget_->setCurrentIndex(index);
3c100123
SA
143 }
144
8dbbc7f0 145 connect(name_widget_, SIGNAL(editTextChanged(const QString&)),
bf0edd2b 146 this, SLOT(on_nameedit_changed(const QString&)));
0c0218fd 147
8dbbc7f0 148 form->addRow(tr("Name"), name_widget_);
91e8bf08 149
641574bc 150 add_color_option(parent, form);
0c0218fd
JH
151}
152
9e773fec 153QMenu* Signal::create_header_context_menu(QWidget *parent)
86e823ca 154{
9e773fec 155 QMenu *const menu = Trace::create_header_context_menu(parent);
86e823ca
JH
156
157 menu->addSeparator();
158
159 QAction *const disable = new QAction(tr("Disable"), this);
a2d21018 160 disable->setShortcuts(QKeySequence::Delete);
86e823ca
JH
161 connect(disable, SIGNAL(triggered()), this, SLOT(on_disable()));
162 menu->addAction(disable);
163
164 return menu;
165}
166
5ed1adf5
JH
167void Signal::delete_pressed()
168{
169 on_disable();
170}
171
bf0edd2b
SA
172void Signal::on_name_changed(const QString &text)
173{
aecae05c
SA
174 // On startup, this event is fired when a session restores signal
175 // names. However, the name widget hasn't yet been created.
176 if (!name_widget_)
177 return;
178
bf0edd2b
SA
179 if (text != name_widget_->currentText())
180 name_widget_->setEditText(text);
181
182 Trace::on_name_changed(text);
183}
184
86e823ca
JH
185void Signal::on_disable()
186{
a45b9b9e
SA
187 base_->set_enabled(false);
188}
189
190void Signal::on_enabled_changed(bool enabled)
191{
192 (void)enabled;
193
194 if (owner_)
195 owner_->extents_changed(true, true);
86e823ca
JH
196}
197
1573bf16 198} // namespace trace
f4e57597 199} // namespace views
51e77110 200} // namespace pv