]> sigrok.org Git - pulseview.git/blame - pv/views/trace/signal.cpp
Improve hover point signaling
[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;
f1626bb8 39using std::make_shared;
8d3e0764 40
51e77110 41namespace pv {
f4e57597 42namespace views {
1573bf16 43namespace trace {
51e77110 44
6ac6242b 45const char *const ChannelNames[] = {
9e40e83d
JH
46 "CLK",
47 "DATA",
48 "IN",
49 "OUT",
50 "RST",
fae4a2e6
UH
51 "TX",
52 "RX",
9e40e83d
JH
53 "EN",
54 "SCLK",
55 "MOSI",
56 "MISO",
57 "/SS",
58 "SDA",
59 "SCL"
60};
61
2b81ae46 62Signal::Signal(pv::Session &session,
6f925ba9 63 shared_ptr<data::SignalBase> channel) :
bf0edd2b 64 Trace(channel),
8dbbc7f0 65 session_(session),
fcb97d77 66 name_widget_(nullptr)
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
3a21afa6
SA
92void Signal::save_settings(QSettings &settings) const
93{
94 (void)settings;
95}
96
97void Signal::restore_settings(QSettings &settings)
98{
99 (void)settings;
100}
101
60938e04 102void Signal::paint_back(QPainter &p, ViewItemPaintParams &pp)
99af6802 103{
73a25a6e 104 if (base_->enabled())
99af6802
SA
105 Trace::paint_back(p, pp);
106}
107
0c0218fd
JH
108void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
109{
8dbbc7f0
JH
110 name_widget_ = new QComboBox(parent);
111 name_widget_->setEditable(true);
f74015db 112 name_widget_->setCompleter(nullptr);
0c0218fd 113
f3290553 114 for (unsigned int i = 0; i < countof(ChannelNames); i++)
8dbbc7f0 115 name_widget_->insertItem(i, ChannelNames[i]);
3c100123 116
73a25a6e 117 const int index = name_widget_->findText(base_->name(), Qt::MatchExactly);
3c100123
SA
118
119 if (index == -1) {
73a25a6e 120 name_widget_->insertItem(0, base_->name());
8dbbc7f0 121 name_widget_->setCurrentIndex(0);
3c100123 122 } else {
8dbbc7f0 123 name_widget_->setCurrentIndex(index);
3c100123
SA
124 }
125
8dbbc7f0 126 connect(name_widget_, SIGNAL(editTextChanged(const QString&)),
bf0edd2b 127 this, SLOT(on_nameedit_changed(const QString&)));
0c0218fd 128
8dbbc7f0 129 form->addRow(tr("Name"), name_widget_);
91e8bf08
JH
130
131 add_colour_option(parent, form);
0c0218fd
JH
132}
133
86e823ca
JH
134QMenu* Signal::create_context_menu(QWidget *parent)
135{
136 QMenu *const menu = Trace::create_context_menu(parent);
137
138 menu->addSeparator();
139
140 QAction *const disable = new QAction(tr("Disable"), this);
a2d21018 141 disable->setShortcuts(QKeySequence::Delete);
86e823ca
JH
142 connect(disable, SIGNAL(triggered()), this, SLOT(on_disable()));
143 menu->addAction(disable);
144
145 return menu;
146}
147
5ed1adf5
JH
148void Signal::delete_pressed()
149{
150 on_disable();
151}
152
bf0edd2b
SA
153void Signal::on_name_changed(const QString &text)
154{
aecae05c
SA
155 // On startup, this event is fired when a session restores signal
156 // names. However, the name widget hasn't yet been created.
157 if (!name_widget_)
158 return;
159
bf0edd2b
SA
160 if (text != name_widget_->currentText())
161 name_widget_->setEditText(text);
162
163 Trace::on_name_changed(text);
164}
165
86e823ca
JH
166void Signal::on_disable()
167{
a45b9b9e
SA
168 base_->set_enabled(false);
169}
170
171void Signal::on_enabled_changed(bool enabled)
172{
173 (void)enabled;
174
175 if (owner_)
176 owner_->extents_changed(true, true);
86e823ca
JH
177}
178
1573bf16 179} // namespace trace
f4e57597 180} // namespace views
51e77110 181} // namespace pv