projects
/
pulseview.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2db7704
)
Make pv::prop objects run on GVariants
author
Joel Holdsworth
<joel@airwebreathe.org.uk>
Mon, 1 Apr 2013 15:09:44 +0000
(16:09 +0100)
committer
Joel Holdsworth
<joel@airwebreathe.org.uk>
Mon, 8 Apr 2013 17:48:44 +0000
(18:48 +0100)
pv/prop/double.cpp
patch
|
blob
|
history
pv/prop/double.h
patch
|
blob
|
history
pv/prop/enum.cpp
patch
|
blob
|
history
pv/prop/enum.h
patch
|
blob
|
history
pv/prop/property.cpp
patch
|
blob
|
history
pv/prop/property.h
patch
|
blob
|
history
diff --git
a/pv/prop/double.cpp
b/pv/prop/double.cpp
index c1e776e1f6c890c21d9d435cbc66316d8976e528..6f6fe0c1ea7e228ca7ed1487efa13e7202a3f5c2 100644
(file)
--- a/
pv/prop/double.cpp
+++ b/
pv/prop/double.cpp
@@
-35,15
+35,13
@@
Double::Double(QString name,
QString suffix,
optional< pair<double, double> > range,
optional<double> step,
QString suffix,
optional< pair<double, double> > range,
optional<double> step,
-
function<double ()>
getter,
-
function<void (double)>
setter) :
- Property(name),
+
Getter
getter,
+
Setter
setter) :
+ Property(name
, getter, setter
),
_decimals(decimals),
_suffix(suffix),
_range(range),
_step(step),
_decimals(decimals),
_suffix(suffix),
_range(range),
_step(step),
- _getter(getter),
- _setter(setter),
_spin_box(NULL)
{
}
_spin_box(NULL)
{
}
@@
-61,7
+59,12
@@
QWidget* Double::get_widget(QWidget *parent)
if (_step)
_spin_box->setSingleStep(*_step);
if (_step)
_spin_box->setSingleStep(*_step);
- _spin_box->setValue(_getter ? _getter() : 0.0);
+ GVariant *const value = _getter ? _getter() : NULL;
+
+ if (value) {
+ _spin_box->setValue(g_variant_get_double(value));
+ g_variant_unref(value);
+ }
return _spin_box;
}
return _spin_box;
}
@@
-73,7
+76,7
@@
void Double::commit()
if (!_spin_box)
return;
if (!_spin_box)
return;
- _setter(
_spin_box->value(
));
+ _setter(
g_variant_new_double(_spin_box->value()
));
}
} // prop
}
} // prop
diff --git
a/pv/prop/double.h
b/pv/prop/double.h
index 19cbe2c185e99ad0b0e35b3f653fd3c912eae67c..6b6275c10effd429085e2c619d3624dbbffbf9c2 100644
(file)
--- a/
pv/prop/double.h
+++ b/
pv/prop/double.h
@@
-39,8
+39,8
@@
public:
Double(QString name, int decimals, QString suffix,
boost::optional< std::pair<double, double> > range,
boost::optional<double> step,
Double(QString name, int decimals, QString suffix,
boost::optional< std::pair<double, double> > range,
boost::optional<double> step,
-
boost::function<double ()>
getter,
-
boost::function<void (double)>
setter);
+
Getter
getter,
+
Setter
setter);
QWidget* get_widget(QWidget *parent);
QWidget* get_widget(QWidget *parent);
@@
-51,8
+51,6
@@
private:
const QString _suffix;
const boost::optional< std::pair<double, double> > _range;
const boost::optional<double> _step;
const QString _suffix;
const boost::optional< std::pair<double, double> > _range;
const boost::optional<double> _step;
- boost::function<double ()> _getter;
- boost::function<void (double)> _setter;
QDoubleSpinBox *_spin_box;
};
QDoubleSpinBox *_spin_box;
};
diff --git
a/pv/prop/enum.cpp
b/pv/prop/enum.cpp
index 894ba9f8e2754ded46f9e07b783484871d25eade..065fd548f22b336151d03da49f0c03e43456bce1 100644
(file)
--- a/
pv/prop/enum.cpp
+++ b/
pv/prop/enum.cpp
@@
-20,7
+20,6
@@
#include <assert.h>
#include <assert.h>
-#include <glib-2.0/glib.h>
#include <QComboBox>
#include "enum.h"
#include <QComboBox>
#include "enum.h"
@@
-32,35
+31,38
@@
namespace pv {
namespace prop {
Enum::Enum(QString name,
namespace prop {
Enum::Enum(QString name,
- vector<pair<const void*, QString> > values,
- function<GVariant* ()> getter,
- function<void (GVariant*)> setter) :
- Property(name),
+ vector<pair<GVariant*, QString> > values,
+ Getter getter, Setter setter) :
+ Property(name, getter, setter),
_values(values),
_values(values),
- _getter(getter),
- _setter(setter),
_selector(NULL)
{
}
_selector(NULL)
{
}
+Enum::~Enum()
+{
+ for (unsigned int i = 0; i < _values.size(); i++)
+ g_variant_unref(_values[i].first);
+}
+
QWidget* Enum::get_widget(QWidget *parent)
{
if (_selector)
return _selector;
QWidget* Enum::get_widget(QWidget *parent)
{
if (_selector)
return _selector;
- const void *value = NULL;
- if (_getter)
- value = _getter();
+ GVariant *const value = _getter ? _getter() : NULL;
+ assert(value);
_selector = new QComboBox(parent);
for (unsigned int i = 0; i < _values.size(); i++) {
_selector = new QComboBox(parent);
for (unsigned int i = 0; i < _values.size(); i++) {
- const pair<const void*, QString> &v = _values[i];
- _selector->addItem(v.second,
- qVariantFromValue((void*)v.first));
- if (v.first == value)
+ const pair<GVariant*, QString> &v = _values[i];
+ _selector->addItem(v.second, qVariantFromValue((void*)v.first));
+ if (g_variant_compare(v.first, value) == 0)
_selector->setCurrentIndex(i);
}
_selector->setCurrentIndex(i);
}
+ g_variant_unref(value);
+
return _selector;
}
return _selector;
}
@@
-75,7
+77,7
@@
void Enum::commit()
if (index < 0)
return;
if (index < 0)
return;
- _setter(
_selector->itemData(index).value<GVariant
*>());
+ _setter(
(GVariant*)_selector->itemData(index).value<void
*>());
}
} // prop
}
} // prop
diff --git
a/pv/prop/enum.h
b/pv/prop/enum.h
index 02b60df5dd5ee982ace26230f89a1b2ba6e2b34c..402798c08aed26a2c5b5a8c088704528b6eb5bb2 100644
(file)
--- a/
pv/prop/enum.h
+++ b/
pv/prop/enum.h
@@
-24,7
+24,6
@@
#include <utility>
#include <vector>
#include <utility>
#include <vector>
-#include <glib-2.0/glib.h>
#include "property.h"
class QComboBox;
#include "property.h"
class QComboBox;
@@
-35,19
+34,17
@@
namespace prop {
class Enum : public Property
{
public:
class Enum : public Property
{
public:
- Enum(QString name,
- std::vector<std::pair<const void*, QString> > values,
- boost::function<GVariant* ()> getter,
-
boost::function<void (GVariant*)> setter
);
+ Enum(QString name,
std::vector<std::pair<GVariant*, QString> > values,
+ Getter getter, Setter setter);
+
+
virtual ~Enum(
);
QWidget* get_widget(QWidget *parent);
void commit();
private:
QWidget* get_widget(QWidget *parent);
void commit();
private:
- const std::vector< std::pair<const void*, QString> > _values;
- boost::function<GVariant* ()> _getter;
- boost::function<void (GVariant*)> _setter;
+ const std::vector< std::pair<GVariant*, QString> > _values;
QComboBox *_selector;
};
QComboBox *_selector;
};
diff --git
a/pv/prop/property.cpp
b/pv/prop/property.cpp
index 0a14d241ec1e5921b1acef729ced9d73377b4762..8276a191b57b99709bc9eef9c650c10169f62090 100644
(file)
--- a/
pv/prop/property.cpp
+++ b/
pv/prop/property.cpp
@@
-23,7
+23,9
@@
namespace pv {
namespace prop {
namespace pv {
namespace prop {
-Property::Property(QString name) :
+Property::Property(QString name, Getter getter, Setter setter) :
+ _getter(getter),
+ _setter(setter),
_name(name)
{
}
_name(name)
{
}
diff --git
a/pv/prop/property.h
b/pv/prop/property.h
index 002c91161faffd053d2a690e15f641a65282de9d..6ab83193963c3d0a8f6b470c2bd551c41ad625ac 100644
(file)
--- 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
#ifndef PULSEVIEW_PV_PROP_PROPERTY_H
#define PULSEVIEW_PV_PROP_PROPERTY_H
+#include <glib-2.0/glib.h>
+
#include <boost/function.hpp>
#include <QString>
#include <boost/function.hpp>
#include <QString>
@@
-33,8
+35,12
@@
namespace prop {
class Property
{
class Property
{
+public:
+ typedef boost::function<GVariant* ()> Getter;
+ typedef boost::function<void (GVariant*)> Setter;
+
protected:
protected:
- Property(QString name);
+ Property(QString name
, Getter getter, Setter setter
);
public:
const QString& name() const;
public:
const QString& name() const;
@@
-43,6
+49,10
@@
public:
virtual void commit() = 0;
virtual void commit() = 0;
+protected:
+ const Getter _getter;
+ const Setter _setter;
+
private:
QString _name;
};
private:
QString _name;
};