X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fprop%2Fdouble.cpp;h=d059755843112be79d6e014672f05e0e31feb806;hb=2acdb232d6bb452cfdfaea3ef5218fb4da592329;hp=39e205ee691f2910dd7899ac958ae5d9c69bde3f;hpb=f459c5400e067c4389c472b84194d760e7bfd585;p=pulseview.git diff --git a/pv/prop/double.cpp b/pv/prop/double.cpp index 39e205e..d059755 100644 --- a/pv/prop/double.cpp +++ b/pv/prop/double.cpp @@ -22,10 +22,10 @@ #include -#include "double.h" +#include "double.hpp" -using namespace std; -using namespace boost; +using boost::optional; +using std::pair; namespace pv { namespace prop { @@ -38,11 +38,11 @@ Double::Double(QString name, Getter getter, Setter setter) : Property(name, getter, setter), - _decimals(decimals), - _suffix(suffix), - _range(range), - _step(step), - _spin_box(NULL) + decimals_(decimals), + suffix_(suffix), + range_(range), + step_(step), + spin_box_(NULL) { } @@ -50,37 +50,51 @@ Double::~Double() { } -QWidget* Double::get_widget(QWidget *parent) +QWidget* Double::get_widget(QWidget *parent, bool auto_commit) { - if (_spin_box) - return _spin_box; + if (spin_box_) + return spin_box_; - _spin_box = new QDoubleSpinBox(parent); - _spin_box->setDecimals(_decimals); - _spin_box->setSuffix(_suffix); - if (_range) - _spin_box->setRange(_range->first, _range->second); - if (_step) - _spin_box->setSingleStep(*_step); + if (!getter_) + return NULL; - GVariant *const value = _getter ? _getter() : NULL; + Glib::VariantBase variant = getter_(); + if (!variant.gobj()) + return NULL; - if (value) { - _spin_box->setValue(g_variant_get_double(value)); - g_variant_unref(value); - } + double value = Glib::VariantBase::cast_dynamic>( + variant).get(); - return _spin_box; + spin_box_ = new QDoubleSpinBox(parent); + spin_box_->setDecimals(decimals_); + spin_box_->setSuffix(suffix_); + if (range_) + spin_box_->setRange(range_->first, range_->second); + if (step_) + spin_box_->setSingleStep(*step_); + + spin_box_->setValue(value); + + if (auto_commit) + connect(spin_box_, SIGNAL(valueChanged(double)), + this, SLOT(on_value_changed(double))); + + return spin_box_; } void Double::commit() { - assert(_setter); + assert(setter_); - if (!_spin_box) + 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