From a2b921574b467fd9193d06497bf0ee058e8f7470 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 7 Apr 2013 19:27:56 +0100 Subject: [PATCH] Added Int property and bound to SR_CONF_CAPTURE_RATIO --- CMakeLists.txt | 1 + pv/prop/binding/deviceoptions.cpp | 14 ++++++ pv/prop/binding/deviceoptions.h | 3 ++ pv/prop/int.cpp | 75 +++++++++++++++++++++++++++++++ pv/prop/int.h | 56 +++++++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 pv/prop/int.cpp create mode 100644 pv/prop/int.h diff --git a/CMakeLists.txt b/CMakeLists.txt index df201786..7d46b25e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,7 @@ set(pulseview_SOURCES pv/prop/bool.cpp pv/prop/double.cpp pv/prop/enum.cpp + pv/prop/int.cpp pv/prop/property.cpp pv/prop/binding/binding.cpp pv/prop/binding/deviceoptions.cpp diff --git a/pv/prop/binding/deviceoptions.cpp b/pv/prop/binding/deviceoptions.cpp index 50af3ed4..f71cbac2 100644 --- a/pv/prop/binding/deviceoptions.cpp +++ b/pv/prop/binding/deviceoptions.cpp @@ -30,6 +30,7 @@ #include #include #include +#include using namespace boost; using namespace std; @@ -71,6 +72,10 @@ DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : bind_samplerate(name, gvar_list); break; + case SR_CONF_CAPTURE_RATIO: + bind_int(name, key, "%", make_pair(0L, 100L)); + break; + case SR_CONF_PATTERN_MODE: case SR_CONF_BUFFERSIZE: case SR_CONF_TRIGGER_SOURCE: @@ -143,6 +148,15 @@ void DeviceOptions::bind_enum(const QString &name, int key, bind(config_setter, _sdi, key, _1)))); } +void DeviceOptions::bind_int(const QString &name, int key, QString suffix, + optional< std::pair > range) +{ + _properties.push_back(shared_ptr( + new Int(name, suffix, range, + bind(config_getter, _sdi, key), + bind(config_setter, _sdi, key, _1)))); +} + QString DeviceOptions::print_gvariant(GVariant *const gvar) { QString s; diff --git a/pv/prop/binding/deviceoptions.h b/pv/prop/binding/deviceoptions.h index f2344796..491acfc4 100644 --- a/pv/prop/binding/deviceoptions.h +++ b/pv/prop/binding/deviceoptions.h @@ -22,6 +22,7 @@ #define PULSEVIEW_PV_PROP_BINDING_DEVICEOPTIONS_H #include +#include #include @@ -49,6 +50,8 @@ private: void bind_enum(const QString &name, int key, GVariant *const gvar_list, boost::function printer = print_gvariant); + void bind_int(const QString &name, int key, QString suffix, + boost::optional< std::pair > range); static QString print_gvariant(GVariant *const gvar); diff --git a/pv/prop/int.cpp b/pv/prop/int.cpp new file mode 100644 index 00000000..502665da --- /dev/null +++ b/pv/prop/int.cpp @@ -0,0 +1,75 @@ +/* + * 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 "int.h" + +using namespace std; +using namespace boost; + +namespace pv { +namespace prop { + +Int::Int(QString name, + QString suffix, + optional< pair > range, + Getter getter, + Setter setter) : + Property(name, getter, setter), + _suffix(suffix), + _range(range), + _spin_box(NULL) +{ +} + +QWidget* Int::get_widget(QWidget *parent) +{ + if (_spin_box) + return _spin_box; + + _spin_box = new QSpinBox(parent); + _spin_box->setSuffix(_suffix); + if (_range) + _spin_box->setRange((int)_range->first, (int)_range->second); + + GVariant *const value = _getter ? _getter() : NULL; + if (value) { + _spin_box->setValue((int)g_variant_get_int64(value)); + g_variant_unref(value); + } + + return _spin_box; +} + +void Int::commit() +{ + assert(_setter); + + if (!_spin_box) + return; + + _setter(g_variant_new_int64(_spin_box->value())); +} + +} // prop +} // pv diff --git a/pv/prop/int.h b/pv/prop/int.h new file mode 100644 index 00000000..ef6fb1df --- /dev/null +++ b/pv/prop/int.h @@ -0,0 +1,56 @@ +/* + * 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_INT_H +#define PULSEVIEW_PV_PROP_INT_H + +#include + +#include + +#include "property.h" + +class QSpinBox; + +namespace pv { +namespace prop { + +class Int : public Property +{ +public: + Int(QString name, QString suffix, + boost::optional< std::pair > range, + Getter getter, Setter setter); + + QWidget* get_widget(QWidget *parent); + + void commit(); + +private: + const QString _suffix; + const boost::optional< std::pair > _range; + + QSpinBox *_spin_box; +}; + +} // prop +} // pv + +#endif // PULSEVIEW_PV_PROP_INT_H -- 2.30.2