for (shared_ptr<pv::prop::Property> p : properties_) {
assert(p);
- QWidget *const widget = p->get_widget(layout->parentWidget(),
- auto_commit);
+ QWidget *const widget = p->get_widget(layout->parentWidget(), auto_commit);
if (p->labeled_widget()) {
layout->addRow(widget);
} else {
return form;
}
+void Binding::update_property_widgets()
+{
+ for (shared_ptr<pv::prop::Property> p : properties_) {
+ assert(p);
+ p->update_widget();
+ }
+}
+
QString Binding::print_gvariant(Glib::VariantBase gvar)
{
QString s;
s = QString::fromStdString("(null)");
else if (gvar.is_of_type(Glib::VariantType("s")))
s = QString::fromStdString(
- Glib::VariantBase::cast_dynamic<Glib::Variant<string>>(
- gvar).get());
+ Glib::VariantBase::cast_dynamic<Glib::Variant<string>>(gvar).get());
else
s = QString::fromStdString(gvar.print());
QWidget* get_property_form(QWidget *parent,
bool auto_commit = false) const;
+ void update_property_widgets();
+
static QString print_gvariant(Glib::VariantBase gvar);
protected:
return binding_;
}
+void DeviceOptions::show()
+{
+ // Update device config widgets with the current values supplied by the
+ // driver before actually showing the popup dialog
+ binding_.update_property_widgets();
+
+ Popup::show();
+}
+
} // namespace popups
} // namespace pv
pv::binding::Device& binding();
+ virtual void show();
+
private:
shared_ptr<sigrok::Device> device_;
if (!variant.gobj())
return nullptr;
- bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
- variant).get();
-
check_box_ = new QCheckBox(name(), parent);
check_box_->setToolTip(desc());
- check_box_->setCheckState(value ? Qt::Checked : Qt::Unchecked);
+
+ update_widget();
if (auto_commit)
connect(check_box_, SIGNAL(stateChanged(int)),
return true;
}
+void Bool::update_widget()
+{
+ if (!check_box_)
+ return;
+
+ Glib::VariantBase variant = getter_();
+ assert(variant.gobj());
+
+ bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
+ variant).get();
+
+ check_box_->setCheckState(value ? Qt::Checked : Qt::Unchecked);
+}
+
void Bool::commit()
{
assert(setter_);
QWidget* get_widget(QWidget *parent, bool auto_commit);
bool labeled_widget() const;
+ void update_widget();
void commit();
if (!variant.gobj())
return nullptr;
- double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
- variant).get();
-
spin_box_ = new QDoubleSpinBox(parent);
spin_box_->setDecimals(decimals_);
spin_box_->setSuffix(suffix_);
if (step_)
spin_box_->setSingleStep(*step_);
- spin_box_->setValue(value);
+ update_widget();
if (auto_commit)
connect(spin_box_, SIGNAL(valueChanged(double)),
return spin_box_;
}
+void Double::update_widget()
+{
+ if (!spin_box_)
+ return;
+
+ Glib::VariantBase variant = getter_();
+ assert(variant.gobj());
+
+ double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
+ variant).get();
+ spin_box_->setValue(value);
+}
+
void Double::commit()
{
assert(setter_);
virtual ~Double() = default;
QWidget* get_widget(QWidget *parent, bool auto_commit);
+ void update_widget();
void commit();
for (unsigned int i = 0; i < values_.size(); i++) {
const pair<Glib::VariantBase, QString> &v = values_[i];
selector_->addItem(v.second, qVariantFromValue(v.first));
- if (v.first.equal(variant))
- selector_->setCurrentIndex(i);
}
+ update_widget();
+
if (auto_commit)
connect(selector_, SIGNAL(currentIndexChanged(int)),
this, SLOT(on_current_item_changed(int)));
return selector_;
}
+void Enum::update_widget()
+{
+ if (!selector_)
+ return;
+
+ Glib::VariantBase variant = getter_();
+ assert(variant.gobj());
+
+ for (unsigned int i = 0; i < values_.size(); i++) {
+ const pair<Glib::VariantBase, QString> &v = values_[i];
+ if (v.first.equal(variant))
+ selector_->setCurrentIndex(i);
+ }
+}
+
void Enum::commit()
{
assert(setter_);
virtual ~Enum() = default;
QWidget* get_widget(QWidget *parent, bool auto_commit);
+ void update_widget();
void commit();
QWidget* Int::get_widget(QWidget *parent, bool auto_commit)
{
- int64_t int_val = 0, range_min = 0;
+ int64_t range_min = 0;
uint64_t range_max = 0;
if (spin_box_)
assert(type);
if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) {
- int_val = g_variant_get_byte(value);
range_min = 0, range_max = UINT8_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) {
- int_val = g_variant_get_int16(value);
range_min = INT16_MIN, range_max = INT16_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) {
- int_val = g_variant_get_uint16(value);
range_min = 0, range_max = UINT16_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) {
- int_val = g_variant_get_int32(value);
range_min = INT32_MIN, range_max = INT32_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) {
- int_val = g_variant_get_uint32(value);
range_min = 0, range_max = UINT32_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) {
- int_val = g_variant_get_int64(value);
range_min = INT64_MIN, range_max = INT64_MAX;
} else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) {
- int_val = g_variant_get_uint64(value);
range_min = 0, range_max = UINT64_MAX;
} else {
// Unexpected value type.
else
spin_box_->setRange((int)range_min, (int)range_max);
- spin_box_->setValue((int)int_val);
+ update_widget();
if (auto_commit)
connect(spin_box_, SIGNAL(valueChanged(int)),
return spin_box_;
}
+void Int::update_widget()
+{
+ if (!spin_box_)
+ return;
+
+ value_ = getter_();
+ GVariant *value = value_.gobj();
+ assert(value);
+
+ const GVariantType *const type = g_variant_get_type(value);
+ assert(type);
+
+ int64_t int_val = 0;
+
+ if (g_variant_type_equal(type, G_VARIANT_TYPE_BYTE)) {
+ int_val = g_variant_get_byte(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT16)) {
+ int_val = g_variant_get_int16(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT16)) {
+ int_val = g_variant_get_uint16(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT32)) {
+ int_val = g_variant_get_int32(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT32)) {
+ int_val = g_variant_get_uint32(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_INT64)) {
+ int_val = g_variant_get_int64(value);
+ } else if (g_variant_type_equal(type, G_VARIANT_TYPE_UINT64)) {
+ int_val = g_variant_get_uint64(value);
+ } else {
+ // Unexpected value type.
+ assert(false);
+ }
+
+ spin_box_->setValue((int)int_val);
+}
+
void Int::commit()
{
assert(setter_);
virtual ~Int() = default;
QWidget* get_widget(QWidget *parent, bool auto_commit);
+ void update_widget();
void commit();
const QString& name() const;
const QString& desc() const;
- virtual QWidget* get_widget(QWidget *parent,
- bool auto_commit = false) = 0;
+ virtual QWidget* get_widget(QWidget *parent, bool auto_commit = false) = 0;
virtual bool labeled_widget() const;
+ virtual void update_widget() = 0;
virtual void commit() = 0;
if (!variant.gobj())
return nullptr;
- string value = Glib::VariantBase::cast_dynamic<Glib::Variant<ustring>>(
- variant).get();
-
line_edit_ = new QLineEdit(parent);
- line_edit_->setText(QString::fromStdString(value));
+
+ update_widget();
if (auto_commit)
connect(line_edit_, SIGNAL(textEdited(const QString&)),
return line_edit_;
}
+void String::update_widget()
+{
+ if (!line_edit_)
+ return;
+
+ Glib::VariantBase variant = getter_();
+ assert(variant.gobj());
+
+ string value = Glib::VariantBase::cast_dynamic<Glib::Variant<ustring>>(
+ variant).get();
+
+ line_edit_->setText(QString::fromStdString(value));
+}
+
void String::commit()
{
assert(setter_);
String(QString name, QString desc, Getter getter, Setter setter);
QWidget* get_widget(QWidget *parent, bool auto_commit);
+ void update_widget();
void commit();
bool eventFilter(QObject *obj, QEvent *event);
- void show();
+ virtual void show();
private:
bool space_for_arrow() const;