* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <assert.h>
+
#include <QComboBox>
#include "enum.h"
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)
{
}
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
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;
};
#ifndef PULSEVIEW_PV_PROP_PROPERTY_H
#define PULSEVIEW_PV_PROP_PROPERTY_H
+#include <boost/function.hpp>
+
#include <QString>
#include <QWidget>
virtual QWidget* get_widget(QWidget *parent) = 0;
+ virtual void commit() = 0;
+
private:
QString _name;
};