X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fsignal.cpp;h=5cd5b183590af45dcd783dd948f3a0d81af84582;hp=ba1271b0c4251afee4f3dedfff8b534d59a3d647;hb=8c09273b13a10399e7f7d18dd446c2d13813e239;hpb=8d3e0764def48fdf19dc9100c87bbb42da5a9d6d diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index ba1271b0..5cd5b183 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -21,30 +21,35 @@ #include #include -#include +#include #include #include +#include +#include #include -#include +#include -#include "signal.h" -#include "view.h" +#include "signal.hpp" +#include "view.hpp" -using boost::shared_ptr; +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", @@ -54,54 +59,81 @@ const char *const ProbeNames[] = { "SCL" }; -Signal::Signal(pv::SigSession &session, shared_ptr dev_inst, - sr_probe *const probe) : - Trace(session, probe->name), - _dev_inst(dev_inst), - _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) { - 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; + + if (name != name_widget_->currentText()) + name_widget_->setEditText(name); + + // 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 ViewItemOwner::item_list& Signal::child_items() const +{ + return items_; } -const sr_probe* Signal::probe() const +void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - return _probe; + if (channel_->enabled()) + Trace::paint_back(p, pp); } 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(nullptr); + + 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); }