From: Joel Holdsworth Date: Fri, 28 Dec 2012 10:15:54 +0000 (+0000) Subject: Added get/set support to Property and Enum X-Git-Tag: pulseview-0.1.0~180 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=24bb0bd140f7f8b00ea3c0cbe0c5d26dc03a3b69;p=pulseview.git Added get/set support to Property and Enum --- diff --git a/pv/prop/enum.cpp b/pv/prop/enum.cpp index 29f95d8e..1694840a 100644 --- a/pv/prop/enum.cpp +++ b/pv/prop/enum.cpp @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include "enum.h" @@ -27,9 +29,14 @@ using namespace std; namespace pv { namespace prop { -Enum::Enum(QString name, vector< pair > values) : +Enum::Enum(QString name, + std::vector > values, + boost::function getter, + boost::function 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 >::const_iterator i = _values.begin(); + for(vector< pair >::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()); +} + } // prop } // pv diff --git a/pv/prop/enum.h b/pv/prop/enum.h index 2350fef8..c2cc6395 100644 --- a/pv/prop/enum.h +++ b/pv/prop/enum.h @@ -34,12 +34,19 @@ namespace prop { class Enum : public Property { public: - Enum(QString name, std::vector > values); + Enum(QString name, + std::vector > values, + boost::function getter, + boost::function setter); QWidget* get_widget(QWidget *parent); + void commit(); + private: - const std::vector< std::pair > _values; + const std::vector< std::pair > _values; + boost::function _getter; + boost::function _setter; QComboBox *_selector; }; diff --git a/pv/prop/property.h b/pv/prop/property.h index e6745a10..002c9116 100644 --- a/pv/prop/property.h +++ b/pv/prop/property.h @@ -21,6 +21,8 @@ #ifndef PULSEVIEW_PV_PROP_PROPERTY_H #define PULSEVIEW_PV_PROP_PROPERTY_H +#include + #include #include @@ -39,6 +41,8 @@ public: virtual QWidget* get_widget(QWidget *parent) = 0; + virtual void commit() = 0; + private: QString _name; };