]> sigrok.org Git - pulseview.git/commitdiff
Added get/set support to Property and Enum
authorJoel Holdsworth <redacted>
Fri, 28 Dec 2012 10:15:54 +0000 (10:15 +0000)
committerJoel Holdsworth <redacted>
Fri, 28 Dec 2012 10:19:38 +0000 (10:19 +0000)
pv/prop/enum.cpp
pv/prop/enum.h
pv/prop/property.h

index 29f95d8ebcf9d19417a0fe4f8806b512b9f7b615..1694840a1c7a69357e860bbe047e4af2b681f4fe 100644 (file)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <assert.h>
+
 #include <QComboBox>
 
 #include "enum.h"
@@ -27,9 +29,14 @@ using namespace std;
 namespace pv {
 namespace prop {
 
-Enum::Enum(QString name, vector< pair<int, QString> > values) :
+Enum::Enum(QString name,
+       std::vector<std::pair<const void*, QString> > values,
+       boost::function<const void* ()> getter,
+       boost::function<void (const void*)> setter) :
        Property(name),
        _values(values),
+       _getter(getter),
+       _setter(setter),
        _selector(NULL)
 {
 }
@@ -40,13 +47,28 @@ QWidget* Enum::get_widget(QWidget *parent)
                return _selector;
 
        _selector = new QComboBox(parent);
-       for(vector< pair<int, QString> >::const_iterator i = _values.begin();
+       for(vector< pair<const void*, QString> >::const_iterator i =
+                       _values.begin();
                i != _values.end(); i++)
                _selector->addItem((*i).second,
-                       qVariantFromValue((*i).first));
+                       qVariantFromValue((void*)(*i).first));
 
        return _selector;
 }
 
+void Enum::commit()
+{
+       assert(_setter);
+
+       if(!_selector)
+               return;
+
+       const int index = _selector->currentIndex();
+       if (index < 0)
+               return;
+
+       _setter(_selector->itemData(index).value<void*>());
+}
+
 } // prop
 } // pv
index 2350fef886917ad884639938c0f5b106a00a6c70..c2cc63956cde129eac87f05a66959259b6b96cab 100644 (file)
@@ -34,12 +34,19 @@ namespace prop {
 class Enum : public Property
 {
 public:
-       Enum(QString name, std::vector<std::pair<int, QString> > values);
+       Enum(QString name,
+               std::vector<std::pair<const void*, QString> > values,
+               boost::function<const void* ()> getter,
+               boost::function<void (const void*)> setter);
 
        QWidget* get_widget(QWidget *parent);
 
+       void commit();
+
 private:
-       const std::vector< std::pair<int, QString> > _values;
+       const std::vector< std::pair<const void*, QString> > _values;
+       boost::function<const void* ()> _getter;
+       boost::function<void (const void*)> _setter;
 
        QComboBox *_selector;
 };
index e6745a10d903cf9b4726f83c2bd1d252cf741b8a..002c91161faffd053d2a690e15f641a65282de9d 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef PULSEVIEW_PV_PROP_PROPERTY_H
 #define PULSEVIEW_PV_PROP_PROPERTY_H
 
+#include <boost/function.hpp>
+
 #include <QString>
 #include <QWidget>
 
@@ -39,6 +41,8 @@ public:
 
        virtual QWidget* get_widget(QWidget *parent) = 0;
 
+       virtual void commit() = 0;
+
 private:
        QString _name;
 };