X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fprop%2Fbinding%2Fbinding.cpp;h=3a6c73fb09afbdc162e181d54b7718c62d45be5b;hp=3b15f5a9ebfed1858258461b63bb0b33c62ba15c;hb=5b1994c45194a95069dfcadf637723f3db8249da;hpb=de1d99bbe58f825e30048baa48a9439c01686f10 diff --git a/pv/prop/binding/binding.cpp b/pv/prop/binding/binding.cpp index 3b15f5a9..3a6c73fb 100644 --- a/pv/prop/binding/binding.cpp +++ b/pv/prop/binding/binding.cpp @@ -18,52 +18,75 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include - #include -#include "binding.h" +#include #include -using namespace boost; +#include "binding.h" + +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; + BOOST_FOREACH(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) + BOOST_FOREACH(shared_ptr p, _properties) { assert(p); - const QString label = p->labeled_widget() ? QString() : p->name(); - layout->addRow(label, 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