]> sigrok.org Git - pulseview.git/blame_incremental - pv/views/trace/signal.cpp
Typo fix: treshold -> threshold
[pulseview.git] / pv / views / trace / signal.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, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <extdef.h>
21
22#include <cassert>
23#include <cmath>
24
25#include <QApplication>
26#include <QFormLayout>
27#include <QKeyEvent>
28#include <QLineEdit>
29#include <QMenu>
30
31#include <libsigrokcxx/libsigrokcxx.hpp>
32
33#include "pv/data/signalbase.hpp"
34
35#include "signal.hpp"
36#include "view.hpp"
37
38using std::shared_ptr;
39using std::make_shared;
40
41namespace pv {
42namespace views {
43namespace trace {
44
45const char *const ChannelNames[] = {
46 "CLK",
47 "DATA",
48 "IN",
49 "OUT",
50 "RST",
51 "TX",
52 "RX",
53 "EN",
54 "SCLK",
55 "MOSI",
56 "MISO",
57 "/SS",
58 "SDA",
59 "SCL"
60};
61
62Signal::Signal(pv::Session &session,
63 shared_ptr<data::SignalBase> channel) :
64 Trace(channel),
65 session_(session),
66 name_widget_(nullptr)
67{
68 assert(base_);
69
70 connect(base_.get(), SIGNAL(enabled_changed(bool)),
71 this, SLOT(on_enabled_changed(bool)));
72}
73
74void Signal::set_name(QString name)
75{
76 Trace::set_name(name);
77
78 if (name != name_widget_->currentText())
79 name_widget_->setEditText(name);
80}
81
82bool Signal::enabled() const
83{
84 return base_->enabled();
85}
86
87shared_ptr<data::SignalBase> Signal::base() const
88{
89 return base_;
90}
91
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
102void Signal::paint_back(QPainter &p, ViewItemPaintParams &pp)
103{
104 if (base_->enabled())
105 Trace::paint_back(p, pp);
106}
107
108void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
109{
110 name_widget_ = new QComboBox(parent);
111 name_widget_->setEditable(true);
112 name_widget_->setCompleter(nullptr);
113
114 for (unsigned int i = 0; i < countof(ChannelNames); i++)
115 name_widget_->insertItem(i, ChannelNames[i]);
116
117 const int index = name_widget_->findText(base_->name(), Qt::MatchExactly);
118
119 if (index == -1) {
120 name_widget_->insertItem(0, base_->name());
121 name_widget_->setCurrentIndex(0);
122 } else {
123 name_widget_->setCurrentIndex(index);
124 }
125
126 connect(name_widget_, SIGNAL(editTextChanged(const QString&)),
127 this, SLOT(on_nameedit_changed(const QString&)));
128
129 form->addRow(tr("Name"), name_widget_);
130
131 add_colour_option(parent, form);
132}
133
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);
141 disable->setShortcuts(QKeySequence::Delete);
142 connect(disable, SIGNAL(triggered()), this, SLOT(on_disable()));
143 menu->addAction(disable);
144
145 return menu;
146}
147
148void Signal::delete_pressed()
149{
150 on_disable();
151}
152
153void Signal::on_name_changed(const QString &text)
154{
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
160 if (text != name_widget_->currentText())
161 name_widget_->setEditText(text);
162
163 Trace::on_name_changed(text);
164}
165
166void Signal::on_disable()
167{
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);
177}
178
179} // namespace trace
180} // namespace views
181} // namespace pv