]>
Commit | Line | Data |
---|---|---|
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 | 29 | using std::shared_ptr; |
6f925ba9 UH |
30 | using std::string; |
31 | using std::vector; | |
8481fbdf | 32 | |
c8df6005 | 33 | namespace pv { |
c8df6005 JH |
34 | namespace binding { |
35 | ||
6f925ba9 | 36 | const vector< shared_ptr<prop::Property> >& Binding::properties() |
3a69ef6b | 37 | { |
8dbbc7f0 | 38 | return properties_; |
3a69ef6b JH |
39 | } |
40 | ||
8481fbdf JH |
41 | void 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 |
49 | void 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 JH |
56 | |
57 | QWidget *const widget = p->get_widget(layout->parentWidget(), | |
58 | auto_commit); | |
894c4b52 | 59 | if (p->labeled_widget()) { |
e7e57b25 | 60 | layout->addRow(widget); |
894c4b52 UH |
61 | } else { |
62 | auto *lbl = new QLabel(p->name()); | |
63 | lbl->setToolTip(p->desc()); | |
64 | layout->addRow(lbl, widget); | |
65 | } | |
8481fbdf | 66 | } |
4206fe26 | 67 | } |
8481fbdf | 68 | |
f904b412 JH |
69 | QWidget* Binding::get_property_form(QWidget *parent, |
70 | bool auto_commit) const | |
4206fe26 JH |
71 | { |
72 | QWidget *const form = new QWidget(parent); | |
73 | QFormLayout *const layout = new QFormLayout(form); | |
74 | form->setLayout(layout); | |
f904b412 | 75 | add_properties_to_form(layout, auto_commit); |
8481fbdf JH |
76 | return form; |
77 | } | |
78 | ||
e8d00928 | 79 | QString Binding::print_gvariant(Glib::VariantBase gvar) |
5b1994c4 JH |
80 | { |
81 | QString s; | |
82 | ||
e8d00928 ML |
83 | if (!gvar.gobj()) |
84 | s = QString::fromStdString("(null)"); | |
85 | else if (gvar.is_of_type(Glib::VariantType("s"))) | |
86 | s = QString::fromStdString( | |
6f925ba9 | 87 | Glib::VariantBase::cast_dynamic<Glib::Variant<string>>( |
e8d00928 | 88 | gvar).get()); |
5b1994c4 | 89 | else |
e8d00928 | 90 | s = QString::fromStdString(gvar.print()); |
5b1994c4 JH |
91 | |
92 | return s; | |
93 | } | |
94 | ||
870ea3db UH |
95 | } // namespace binding |
96 | } // namespace pv |