]> sigrok.org Git - pulseview.git/commitdiff
Added Int property and bound to SR_CONF_CAPTURE_RATIO
authorJoel Holdsworth <redacted>
Sun, 7 Apr 2013 18:27:56 +0000 (19:27 +0100)
committerJoel Holdsworth <redacted>
Mon, 8 Apr 2013 18:08:18 +0000 (19:08 +0100)
CMakeLists.txt
pv/prop/binding/deviceoptions.cpp
pv/prop/binding/deviceoptions.h
pv/prop/int.cpp [new file with mode: 0644]
pv/prop/int.h [new file with mode: 0644]

index df201786445b17d7e6da62321471d61094791ced..7d46b25ee5359b171f93216ffec1924ab7cf260d 100644 (file)
@@ -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
index 50af3ed4ffdec51a09565537a997f2578f2d366b..f71cbac2a42aeb57a3db42d4377b973346e679d5 100644 (file)
@@ -30,6 +30,7 @@
 #include <pv/prop/bool.h>
 #include <pv/prop/double.h>
 #include <pv/prop/enum.h>
+#include <pv/prop/int.h>
 
 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<int64_t, int64_t> > range)
+{
+       _properties.push_back(shared_ptr<Property>(
+               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;
index f2344796e338220b77dd8892459efe60a9000b6b..491acfc45703a028f9c083b374713984a0d27d1d 100644 (file)
@@ -22,6 +22,7 @@
 #define PULSEVIEW_PV_PROP_BINDING_DEVICEOPTIONS_H
 
 #include <boost/function.hpp>
+#include <boost/optional.hpp>
 
 #include <QString>
 
@@ -49,6 +50,8 @@ private:
        void bind_enum(const QString &name, int key,
                GVariant *const gvar_list,
                boost::function<QString (GVariant*)> printer = print_gvariant);
+       void bind_int(const QString &name, int key, QString suffix,
+               boost::optional< std::pair<int64_t, int64_t> > range);
 
        static QString print_gvariant(GVariant *const gvar);
 
diff --git a/pv/prop/int.cpp b/pv/prop/int.cpp
new file mode 100644 (file)
index 0000000..502665d
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 <assert.h>
+
+#include <QSpinBox>
+
+#include "int.h"
+
+using namespace std;
+using namespace boost;
+
+namespace pv {
+namespace prop {
+
+Int::Int(QString name,
+       QString suffix,
+       optional< pair<int64_t, int64_t> > 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 (file)
index 0000000..ef6fb1d
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 <utility>
+
+#include <boost/optional.hpp>
+
+#include "property.h"
+
+class QSpinBox;
+
+namespace pv {
+namespace prop {
+
+class Int : public Property
+{
+public:
+       Int(QString name, QString suffix,
+               boost::optional< std::pair<int64_t, int64_t> > range,
+               Getter getter, Setter setter);
+
+       QWidget* get_widget(QWidget *parent);
+
+       void commit();
+
+private:
+       const QString _suffix;
+       const boost::optional< std::pair<int64_t, int64_t> > _range;
+
+       QSpinBox *_spin_box;
+};
+
+} // prop
+} // pv
+
+#endif // PULSEVIEW_PV_PROP_INT_H