2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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/>.
25 #include <QApplication>
26 #include <QFormLayout>
31 #include <libsigrokcxx/libsigrokcxx.hpp>
33 #include "pv/data/signalbase.hpp"
38 using std::shared_ptr
;
44 const char *const ChannelNames
[] = {
66 Signal::Signal(pv::Session
&session
,
67 shared_ptr
<data::SignalBase
> signal
) :
74 connect(base_
.get(), SIGNAL(enabled_changed(bool)),
75 this, SLOT(on_enabled_changed(bool)));
78 void Signal::set_name(QString name
)
80 base_
->set_name(name
);
82 if (name
!= name_widget_
->currentText())
83 name_widget_
->setEditText(name
);
86 bool Signal::enabled() const
88 return base_
->enabled();
91 shared_ptr
<data::SignalBase
> Signal::base() const
96 void Signal::save_settings(QSettings
&settings
) const
98 std::map
<QString
, QVariant
> settings_map
= save_settings();
100 for (auto& entry
: settings_map
)
101 settings
.setValue(entry
.first
, entry
.second
);
104 std::map
<QString
, QVariant
> Signal::save_settings() const
106 return std::map
<QString
, QVariant
>();
109 void Signal::restore_settings(QSettings
&settings
)
111 std::map
<QString
, QVariant
> settings_map
;
113 QStringList keys
= settings
.allKeys();
114 for (int i
= 0; i
< keys
.size(); i
++)
115 settings_map
[keys
.at(i
)] = settings
.value(keys
.at(i
));
117 restore_settings(settings_map
);
120 void Signal::restore_settings(std::map
<QString
, QVariant
> settings
)
126 void Signal::paint_back(QPainter
&p
, ViewItemPaintParams
&pp
)
128 if (base_
->enabled())
129 Trace::paint_back(p
, pp
);
132 void Signal::populate_popup_form(QWidget
*parent
, QFormLayout
*form
)
134 name_widget_
= new QComboBox(parent
);
135 name_widget_
->setEditable(true);
136 name_widget_
->setCompleter(nullptr);
138 for (unsigned int i
= 0; i
< countof(ChannelNames
); i
++)
139 name_widget_
->insertItem(i
, ChannelNames
[i
]);
141 const int index
= name_widget_
->findText(base_
->name(), Qt::MatchExactly
);
144 name_widget_
->insertItem(0, base_
->name());
145 name_widget_
->setCurrentIndex(0);
147 name_widget_
->setCurrentIndex(index
);
150 connect(name_widget_
, SIGNAL(editTextChanged(const QString
&)),
151 this, SLOT(on_nameedit_changed(const QString
&)));
153 form
->addRow(tr("Name"), name_widget_
);
155 add_color_option(parent
, form
);
158 QMenu
* Signal::create_header_context_menu(QWidget
*parent
)
160 QMenu
*const menu
= Trace::create_header_context_menu(parent
);
162 menu
->addSeparator();
166 if (base_
->is_generated())
167 caption
= tr("Remove");
169 caption
= tr("Disable");
171 QAction
*const a
= new QAction(caption
, this);
172 a
->setShortcuts(QKeySequence::Delete
);
173 connect(a
, SIGNAL(triggered()), this, SLOT(on_disable()));
179 void Signal::delete_pressed()
184 void Signal::on_name_changed(const QString
&text
)
186 // On startup, this event is fired when a session restores signal
187 // names. However, the name widget hasn't yet been created.
191 if (text
!= name_widget_
->currentText())
192 name_widget_
->setEditText(text
);
194 Trace::on_name_changed(text
);
197 void Signal::on_disable()
199 if (base_
->is_generated())
200 session_
.remove_generated_signal(base_
);
202 base_
->set_enabled(false);
205 void Signal::on_enabled_changed(bool enabled
)
210 owner_
->extents_changed(true, true);