Commit ecf594d5 authored by Artur Grunau's avatar Artur Grunau
Browse files

FloatPropertyWidget: configurable decimal places

FloatPropertyWidget and VecPropertyWidget configure their adjusters to
display as many decimals as their properties have significant decimal
places. Moreover, they connect to the s_decimalsChanged signal in order
to reconfigure their adjusters when the number of significant decimal
places of their properties changes.
parent f318af5c
...@@ -34,12 +34,10 @@ namespace campvis { ...@@ -34,12 +34,10 @@ namespace campvis {
: AbstractPropertyWidget(property, false, parent) : AbstractPropertyWidget(property, false, parent)
, _adjuster(0) , _adjuster(0)
{ {
const float stepValue = 0.01f;
_adjuster = new DoubleAdjusterWidget(); _adjuster = new DoubleAdjusterWidget();
_adjuster->setMinimum(property->getMinValue()); _adjuster->setMinimum(property->getMinValue());
_adjuster->setMaximum(property->getMaxValue()); _adjuster->setMaximum(property->getMaxValue());
_adjuster->setDecimals(3); _adjuster->setDecimals(property->getDecimals());
_adjuster->setSingleStep(property->getStepValue()); _adjuster->setSingleStep(property->getStepValue());
_adjuster->setValue(property->getValue()); _adjuster->setValue(property->getValue());
...@@ -48,11 +46,15 @@ namespace campvis { ...@@ -48,11 +46,15 @@ namespace campvis {
connect(_adjuster, SIGNAL(valueChanged(double)), this, SLOT(onAdjusterValueChanged(double))); connect(_adjuster, SIGNAL(valueChanged(double)), this, SLOT(onAdjusterValueChanged(double)));
property->s_minMaxChanged.connect(this, &FloatPropertyWidget::onPropertyMinMaxChanged); property->s_minMaxChanged.connect(this, &FloatPropertyWidget::onPropertyMinMaxChanged);
property->s_stepChanged.connect(this, &FloatPropertyWidget::onPropertyStepChanged); property->s_stepChanged.connect(this, &FloatPropertyWidget::onPropertyStepChanged);
property->s_decimalsChanged.connect(this, &FloatPropertyWidget::onPropertyDecimalsChanged);
} }
FloatPropertyWidget::~FloatPropertyWidget() { FloatPropertyWidget::~FloatPropertyWidget() {
static_cast<FloatProperty*>(_property)->s_minMaxChanged.disconnect(this); FloatProperty* property = static_cast<FloatProperty*>(_property);
static_cast<FloatProperty*>(_property)->s_stepChanged.disconnect(this);
property->s_minMaxChanged.disconnect(this);
property->s_stepChanged.disconnect(this);
property->s_decimalsChanged.disconnect(this);
} }
void FloatPropertyWidget::updateWidgetFromProperty() { void FloatPropertyWidget::updateWidgetFromProperty() {
...@@ -83,4 +85,11 @@ namespace campvis { ...@@ -83,4 +85,11 @@ namespace campvis {
_adjuster->setSingleStep(prop->getStepValue()); _adjuster->setSingleStep(prop->getStepValue());
} }
} }
void FloatPropertyWidget::onPropertyDecimalsChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
const FloatProperty* prop = static_cast<const FloatProperty*>(property);
_adjuster->setDecimals(prop->getDecimals());
}
}
} }
...@@ -71,6 +71,12 @@ namespace campvis { ...@@ -71,6 +71,12 @@ namespace campvis {
/// Slot getting called when the property's step value has changed, so that the widget can be updated. /// Slot getting called when the property's step value has changed, so that the widget can be updated.
virtual void onPropertyStepChanged(const AbstractProperty* property); virtual void onPropertyStepChanged(const AbstractProperty* property);
/**
* Slot getting called when the number of significant decimal places of the property has
* changed, so that the widget can be updated.
*/
virtual void onPropertyDecimalsChanged(const AbstractProperty* property);
DoubleAdjusterWidget* _adjuster; ///< Widget allowing the user to change the property's value DoubleAdjusterWidget* _adjuster; ///< Widget allowing the user to change the property's value
}; };
...@@ -139,6 +145,12 @@ namespace campvis { ...@@ -139,6 +145,12 @@ namespace campvis {
/// Slot getting called when the property's step value has changed, so that the widget can be updated. /// Slot getting called when the property's step value has changed, so that the widget can be updated.
virtual void onPropertyStepChanged(const AbstractProperty* property); virtual void onPropertyStepChanged(const AbstractProperty* property);
/**
* Slot getting called when the number of significant decimal places of the property has
* changed, so that the widget can be updated.
*/
virtual void onPropertyDecimalsChanged(const AbstractProperty* property);
DoubleAdjusterWidget* _adjusters[size]; DoubleAdjusterWidget* _adjusters[size];
}; };
...@@ -152,7 +164,7 @@ namespace campvis { ...@@ -152,7 +164,7 @@ namespace campvis {
_adjusters[i] = new DoubleAdjusterWidget(); _adjusters[i] = new DoubleAdjusterWidget();
_adjusters[i]->setMinimum(property->getMinValue()[i]); _adjusters[i]->setMinimum(property->getMinValue()[i]);
_adjusters[i]->setMaximum(property->getMaxValue()[i]); _adjusters[i]->setMaximum(property->getMaxValue()[i]);
_adjusters[i]->setDecimals(3); _adjusters[i]->setDecimals(property->getDecimals()[i]);
_adjusters[i]->setSingleStep(property->getStepValue()[i]); _adjusters[i]->setSingleStep(property->getStepValue()[i]);
_adjusters[i]->setValue(property->getValue()[i]); _adjusters[i]->setValue(property->getValue()[i]);
addWidget(_adjusters[i]); addWidget(_adjusters[i]);
...@@ -160,12 +172,16 @@ namespace campvis { ...@@ -160,12 +172,16 @@ namespace campvis {
property->s_minMaxChanged.connect(this, &VecPropertyWidget::onPropertyMinMaxChanged); property->s_minMaxChanged.connect(this, &VecPropertyWidget::onPropertyMinMaxChanged);
property->s_stepChanged.connect(this, &VecPropertyWidget::onPropertyStepChanged); property->s_stepChanged.connect(this, &VecPropertyWidget::onPropertyStepChanged);
property->s_decimalsChanged.connect(this, &VecPropertyWidget::onPropertyDecimalsChanged);
} }
template<size_t SIZE> template<size_t SIZE>
campvis::VecPropertyWidget<SIZE>::~VecPropertyWidget() { campvis::VecPropertyWidget<SIZE>::~VecPropertyWidget() {
static_cast<PropertyType*>(_property)->s_minMaxChanged.disconnect(this); PropertyType* property = static_cast<PropertyType*>(_property);
static_cast<PropertyType*>(_property)->s_stepChanged.disconnect(this);
property->s_minMaxChanged.disconnect(this);
property->s_stepChanged.disconnect(this);
property->s_decimalsChanged.disconnect(this);
} }
template<size_t SIZE> template<size_t SIZE>
...@@ -210,6 +226,16 @@ namespace campvis { ...@@ -210,6 +226,16 @@ namespace campvis {
} }
} }
template<size_t SIZE>
void campvis::VecPropertyWidget<SIZE>::onPropertyDecimalsChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
PropertyType* prop = static_cast<PropertyType*>(_property);
for (size_t i = 0; i < size; ++i) {
_adjusters[i]->setDecimals(prop->getDecimals()[i]);
}
}
}
// ================================================================================================ // ================================================================================================
class Vec2PropertyWidget : public VecPropertyWidget<2> { class Vec2PropertyWidget : public VecPropertyWidget<2> {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment