projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use <cstdlib> for std::abs() on integer datatypes.
[pulseview.git]
/
pv
/
prop
/
double.cpp
diff --git
a/pv/prop/double.cpp
b/pv/prop/double.cpp
index c1e776e1f6c890c21d9d435cbc66316d8976e528..54540bc68ded41c0575c3202726ac383665b5814 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,24
+35,36
@@
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()
+{
+}
+
+QWidget* Double::get_widget(QWidget *parent, bool auto_commit)
{
if (_spin_box)
return _spin_box;
{
if (_spin_box)
return _spin_box;
+ if (!_getter)
+ return NULL;
+
+ Glib::VariantBase variant = _getter();
+ if (!variant.gobj())
+ return NULL;
+
+ double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
+ variant).get();
+
_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);
@@
-61,7
+73,11
@@
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);
+ _spin_box->setValue(value);
+
+ if (auto_commit)
+ connect(_spin_box, SIGNAL(valueChanged(double)),
+ this, SLOT(on_value_changed(double)));
return _spin_box;
}
return _spin_box;
}
@@
-73,7
+89,12
@@
void Double::commit()
if (!_spin_box)
return;
if (!_spin_box)
return;
- _setter(_spin_box->value());
+ _setter(Glib::Variant<double>::create(_spin_box->value()));
+}
+
+void Double::on_value_changed(double)
+{
+ commit();
}
} // prop
}
} // prop