X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fdouble.cpp;h=54540bc68ded41c0575c3202726ac383665b5814;hb=e8d009288de28cb194bc7964f96677c2baf900c9;hp=d7c79ca7db19ce6481d3b8293c06848fcd5364d0;hpb=9f6af8bd3a6bc12f9b32b91cd2a173a8a7763f5c;p=pulseview.git diff --git a/pv/prop/double.cpp b/pv/prop/double.cpp index d7c79ca..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 { @@ -35,33 +35,49 @@ Double::Double(QString name, QString suffix, optional< pair > range, optional step, - function getter, - function setter) : - Property(name), + Getter getter, + Setter setter) : + Property(name, getter, setter), _decimals(decimals), _suffix(suffix), _range(range), _step(step), - _getter(getter), - _setter(setter), _spin_box(NULL) { } -QWidget* Double::get_widget(QWidget *parent) +Double::~Double() { - if(_spin_box) +} + +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); - if(_range) + if (_range) _spin_box->setRange(_range->first, _range->second); - if(_step) + if (_step) _spin_box->setSingleStep(*_step); - _spin_box->setValue(_getter ? _getter() : 0.0); + _spin_box->setValue(value); + + if (auto_commit) + connect(_spin_box, SIGNAL(valueChanged(double)), + this, SLOT(on_value_changed(double))); return _spin_box; } @@ -70,10 +86,15 @@ void Double::commit() { assert(_setter); - if(!_spin_box) + if (!_spin_box) return; - _setter(_spin_box->value()); + _setter(Glib::Variant::create(_spin_box->value())); +} + +void Double::on_value_changed(double) +{ + commit(); } } // prop