X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fview%2Fsignal.cpp;h=5cd5b183590af45dcd783dd948f3a0d81af84582;hp=d031b27a55cba190c4674dcfb39eecfbe6829ee7;hb=8c09273b13a10399e7f7d18dd446c2d13813e239;hpb=a2d210184772cd8d265ba1620de33763f1a00645 diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index d031b27a..5cd5b183 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -21,24 +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", @@ -48,52 +59,81 @@ 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) { - 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 sr_probe* Signal::probe() const +const ViewItemOwner::item_list& Signal::child_items() const { - return _probe; + return items_; +} + +void Signal::paint_back(QPainter &p, const ViewItemPaintParams &pp) +{ + 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); }