- 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);
-
- return _spin_box;
+ if (spin_box_)
+ return spin_box_;
+
+ if (!getter_)
+ return nullptr;
+
+ 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;
+ }
+
+ 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_);
+
+ update_widget();
+
+ if (auto_commit)
+ connect(spin_box_, SIGNAL(valueChanged(double)),
+ this, SLOT(on_value_changed(double)));
+
+ return spin_box_;
+}
+
+void Double::update_widget()
+{
+ if (!spin_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());
+
+ double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
+ variant).get();
+ spin_box_->setValue(value);