X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fbinding%2Fbinding.cpp;fp=pv%2Fbinding%2Fbinding.cpp;h=fccb96be54b83e6770a795d219aae7ac07125bae;hp=0000000000000000000000000000000000000000;hb=61703a0124c7ace84caf415f7d491a3ad6f42599;hpb=c1035a1452fa2aec5414975e83e531c10504b80c diff --git a/pv/binding/binding.cpp b/pv/binding/binding.cpp new file mode 100644 index 0000000..fccb96b --- /dev/null +++ b/pv/binding/binding.cpp @@ -0,0 +1,92 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2012 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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 + */ + +#include + +#include + +#include + +#include "binding.hpp" + +using std::shared_ptr; + +namespace pv { +namespace binding { + +const std::vector< std::shared_ptr >& Binding::properties() +{ + return properties_; +} + +void Binding::commit() +{ + for (shared_ptr p : properties_) { + assert(p); + p->commit(); + } +} + +void Binding::add_properties_to_form(QFormLayout *layout, + bool auto_commit) const +{ + assert(layout); + + for (shared_ptr p : properties_) + { + assert(p); + + QWidget *const widget = p->get_widget(layout->parentWidget(), + auto_commit); + if (p->labeled_widget()) + layout->addRow(widget); + else + layout->addRow(p->name(), widget); + } +} + +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; +} + +QString Binding::print_gvariant(Glib::VariantBase gvar) +{ + QString s; + + if (!gvar.gobj()) + s = QString::fromStdString("(null)"); + else if (gvar.is_of_type(Glib::VariantType("s"))) + s = QString::fromStdString( + Glib::VariantBase::cast_dynamic>( + gvar).get()); + else + s = QString::fromStdString(gvar.print()); + + return s; +} + +} // binding +} // pv