]> sigrok.org Git - pulseview.git/blame - pv/views/trace/signal.cpp
View: Move comment to where it belongs
[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),
526c8c00
SA
65 name_widget_(nullptr),
66 current_segment_(0)
28a4c9c5 67{
73a25a6e 68 assert(base_);
a45b9b9e
SA
69
70 connect(base_.get(), SIGNAL(enabled_changed(bool)),
71 this, SLOT(on_enabled_changed(bool)));
ef8311a4
JH
72}
73
49f8ff3f
JH
74void Signal::set_name(QString name)
75{
931f20b0 76 Trace::set_name(name);
fcb97d77
SA
77
78 if (name != name_widget_->currentText())
79 name_widget_->setEditText(name);
49f8ff3f
JH
80}
81
931f20b0 82bool Signal::enabled() const
2e575351 83{
73a25a6e 84 return base_->enabled();
a29bb7fb
JH
85}
86
73a25a6e 87shared_ptr<data::SignalBase> Signal::base() const
632ba77e 88{
73a25a6e 89 return base_;
632ba77e
JH
90}
91
526c8c00
SA
92void Signal::set_current_segment(const int segment)
93{
94 current_segment_ = segment;
95}
96
97int Signal::get_current_segment() const
98{
99 return current_segment_;
100}
101
3a21afa6
SA
102void Signal::save_settings(QSettings &settings) const
103{
104 (void)settings;
105}
106
107void Signal::restore_settings(QSettings &settings)
108{
109 (void)settings;
110}
111
60938e04 112void Signal::paint_back(QPainter &p, ViewItemPaintParams &pp)
99af6802 113{
73a25a6e 114 if (base_->enabled())
99af6802
SA
115 Trace::paint_back(p, pp);
116}
117
0c0218fd
JH
118void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
119{
8dbbc7f0
JH
120 name_widget_ = new QComboBox(parent);
121 name_widget_->setEditable(true);
f74015db 122 name_widget_->setCompleter(nullptr);
0c0218fd 123
f3290553 124 for (unsigned int i = 0; i < countof(ChannelNames); i++)
8dbbc7f0 125 name_widget_->insertItem(i, ChannelNames[i]);
3c100123 126
73a25a6e 127 const int index = name_widget_->findText(base_->name(), Qt::MatchExactly);
3c100123
SA
128
129 if (index == -1) {
73a25a6e 130 name_widget_->insertItem(0, base_->name());
8dbbc7f0 131 name_widget_->setCurrentIndex(0);
3c100123 132 } else {
8dbbc7f0 133 name_widget_->setCurrentIndex(index);
3c100123
SA
134 }
135
8dbbc7f0 136 connect(name_widget_, SIGNAL(editTextChanged(const QString&)),
bf0edd2b 137 this, SLOT(on_nameedit_changed(const QString&)));
0c0218fd 138
8dbbc7f0 139 form->addRow(tr("Name"), name_widget_);
91e8bf08
JH
140
141 add_colour_option(parent, form);
0c0218fd
JH
142}
143
86e823ca
JH
144QMenu* Signal::create_context_menu(QWidget *parent)
145{
146 QMenu *const menu = Trace::create_context_menu(parent);
147
148 menu->addSeparator();
149
150 QAction *const disable = new QAction(tr("Disable"), this);
a2d21018 151 disable->setShortcuts(QKeySequence::Delete);
86e823ca
JH
152 connect(disable, SIGNAL(triggered()), this, SLOT(on_disable()));
153 menu->addAction(disable);
154
155 return menu;
156}
157
5ed1adf5
JH
158void Signal::delete_pressed()
159{
160 on_disable();
161}
162
bf0edd2b
SA
163void Signal::on_name_changed(const QString &text)
164{
aecae05c
SA
165 // On startup, this event is fired when a session restores signal
166 // names. However, the name widget hasn't yet been created.
167 if (!name_widget_)
168 return;
169
bf0edd2b
SA
170 if (text != name_widget_->currentText())
171 name_widget_->setEditText(text);
172
173 Trace::on_name_changed(text);
174}
175
86e823ca
JH
176void Signal::on_disable()
177{
a45b9b9e
SA
178 base_->set_enabled(false);
179}
180
181void Signal::on_enabled_changed(bool enabled)
182{
183 (void)enabled;
184
185 if (owner_)
186 owner_->extents_changed(true, true);
86e823ca
JH
187}
188
1573bf16 189} // namespace trace
f4e57597 190} // namespace views
51e77110 191} // namespace pv