X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fenum.cpp;h=9044c6bae9d3c6335589c26e7be65835186a7b81;hp=ced2f2bb0c79664b98af758a2ecf42b6d711316a;hb=f45925927eba2b93f367e63f5e3b651e24c67eb3;hpb=0912f8a7b0fde306f2616fef3c63ce742006602d diff --git a/pv/prop/enum.cpp b/pv/prop/enum.cpp index ced2f2bb..9044c6ba 100644 --- a/pv/prop/enum.cpp +++ b/pv/prop/enum.cpp @@ -24,8 +24,8 @@ #include "enum.h" -using namespace boost; -using namespace std; +using std::pair; +using std::vector; namespace pv { namespace prop { @@ -45,23 +45,29 @@ Enum::~Enum() g_variant_unref(_values[i].first); } -QWidget* Enum::get_widget(QWidget *parent) +QWidget* Enum::get_widget(QWidget *parent, bool auto_commit) { if (_selector) return _selector; GVariant *const value = _getter ? _getter() : NULL; + if (!value) + return NULL; _selector = new QComboBox(parent); for (unsigned int i = 0; i < _values.size(); i++) { const pair &v = _values[i]; _selector->addItem(v.second, qVariantFromValue((void*)v.first)); - if (value && g_variant_compare(v.first, value) == 0) + if (value && g_variant_equal(v.first, value)) _selector->setCurrentIndex(i); } g_variant_unref(value); + if (auto_commit) + connect(_selector, SIGNAL(currentIndexChanged(int)), + this, SLOT(on_current_item_changed(int))); + return _selector; } @@ -79,5 +85,10 @@ void Enum::commit() _setter((GVariant*)_selector->itemData(index).value()); } +void Enum::on_current_item_changed(int) +{ + commit(); +} + } // prop } // pv