Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

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 {
: AbstractPropertyWidget(property, false, parent)
, _adjuster(0)
{
const float stepValue = 0.01f;
_adjuster = new DoubleAdjusterWidget();
_adjuster->setMinimum(property->getMinValue());
_adjuster->setMaximum(property->getMaxValue());
_adjuster->setDecimals(3);
_adjuster->setDecimals(property->getDecimals());
_adjuster->setSingleStep(property->getStepValue());
_adjuster->setValue(property->getValue());
......@@ -48,11 +46,15 @@ namespace campvis {
connect(_adjuster, SIGNAL(valueChanged(double)), this, SLOT(onAdjusterValueChanged(double)));
property->s_minMaxChanged.connect(this, &FloatPropertyWidget::onPropertyMinMaxChanged);
property->s_stepChanged.connect(this, &FloatPropertyWidget::onPropertyStepChanged);
property->s_decimalsChanged.connect(this, &FloatPropertyWidget::onPropertyDecimalsChanged);
}
FloatPropertyWidget::~FloatPropertyWidget() {
static_cast<FloatProperty*>(_property)->s_minMaxChanged.disconnect(this);
static_cast<FloatProperty*>(_property)->s_stepChanged.disconnect(this);
FloatProperty* property = static_cast<FloatProperty*>(_property);
property->s_minMaxChanged.disconnect(this);
property->s_stepChanged.disconnect(this);
property->s_decimalsChanged.disconnect(this);
}
void FloatPropertyWidget::updateWidgetFromProperty() {
......@@ -83,4 +85,11 @@ namespace campvis {
_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 {
/// Slot getting called when the property's step value has changed, so that the widget can be updated.
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
};
......@@ -139,6 +145,12 @@ namespace campvis {
/// Slot getting called when the property's step value has changed, so that the widget can be updated.
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];
};
......@@ -152,7 +164,7 @@ namespace campvis {
_adjusters[i] = new DoubleAdjusterWidget();
_adjusters[i]->setMinimum(property->getMinValue()[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]->setValue(property->getValue()[i]);
addWidget(_adjusters[i]);
......@@ -160,12 +172,16 @@ namespace campvis {
property->s_minMaxChanged.connect(this, &VecPropertyWidget::onPropertyMinMaxChanged);
property->s_stepChanged.connect(this, &VecPropertyWidget::onPropertyStepChanged);
property->s_decimalsChanged.connect(this, &VecPropertyWidget::onPropertyDecimalsChanged);
}
template<size_t SIZE>
campvis::VecPropertyWidget<SIZE>::~VecPropertyWidget() {
static_cast<PropertyType*>(_property)->s_minMaxChanged.disconnect(this);
static_cast<PropertyType*>(_property)->s_stepChanged.disconnect(this);
PropertyType* property = static_cast<PropertyType*>(_property);
property->s_minMaxChanged.disconnect(this);
property->s_stepChanged.disconnect(this);
property->s_decimalsChanged.disconnect(this);
}
template<size_t SIZE>
......@@ -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> {
......
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