]> sigrok.org Git - pulseview.git/blobdiff - pv/view/signal.cpp
Rename 'probe' to 'channel' everywhere.
[pulseview.git] / pv / view / signal.cpp
index 3312c5924576b9517c5aa6425de4f935cbf95e63..97e05494cca05eac922a47a6bb0c1dd878472d93 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <QApplication>
 #include <QFormLayout>
+#include <QKeyEvent>
+#include <QLineEdit>
 #include <QMenu>
 
 #include <libsigrok/libsigrok.h>
 
 #include <pv/device/devinst.h>
 
-using boost::shared_ptr;
+using std::shared_ptr;
 
 namespace pv {
 namespace view {
 
-const char *const ProbeNames[] = {
+const char *const ChannelNames[] = {
        "CLK",
        "DATA",
        "IN",
@@ -57,14 +59,14 @@ const char *const ProbeNames[] = {
 };
 
 Signal::Signal(shared_ptr<pv::device::DevInst> dev_inst,
-       const sr_channel *const probe) :
-       Trace(probe->name),
+       const sr_channel *const channel) :
+       Trace(channel->name),
        _dev_inst(dev_inst),
-       _probe(probe),
+       _channel(channel),
        _name_widget(NULL),
        _updating_name_widget(false)
 {
-       assert(_probe);
+       assert(_channel);
 }
 
 void Signal::set_name(QString name)
@@ -77,32 +79,48 @@ void Signal::set_name(QString name)
 
 bool Signal::enabled() const
 {
-       return _probe->enabled;
+       return _channel->enabled;
 }
 
 void Signal::enable(bool enable)
 {
-       _dev_inst->enable_probe(_probe, enable);
+       _dev_inst->enable_channel(_channel, enable);
        visibility_changed();
 }
 
-const sr_channel* Signal::probe() const
+const sr_channel* Signal::channel() const
 {
-       return _probe;
+       return _channel;
 }
 
 void Signal::populate_popup_form(QWidget *parent, QFormLayout *form)
 {
+       int index;
+
        _name_widget = new QComboBox(parent);
        _name_widget->setEditable(true);
 
-       for(unsigned int i = 0; i < countof(ProbeNames); i++)
-               _name_widget->insertItem(i, ProbeNames[i]);
-       _name_widget->setEditText(_probe->name);
+       for(unsigned int i = 0; i < countof(ChannelNames); i++)
+               _name_widget->insertItem(i, ChannelNames[i]);
+
+       index = _name_widget->findText(_name, Qt::MatchExactly);
+
+       if (index == -1) {
+               _name_widget->insertItem(0, _name);
+               _name_widget->setCurrentIndex(0);
+       } else {
+               _name_widget->setCurrentIndex(index);
+       }
+
+       _name_widget->lineEdit()->selectAll();
+       _name_widget->setFocus();
 
        connect(_name_widget, SIGNAL(editTextChanged(const QString&)),
                this, SLOT(on_text_changed(const QString&)));
 
+       // We want to close the popup when the Enter key was pressed.
+       _name_widget->installEventFilter(this);
+
        form->addRow(tr("Name"), _name_widget);
 
        add_colour_option(parent, form);
@@ -122,6 +140,24 @@ QMenu* Signal::create_context_menu(QWidget *parent)
        return menu;
 }
 
+bool Signal::eventFilter(QObject *obj, QEvent *evt)
+{
+       QKeyEvent *keyEvent;
+
+       (void)obj;
+
+       if (evt->type() == QEvent::KeyPress) {
+               keyEvent = static_cast<QKeyEvent*>(evt);
+               if (keyEvent->key() == Qt::Key_Enter ||
+                   keyEvent->key() == Qt::Key_Return) {
+                       close_popup();
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 void Signal::delete_pressed()
 {
        on_disable();