intpropertywidget.cpp 1.6 KB
Newer Older
schultezub's avatar
schultezub committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "intpropertywidget.h"

namespace TUMVis {
    IntPropertyWidget::IntPropertyWidget(IntProperty* property, QWidget* parent /*= 0*/)
        : AbstractPropertyWidget(property, parent)
        , _spinBox(0)
    {
        _spinBox = new QSpinBox(this);
        _spinBox->setMinimum(property->getMinValue());
        _spinBox->setMaximum(property->getMaxValue());
        _spinBox->setValue(property->getValue());
        
        addWidget(_spinBox);

        connect(_spinBox, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
        property->s_minMaxChanged.connect(this, &IntPropertyWidget::onPropertyMinMaxChanged);
    }

    IntPropertyWidget::~IntPropertyWidget() {
schultezub's avatar
schultezub committed
20
        static_cast<IntProperty*>(_property)->s_minMaxChanged.disconnect(this);
schultezub's avatar
schultezub committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    }

    void IntPropertyWidget::updateWidgetFromProperty() {
        IntProperty* prop = static_cast<IntProperty*>(_property);
        _spinBox->blockSignals(true);
        _spinBox->setValue(prop->getValue());
        _spinBox->blockSignals(false);
    }

    void IntPropertyWidget::onValueChanged(int value) {
        _ignorePropertyUpdates = true;
        IntProperty* prop = static_cast<IntProperty*>(_property);
        prop->setValue(value);
        _ignorePropertyUpdates = false;
    }

    void IntPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) {
        if (!_ignorePropertyUpdates) {
            IntProperty* prop = static_cast<IntProperty*>(_property);
            _spinBox->setMinimum(prop->getMinValue());
            _spinBox->setMaximum(prop->getMaxValue());
        }
    }
}