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