X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fdouble.cpp;h=54540bc68ded41c0575c3202726ac383665b5814;hb=e8d009288de28cb194bc7964f96677c2baf900c9;hp=39e205ee691f2910dd7899ac958ae5d9c69bde3f;hpb=f459c5400e067c4389c472b84194d760e7bfd585;p=pulseview.git diff --git a/pv/prop/double.cpp b/pv/prop/double.cpp index 39e205e..54540bc 100644 --- a/pv/prop/double.cpp +++ b/pv/prop/double.cpp @@ -24,8 +24,8 @@ #include "double.h" -using namespace std; -using namespace boost; +using boost::optional; +using std::pair; namespace pv { namespace prop { @@ -50,11 +50,21 @@ Double::~Double() { } -QWidget* Double::get_widget(QWidget *parent) +QWidget* Double::get_widget(QWidget *parent, bool auto_commit) { if (_spin_box) return _spin_box; + if (!_getter) + return NULL; + + Glib::VariantBase variant = _getter(); + if (!variant.gobj()) + return NULL; + + double value = Glib::VariantBase::cast_dynamic>( + variant).get(); + _spin_box = new QDoubleSpinBox(parent); _spin_box->setDecimals(_decimals); _spin_box->setSuffix(_suffix); @@ -63,12 +73,11 @@ QWidget* Double::get_widget(QWidget *parent) if (_step) _spin_box->setSingleStep(*_step); - GVariant *const value = _getter ? _getter() : NULL; + _spin_box->setValue(value); - if (value) { - _spin_box->setValue(g_variant_get_double(value)); - g_variant_unref(value); - } + if (auto_commit) + connect(_spin_box, SIGNAL(valueChanged(double)), + this, SLOT(on_value_changed(double))); return _spin_box; } @@ -80,7 +89,12 @@ void Double::commit() if (!_spin_box) return; - _setter(g_variant_new_double(_spin_box->value())); + _setter(Glib::Variant::create(_spin_box->value())); +} + +void Double::on_value_changed(double) +{ + commit(); } } // prop