]> sigrok.org Git - pulseview.git/blobdiff - pv/prop/enum.cpp
pv::prop::Enum: Do not create a widget if the initial value could not be retrieved
[pulseview.git] / pv / prop / enum.cpp
index 2249b570851fd183aeb943cb857923584902608a..9044c6bae9d3c6335589c26e7be65835186a7b81 100644 (file)
@@ -24,8 +24,8 @@
 
 #include "enum.h"
 
-using namespace boost;
-using namespace std;
+using std::pair;
+using std::vector;
 
 namespace pv {
 namespace prop {
@@ -45,12 +45,14 @@ 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++) {
@@ -62,6 +64,10 @@ QWidget* Enum::get_widget(QWidget *parent)
 
        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*>());
 }
 
+void Enum::on_current_item_changed(int)
+{
+       commit();
+}
+
 } // prop
 } // pv