X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fsignal.cpp;h=47e91f4b9a67f9a904d0b059e3da5cee543a35ab;hp=1f00477a2012d9cb5a3a8e11f6cd046ff62f8682;hb=f1626bb80080435e306c9a6c5d6ff20dd6dc9e57;hpb=b213ef0991a13af0c74ffe5c54382c5c455c5496 diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 1f00477a..47e91f4b 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -21,26 +21,35 @@ #include #include -#include +#include #include #include +#include +#include #include -#include "signal.h" -#include "view.h" +#include + +#include "signal.hpp" +#include "view.hpp" + +using std::shared_ptr; +using std::make_shared; + +using sigrok::Channel; namespace pv { namespace view { -const char *const ProbeNames[] = { +const char *const ChannelNames[] = { "CLK", "DATA", "IN", "OUT", "RST", - "Tx", - "Rx", + "TX", + "RX", "EN", "SCLK", "MOSI", @@ -50,52 +59,76 @@ const char *const ProbeNames[] = { "SCL" }; -Signal::Signal(pv::SigSession &session, sr_probe *const probe) : - Trace(session, probe->name), - _probe(probe), - _name_widget(NULL), - _updating_name_widget(false) +Signal::Signal(pv::Session &session, + std::shared_ptr channel) : + Trace(QString::fromUtf8(channel->name().c_str())), + session_(session), + channel_(channel), + scale_handle_(make_shared(*this)), + items_({scale_handle_}), + name_widget_(nullptr), + updating_name_widget_(false) { - assert(_probe); + assert(channel_); } void Signal::set_name(QString name) { Trace::set_name(name); - _updating_name_widget = true; - _name_widget->setEditText(name); - _updating_name_widget = false; + updating_name_widget_ = true; + name_widget_->setEditText(name); + updating_name_widget_ = false; + + // Store the channel name in sigrok::Channel so that it + // will end up in the .sr file upon save. + channel_->set_name(name.toUtf8().constData()); } bool Signal::enabled() const { - return _probe->enabled; + return channel_->enabled(); } void Signal::enable(bool enable) { - _probe->enabled = enable; - visibility_changed(); + channel_->set_enabled(enable); + + if (owner_) + owner_->extents_changed(true, true); +} + +shared_ptr Signal::channel() const +{ + return channel_; } -const sr_probe* Signal::probe() const +const ViewItemOwner::item_list& Signal::child_items() const { - return _probe; + return items_; } void Signal::populate_popup_form(QWidget *parent, QFormLayout *form) { - _name_widget = new QComboBox(parent); - _name_widget->setEditable(true); + name_widget_ = new QComboBox(parent); + name_widget_->setEditable(true); + name_widget_->setCompleter(0); + + for (unsigned int i = 0; i < countof(ChannelNames); i++) + name_widget_->insertItem(i, ChannelNames[i]); + + const int index = name_widget_->findText(name_, Qt::MatchExactly); - for(unsigned int i = 0; i < countof(ProbeNames); i++) - _name_widget->insertItem(i, ProbeNames[i]); - _name_widget->setEditText(_probe->name); + if (index == -1) { + name_widget_->insertItem(0, name_); + name_widget_->setCurrentIndex(0); + } else { + name_widget_->setCurrentIndex(index); + } - connect(_name_widget, SIGNAL(editTextChanged(const QString&)), + connect(name_widget_, SIGNAL(editTextChanged(const QString&)), this, SLOT(on_text_changed(const QString&))); - form->addRow(tr("Name"), _name_widget); + form->addRow(tr("Name"), name_widget_); add_colour_option(parent, form); }