]>
Commit | Line | Data |
---|---|---|
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, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <extdef.h> | |
22 | ||
23 | #include <assert.h> | |
24 | #include <math.h> | |
25 | ||
26 | #include <QApplication> | |
27 | #include <QFormLayout> | |
28 | #include <QMenu> | |
29 | ||
30 | #include <libsigrok/libsigrok.h> | |
31 | ||
32 | #include "signal.h" | |
33 | #include "view.h" | |
34 | ||
35 | using boost::shared_ptr; | |
36 | ||
37 | namespace pv { | |
38 | namespace view { | |
39 | ||
40 | const char *const ProbeNames[] = { | |
41 | "CLK", | |
42 | "DATA", | |
43 | "IN", | |
44 | "OUT", | |
45 | "RST", | |
46 | "Tx", | |
47 | "Rx", | |
48 | "EN", | |
49 | "SCLK", | |
50 | "MOSI", | |
51 | "MISO", | |
52 | "/SS", | |
53 | "SDA", | |
54 | "SCL" | |
55 | }; | |
56 | ||
57 | Signal::Signal(pv::SigSession &session, shared_ptr<pv::DevInst> dev_inst, | |
58 | sr_probe *const probe) : | |
59 | Trace(session, probe->name), | |
60 | _dev_inst(dev_inst), | |
61 | _probe(probe), | |
62 | _name_widget(NULL), | |
63 | _updating_name_widget(false) | |
64 | { | |
65 | assert(_probe); | |
66 | } | |
67 | ||
68 | void Signal::set_name(QString name) | |
69 | { | |
70 | Trace::set_name(name); | |
71 | _updating_name_widget = true; | |
72 | _name_widget->setEditText(name); | |
73 | _updating_name_widget = false; | |
74 | } | |
75 | ||
76 | bool Signal::enabled() const | |
77 | { | |
78 | return _probe->enabled; | |
79 | } | |
80 | ||
81 | void Signal::enable(bool enable) | |
82 | { | |
83 | _probe->enabled = enable; | |
84 | visibility_changed(); | |
85 | } | |
86 | ||
87 | const sr_probe* Signal::probe() const | |
88 | { | |
89 | return _probe; | |
90 | } | |
91 | ||
92 | void Signal::populate_popup_form(QWidget *parent, QFormLayout *form) | |
93 | { | |
94 | _name_widget = new QComboBox(parent); | |
95 | _name_widget->setEditable(true); | |
96 | ||
97 | for(unsigned int i = 0; i < countof(ProbeNames); i++) | |
98 | _name_widget->insertItem(i, ProbeNames[i]); | |
99 | _name_widget->setEditText(_probe->name); | |
100 | ||
101 | connect(_name_widget, SIGNAL(editTextChanged(const QString&)), | |
102 | this, SLOT(on_text_changed(const QString&))); | |
103 | ||
104 | form->addRow(tr("Name"), _name_widget); | |
105 | ||
106 | add_colour_option(parent, form); | |
107 | } | |
108 | ||
109 | QMenu* Signal::create_context_menu(QWidget *parent) | |
110 | { | |
111 | QMenu *const menu = Trace::create_context_menu(parent); | |
112 | ||
113 | menu->addSeparator(); | |
114 | ||
115 | QAction *const disable = new QAction(tr("Disable"), this); | |
116 | disable->setShortcuts(QKeySequence::Delete); | |
117 | connect(disable, SIGNAL(triggered()), this, SLOT(on_disable())); | |
118 | menu->addAction(disable); | |
119 | ||
120 | return menu; | |
121 | } | |
122 | ||
123 | void Signal::delete_pressed() | |
124 | { | |
125 | on_disable(); | |
126 | } | |
127 | ||
128 | void Signal::on_disable() | |
129 | { | |
130 | enable(false); | |
131 | } | |
132 | ||
133 | } // namespace view | |
134 | } // namespace pv |