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

index 2b9f39d110c6df1ed402d02b0c979bf9055f4547..df201786445b17d7e6da62321471d61094791ced 100644 (file)
@@ -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
index 5d411686f4a820f8ea686e191091f1b6d8c5500b..3b15f5a9ebfed1858258461b63bb0b33c62ba15c 100644 (file)
@@ -50,7 +50,8 @@ QWidget* Binding::get_form(QWidget *parent)
        BOOST_FOREACH(shared_ptr<Property> 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;
index 90f474f24935c04616a6871c1dec89df176d17b2..50af3ed4ffdec51a09565537a997f2578f2d366b 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "deviceoptions.h"
 
+#include <pv/prop/bool.h>
 #include <pv/prop/double.h>
 #include <pv/prop/enum.h>
 
@@ -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<Property>(
+               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<QString (GVariant*)> printer)
 {
@@ -116,6 +131,8 @@ void DeviceOptions::bind_enum(const QString &name, int key,
        GVariantIter iter;
        vector< pair<GVariant*, QString> > 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"))))
        {
index 28806f0f15e35c9fe2a650d809acc660f548a94b..f2344796e338220b77dd8892459efe60a9000b6b 100644 (file)
@@ -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<QString (GVariant*)> printer = print_gvariant);
diff --git a/pv/prop/bool.cpp b/pv/prop/bool.cpp
new file mode 100644 (file)
index 0000000..95cbb96
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * 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 <QCheckBox>
+
+#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 (file)
index 0000000..62e5ca3
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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_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
index 8276a191b57b99709bc9eef9c650c10169f62090..798b5f10dee87ecfd12449aea94252083b6f1331 100644 (file)
@@ -35,5 +35,10 @@ const QString& Property::name() const
        return _name;
 }
 
+bool Property::labeled_widget() const
+{
+       return false;
+}
+
 } // prop
 } // pv
index 6ab83193963c3d0a8f6b470c2bd551c41ad625ac..31b90330d5e68a69cd63f01c220b5abdbdb30f2d 100644 (file)
@@ -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;