#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 {
};
Signal::Signal(shared_ptr<pv::device::DevInst> dev_inst,
- const sr_probe *const probe) :
+ const sr_channel *const probe) :
Trace(probe->name),
_dev_inst(dev_inst),
_probe(probe),
visibility_changed();
}
-const sr_probe* Signal::probe() const
+const sr_channel* Signal::probe() const
{
return _probe;
}
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);
+
+ 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);
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();