X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fbinding%2Fbinding.cpp;h=1a5eb5ec097a32994d04e3057db5090bd41aee77;hp=5d411686f4a820f8ea686e191091f1b6d8c5500b;hb=d9aecf1fcd9af471db3b59de7efc65b9632a6d79;hpb=9ba4ca3540ace02b1b5439ec2f4584f82f2aca77 diff --git a/pv/prop/binding/binding.cpp b/pv/prop/binding/binding.cpp index 5d411686..1a5eb5ec 100644 --- a/pv/prop/binding/binding.cpp +++ b/pv/prop/binding/binding.cpp @@ -19,50 +19,72 @@ */ #include -#include -#include +#include #include "binding.h" -#include - -using namespace boost; +using boost::shared_ptr; namespace pv { namespace prop { namespace binding { -Binding::Binding() : - _form(NULL) +const std::vector< boost::shared_ptr >& Binding::properties() { + return _properties; } -QWidget* Binding::get_form(QWidget *parent) +void Binding::commit() { - if (_form) - return _form; + for (shared_ptr p : _properties) { + assert(p); + p->commit(); + } +} - _form = new QWidget(parent); - QFormLayout *const layout = new QFormLayout(_form); - _form->setLayout(layout); +void Binding::add_properties_to_form(QFormLayout *layout, + bool auto_commit) const +{ + assert(layout); - BOOST_FOREACH(shared_ptr p, _properties) + for (shared_ptr p : _properties) { assert(p); - layout->addRow(p->name(), p->get_widget(_form)); + + QWidget *const widget = p->get_widget(layout->parentWidget(), + auto_commit); + if (p->labeled_widget()) + layout->addRow(widget); + else + layout->addRow(p->name(), widget); } +} - return _form; +QWidget* Binding::get_property_form(QWidget *parent, + bool auto_commit) const +{ + QWidget *const form = new QWidget(parent); + QFormLayout *const layout = new QFormLayout(form); + form->setLayout(layout); + add_properties_to_form(layout, auto_commit); + return form; } -void Binding::commit() +QString Binding::print_gvariant(GVariant *const gvar) { - BOOST_FOREACH(shared_ptr p, _properties) + QString s; + + if (g_variant_is_of_type(gvar, G_VARIANT_TYPE("s"))) + s = QString::fromUtf8(g_variant_get_string(gvar, NULL)); + else { - assert(p); - p->commit(); + gchar *const text = g_variant_print(gvar, FALSE); + s = QString::fromUtf8(text); + g_free(text); } + + return s; } } // binding