2 * This file is part of the PulseView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include <QFormLayout>
23 #include <QHBoxLayout>
26 #include <QPushButton>
28 #include <pv/prop/property.hpp>
30 #include "binding.hpp"
32 using std::shared_ptr;
39 const vector< shared_ptr<prop::Property> >& Binding::properties()
44 void Binding::commit()
46 for (shared_ptr<pv::prop::Property> p : properties_) {
52 void Binding::add_properties_to_form(QFormLayout *layout, bool auto_commit)
58 for (shared_ptr<pv::prop::Property> p : properties_) {
62 QLabel *help_lbl = nullptr;
64 if (p->desc().isEmpty()) {
65 widget = p->get_widget(layout->parentWidget(), auto_commit);
67 QPushButton *help_btn = new QPushButton();
68 help_btn->setFlat(true);
69 help_btn->setIcon(QIcon(":/icons/help-browser.png"));
70 help_btn->setToolTip(p->desc());
71 connect(help_btn, SIGNAL(clicked(bool)),
72 this, SLOT(on_help_clicked()));
74 QHBoxLayout *layout = new QHBoxLayout();
75 layout->setContentsMargins(0, 0, 0, 0);
76 layout->addWidget(p->get_widget(layout->parentWidget(), auto_commit));
77 layout->addWidget(help_btn, 0, Qt::AlignRight);
79 widget = new QWidget();
80 widget->setLayout(layout);
82 help_lbl = new QLabel(p->desc());
83 help_lbl->setVisible(false);
84 help_lbl->setWordWrap(true);
85 help_labels_[help_btn] = help_lbl;
88 if (p->labeled_widget()) {
89 layout->addRow(widget);
91 auto *lbl = new QLabel(p->name());
92 lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
93 layout->addRow(lbl, widget);
97 layout->addRow(help_lbl);
101 QWidget* Binding::get_property_form(QWidget *parent, bool auto_commit)
103 QWidget *const form = new QWidget(parent);
104 QFormLayout *const layout = new QFormLayout(form);
105 form->setLayout(layout);
106 add_properties_to_form(layout, auto_commit);
110 void Binding::update_property_widgets()
112 for (shared_ptr<pv::prop::Property> p : properties_) {
118 QString Binding::print_gvariant(Glib::VariantBase gvar)
123 s = QString::fromStdString("(null)");
124 else if (gvar.is_of_type(Glib::VariantType("s")))
125 s = QString::fromStdString(
126 Glib::VariantBase::cast_dynamic<Glib::Variant<string>>(gvar).get());
128 s = QString::fromStdString(gvar.print());
133 void Binding::on_help_clicked()
135 QPushButton *btn = qobject_cast<QPushButton*>(QObject::sender());
138 QLabel *lbl = help_labels_.at(btn);
139 lbl->setVisible(!lbl->isVisible());
142 } // namespace binding