X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fbool.cpp;h=0cd1604612661730348acd099580f7ac02947725;hp=c057d61ebcebc401ffe70122c751b8f164ca267e;hb=b571a8e7e0dc3e3b6daa58f27050e76466f006dd;hpb=8dbbc7f0b9ea59d0f0d62225772f8a56eee125f5 diff --git a/pv/prop/bool.cpp b/pv/prop/bool.cpp index c057d61e..0cd16046 100644 --- a/pv/prop/bool.cpp +++ b/pv/prop/bool.cpp @@ -14,26 +14,24 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ -#include +#include #include +#include -#include "bool.h" +#include + +#include "bool.hpp" namespace pv { namespace prop { -Bool::Bool(QString name, Getter getter, Setter setter) : - Property(name, getter, setter), - check_box_(NULL) -{ -} - -Bool::~Bool() +Bool::Bool(QString name, QString desc, Getter getter, Setter setter) : + Property(name, desc, getter, setter), + check_box_(nullptr) { } @@ -43,17 +41,21 @@ QWidget* Bool::get_widget(QWidget *parent, bool auto_commit) return check_box_; if (!getter_) - return NULL; + return nullptr; - Glib::VariantBase variant = getter_(); - if (!variant.gobj()) - return NULL; - - bool value = Glib::VariantBase::cast_dynamic>( - variant).get(); + try { + Glib::VariantBase variant = getter_(); + if (!variant.gobj()) + return nullptr; + } catch (const sigrok::Error &e) { + qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what()); + return nullptr; + } check_box_ = new QCheckBox(name(), parent); - check_box_->setCheckState(value ? Qt::Checked : Qt::Unchecked); + check_box_->setToolTip(desc()); + + update_widget(); if (auto_commit) connect(check_box_, SIGNAL(stateChanged(int)), @@ -67,6 +69,27 @@ bool Bool::labeled_widget() const return true; } +void Bool::update_widget() +{ + if (!check_box_) + return; + + Glib::VariantBase variant; + + try { + variant = getter_(); + } catch (const sigrok::Error &e) { + qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what()); + return; + } + + assert(variant.gobj()); + bool value = Glib::VariantBase::cast_dynamic>( + variant).get(); + + check_box_->setCheckState(value ? Qt::Checked : Qt::Unchecked); +} + void Bool::commit() { assert(setter_); @@ -74,8 +97,7 @@ void Bool::commit() if (!check_box_) return; - setter_(Glib::Variant::create( - check_box_->checkState() == Qt::Checked)); + setter_(Glib::Variant::create(check_box_->checkState() == Qt::Checked)); } void Bool::on_state_changed(int) @@ -83,5 +105,5 @@ void Bool::on_state_changed(int) commit(); } -} // prop -} // pv +} // namespace prop +} // namespace pv