From de1d99bbe58f825e30048baa48a9439c01686f10 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 7 Apr 2013 18:56:20 +0100 Subject: [PATCH] Added Bool property and bound to SR_CONF_RLE --- CMakeLists.txt | 1 + pv/prop/binding/binding.cpp | 3 +- pv/prop/binding/deviceoptions.cpp | 27 +++++++++-- pv/prop/binding/deviceoptions.h | 1 + pv/prop/bool.cpp | 74 +++++++++++++++++++++++++++++++ pv/prop/bool.h | 48 ++++++++++++++++++++ pv/prop/property.cpp | 5 +++ pv/prop/property.h | 1 + 8 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 pv/prop/bool.cpp create mode 100644 pv/prop/bool.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b9f39d1..df201786 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,6 +102,7 @@ set(pulseview_SOURCES pv/dialogs/about.cpp pv/dialogs/connect.cpp pv/dialogs/deviceoptions.cpp + pv/prop/bool.cpp pv/prop/double.cpp pv/prop/enum.cpp pv/prop/property.cpp diff --git a/pv/prop/binding/binding.cpp b/pv/prop/binding/binding.cpp index 5d411686..3b15f5a9 100644 --- a/pv/prop/binding/binding.cpp +++ b/pv/prop/binding/binding.cpp @@ -50,7 +50,8 @@ QWidget* Binding::get_form(QWidget *parent) BOOST_FOREACH(shared_ptr p, _properties) { assert(p); - layout->addRow(p->name(), p->get_widget(_form)); + const QString label = p->labeled_widget() ? QString() : p->name(); + layout->addRow(label, p->get_widget(_form)); } return _form; diff --git a/pv/prop/binding/deviceoptions.cpp b/pv/prop/binding/deviceoptions.cpp index 90f474f2..50af3ed4 100644 --- a/pv/prop/binding/deviceoptions.cpp +++ b/pv/prop/binding/deviceoptions.cpp @@ -27,6 +27,7 @@ #include "deviceoptions.h" +#include #include #include @@ -54,11 +55,13 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : const struct sr_config_info *const info = sr_config_info_get(options[i]); + if (!info) + continue; + const int key = info->key; - if (!info || sr_config_list(_sdi->driver, key, - &gvar_list, _sdi) != SR_OK) - continue; + if(sr_config_list(_sdi->driver, key, &gvar_list, _sdi) != SR_OK) + gvar_list = NULL; const QString name(info->name); @@ -76,6 +79,10 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : bind_enum(name, key, gvar_list); break; + case SR_CONF_RLE: + bind_bool(name, key); + break; + case SR_CONF_TIMEBASE: bind_enum(name, key, gvar_list, print_timebase); break; @@ -85,7 +92,8 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : break; } - g_variant_unref(gvar_list); + if (gvar_list) + g_variant_unref(gvar_list); } g_variant_unref(gvar_opts); } @@ -109,6 +117,13 @@ void DeviceOptions::config_setter( qDebug() << "WARNING: Failed to set value of sample rate"; } +void DeviceOptions::bind_bool(const QString &name, int key) +{ + _properties.push_back(shared_ptr( + new Bool(name, bind(config_getter, _sdi, key), + bind(config_setter, _sdi, key, _1)))); +} + void DeviceOptions::bind_enum(const QString &name, int key, GVariant *const gvar_list, function printer) { @@ -116,6 +131,8 @@ void DeviceOptions::bind_enum(const QString &name, int key, GVariantIter iter; vector< pair > values; + assert(gvar_list); + g_variant_iter_init (&iter, gvar_list); while ((gvar = g_variant_iter_next_value (&iter))) values.push_back(make_pair(gvar, printer(gvar))); @@ -147,6 +164,8 @@ void DeviceOptions::bind_samplerate(const QString &name, { GVariant *gvar_list_samplerates; + assert(gvar_list); + if ((gvar_list_samplerates = g_variant_lookup_value(gvar_list, "samplerate-steps", G_VARIANT_TYPE("at")))) { diff --git a/pv/prop/binding/deviceoptions.h b/pv/prop/binding/deviceoptions.h index 28806f0f..f2344796 100644 --- a/pv/prop/binding/deviceoptions.h +++ b/pv/prop/binding/deviceoptions.h @@ -45,6 +45,7 @@ private: static void config_setter( const struct sr_dev_inst *sdi, int key, GVariant* value); + void bind_bool(const QString &name, int key); void bind_enum(const QString &name, int key, GVariant *const gvar_list, boost::function printer = print_gvariant); diff --git a/pv/prop/bool.cpp b/pv/prop/bool.cpp new file mode 100644 index 00000000..95cbb96e --- /dev/null +++ b/pv/prop/bool.cpp @@ -0,0 +1,74 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 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 "bool.h" + +using namespace std; +using namespace boost; + +namespace pv { +namespace prop { + +Bool::Bool(QString name, Getter getter, Setter setter) : + Property(name, getter, setter), + _check_box(NULL) +{ +} + +QWidget* Bool::get_widget(QWidget *parent) +{ + if (_check_box) + return _check_box; + + _check_box = new QCheckBox(name(), parent); + + GVariant *const value = _getter ? _getter() : NULL; + + if (value) { + _check_box->setCheckState(g_variant_get_boolean(value) ? + Qt::Checked : Qt::Unchecked); + g_variant_unref(value); + } + + return _check_box; +} + +bool Bool::labeled_widget() const +{ + return true; +} + +void Bool::commit() +{ + assert(_setter); + + if (!_check_box) + return; + + _setter(g_variant_new_boolean( + _check_box->checkState() == Qt::Checked)); +} + +} // prop +} // pv diff --git a/pv/prop/bool.h b/pv/prop/bool.h new file mode 100644 index 00000000..62e5ca36 --- /dev/null +++ b/pv/prop/bool.h @@ -0,0 +1,48 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2013 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 + */ + +#ifndef PULSEVIEW_PV_PROP_BOOL_H +#define PULSEVIEW_PV_PROP_BOOL_H + +#include "property.h" + +class QCheckBox; + +namespace pv { +namespace prop { + +class Bool : public Property +{ +public: + Bool(QString name, Getter getter, Setter setter); + + QWidget* get_widget(QWidget *parent); + bool labeled_widget() const; + + void commit(); + +private: + QCheckBox *_check_box; +}; + +} // prop +} // pv + +#endif // PULSEVIEW_PV_PROP_BOOL_H diff --git a/pv/prop/property.cpp b/pv/prop/property.cpp index 8276a191..798b5f10 100644 --- a/pv/prop/property.cpp +++ b/pv/prop/property.cpp @@ -35,5 +35,10 @@ const QString& Property::name() const return _name; } +bool Property::labeled_widget() const +{ + return false; +} + } // prop } // pv diff --git a/pv/prop/property.h b/pv/prop/property.h index 6ab83193..31b90330 100644 --- a/pv/prop/property.h +++ b/pv/prop/property.h @@ -46,6 +46,7 @@ public: const QString& name() const; virtual QWidget* get_widget(QWidget *parent) = 0; + virtual bool labeled_widget() const; virtual void commit() = 0; -- 2.30.2