projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Moved DevInst into the pv::device namespace
[pulseview.git]
/
pv
/
prop
/
double.cpp
diff --git
a/pv/prop/double.cpp
b/pv/prop/double.cpp
index d7c79ca7db19ce6481d3b8293c06848fcd5364d0..93b45d327362f93b12595a4249e154bcdac0bb14 100644
(file)
--- a/
pv/prop/double.cpp
+++ b/
pv/prop/double.cpp
@@
-24,8
+24,8
@@
#include "double.h"
#include "double.h"
-using
namespace std
;
-using
namespace boost
;
+using
boost::optional
;
+using
std::pair
;
namespace pv {
namespace prop {
namespace pv {
namespace prop {
@@
-35,33
+35,44
@@
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)
{
}
-
QWidget* Double::get_widget(QWidget *parent
)
+
Double::~Double(
)
{
{
- if(_spin_box)
+}
+
+QWidget* Double::get_widget(QWidget *parent, bool auto_commit)
+{
+ if (_spin_box)
return _spin_box;
return _spin_box;
+ GVariant *const value = _getter ? _getter() : NULL;
+ if (!value)
+ return NULL;
+
_spin_box = new QDoubleSpinBox(parent);
_spin_box->setDecimals(_decimals);
_spin_box->setSuffix(_suffix);
_spin_box = new QDoubleSpinBox(parent);
_spin_box->setDecimals(_decimals);
_spin_box->setSuffix(_suffix);
- if(_range)
+ if
(_range)
_spin_box->setRange(_range->first, _range->second);
_spin_box->setRange(_range->first, _range->second);
- if(_step)
+ if
(_step)
_spin_box->setSingleStep(*_step);
_spin_box->setSingleStep(*_step);
- _spin_box->setValue(_getter ? _getter() : 0.0);
+ _spin_box->setValue(g_variant_get_double(value));
+ g_variant_unref(value);
+
+ if (auto_commit)
+ connect(_spin_box, SIGNAL(valueChanged(double)),
+ this, SLOT(on_value_changed(double)));
return _spin_box;
}
return _spin_box;
}
@@
-70,10
+81,15
@@
void Double::commit()
{
assert(_setter);
{
assert(_setter);
- if(!_spin_box)
+ if
(!_spin_box)
return;
return;
- _setter(_spin_box->value());
+ _setter(g_variant_new_double(_spin_box->value()));
+}
+
+void Double::on_value_changed(double)
+{
+ commit();
}
} // prop
}
} // prop