X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fprop%2Fbool.cpp;h=3281de78cbf90841e7480c238fa8781ebeef9c36;hb=8d466c03419819b02bbbcd591ff6c2847f507d6f;hp=ac142fd440403c6b015c441f6e6b1d13ae3923aa;hpb=819f4c25391a9c74d3d2f528d462142d5c4aad4d;p=pulseview.git diff --git a/pv/prop/bool.cpp b/pv/prop/bool.cpp index ac142fd4..3281de78 100644 --- a/pv/prop/bool.cpp +++ b/pv/prop/bool.cpp @@ -22,41 +22,40 @@ #include -#include "bool.h" +#include "bool.hpp" namespace pv { namespace prop { Bool::Bool(QString name, Getter getter, Setter setter) : Property(name, getter, setter), - _check_box(NULL) -{ -} - -Bool::~Bool() + check_box_(nullptr) { } QWidget* Bool::get_widget(QWidget *parent, bool auto_commit) { - if (_check_box) - return _check_box; + if (check_box_) + return check_box_; + + if (!getter_) + return nullptr; - _check_box = new QCheckBox(name(), parent); + Glib::VariantBase variant = getter_(); + if (!variant.gobj()) + return nullptr; - GVariant *const value = _getter ? _getter() : NULL; + bool value = Glib::VariantBase::cast_dynamic>( + variant).get(); - if (value) { - _check_box->setCheckState(g_variant_get_boolean(value) ? - Qt::Checked : Qt::Unchecked); - g_variant_unref(value); - } + check_box_ = new QCheckBox(name(), parent); + check_box_->setCheckState(value ? Qt::Checked : Qt::Unchecked); if (auto_commit) - connect(_check_box, SIGNAL(stateChanged(int)), + connect(check_box_, SIGNAL(stateChanged(int)), this, SLOT(on_state_changed(int))); - return _check_box; + return check_box_; } bool Bool::labeled_widget() const @@ -66,13 +65,13 @@ bool Bool::labeled_widget() const void Bool::commit() { - assert(_setter); + assert(setter_); - if (!_check_box) + if (!check_box_) return; - _setter(g_variant_new_boolean( - _check_box->checkState() == Qt::Checked)); + setter_(Glib::Variant::create( + check_box_->checkState() == Qt::Checked)); } void Bool::on_state_changed(int)