]> sigrok.org Git - pulseview.git/blame - pv/binding/binding.cpp
device.cpp: Add SR_CONF_EXTERNAL_CLOCK_SOURCE.
[pulseview.git] / pv / binding / binding.cpp
CommitLineData
c8df6005
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
c8df6005
JH
18 */
19
f9abf97e
JH
20#include <cassert>
21
8481fbdf 22#include <QFormLayout>
894c4b52 23#include <QLabel>
8481fbdf 24
2acdb232 25#include <pv/prop/property.hpp>
8481fbdf 26
2acdb232 27#include "binding.hpp"
c8df6005 28
f9abf97e 29using std::shared_ptr;
6f925ba9
UH
30using std::string;
31using std::vector;
8481fbdf 32
c8df6005 33namespace pv {
c8df6005
JH
34namespace binding {
35
6f925ba9 36const vector< shared_ptr<prop::Property> >& Binding::properties()
3a69ef6b 37{
8dbbc7f0 38 return properties_;
3a69ef6b
JH
39}
40
8481fbdf
JH
41void Binding::commit()
42{
8dbbc7f0 43 for (shared_ptr<pv::prop::Property> p : properties_) {
8481fbdf
JH
44 assert(p);
45 p->commit();
46 }
47}
48
f904b412
JH
49void Binding::add_properties_to_form(QFormLayout *layout,
50 bool auto_commit) const
8481fbdf 51{
4206fe26 52 assert(layout);
8481fbdf 53
2ad82c2e 54 for (shared_ptr<pv::prop::Property> p : properties_) {
8481fbdf 55 assert(p);
e7e57b25 56
dbed5609 57 QWidget *const widget = p->get_widget(layout->parentWidget(), auto_commit);
894c4b52 58 if (p->labeled_widget()) {
e7e57b25 59 layout->addRow(widget);
894c4b52
UH
60 } else {
61 auto *lbl = new QLabel(p->name());
62 lbl->setToolTip(p->desc());
63 layout->addRow(lbl, widget);
64 }
8481fbdf 65 }
4206fe26 66}
8481fbdf 67
f904b412
JH
68QWidget* Binding::get_property_form(QWidget *parent,
69 bool auto_commit) const
4206fe26
JH
70{
71 QWidget *const form = new QWidget(parent);
72 QFormLayout *const layout = new QFormLayout(form);
73 form->setLayout(layout);
f904b412 74 add_properties_to_form(layout, auto_commit);
8481fbdf
JH
75 return form;
76}
77
dbed5609
SA
78void Binding::update_property_widgets()
79{
80 for (shared_ptr<pv::prop::Property> p : properties_) {
81 assert(p);
82 p->update_widget();
83 }
84}
85
e8d00928 86QString Binding::print_gvariant(Glib::VariantBase gvar)
5b1994c4
JH
87{
88 QString s;
89
e8d00928
ML
90 if (!gvar.gobj())
91 s = QString::fromStdString("(null)");
92 else if (gvar.is_of_type(Glib::VariantType("s")))
93 s = QString::fromStdString(
dbed5609 94 Glib::VariantBase::cast_dynamic<Glib::Variant<string>>(gvar).get());
5b1994c4 95 else
e8d00928 96 s = QString::fromStdString(gvar.print());
5b1994c4
JH
97
98 return s;
99}
100
870ea3db
UH
101} // namespace binding
102} // namespace pv