Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

floatpropertywidget.h 10.6 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
26
27
#ifndef FLOATPROPERTYWIDGET_H__
#define FLOATPROPERTYWIDGET_H__

28
#include "application/gui/adjusterwidgets/doubleadjusterwidget.h"
schultezub's avatar
schultezub committed
29
#include "application/gui/properties/abstractpropertywidget.h"
30
#include "core/properties/floatingpointproperty.h"
schultezub's avatar
schultezub committed
31

schultezub's avatar
schultezub committed
32
namespace campvis {
schultezub's avatar
schultezub committed
33
    /**
34
     * Widget for a FloatProperty
schultezub's avatar
schultezub committed
35
     */
36
    class CAMPVIS_APPLICATION_API FloatPropertyWidget : public AbstractPropertyWidget {
37
        Q_OBJECT
schultezub's avatar
schultezub committed
38
39
40
41
42

    public:
        /**
         * Creates a new FloatPropertyWidget for the property \a property.
         * \param   property    The property the widget shall handle
43
         * \param   dataContainer   DataContainer to use (optional), defaults to nullptr.
schultezub's avatar
schultezub committed
44
45
         * \param   parent      Parent Qt widget
         */
46
        FloatPropertyWidget(FloatProperty* property, DataContainer* dataContainer, QWidget* parent = 0);
schultezub's avatar
schultezub committed
47
48
49
50
51
52
53
54
55
56
57
58
59

        /**
         * Destructor
         */
        virtual ~FloatPropertyWidget();

    protected:
        /**
         * Gets called when the property has changed, so that widget can update its state.
         */
        virtual void updateWidgetFromProperty();

    private slots:
60
61
        /// Slot getting called when the adjuster's value changes
        void onAdjusterValueChanged(double value);
schultezub's avatar
schultezub committed
62
63
64
65
66

    private:
        /// Slot getting called when the property's min or max value has changed, so that the widget can be updated.
        virtual void onPropertyMinMaxChanged(const AbstractProperty* property);

67
68
69
        /// Slot getting called when the property's step value has changed, so that the widget can be updated.
        virtual void onPropertyStepChanged(const AbstractProperty* property);

70
71
72
73
74
75
        /**
         * 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);

76
        DoubleAdjusterWidget* _adjuster;        ///< Widget allowing the user to change the property's value
schultezub's avatar
schultezub committed
77
78

    };
79
80
81
82
83
84
85
86
87
88

// ================================================================================================

    namespace {
        template<size_t SIZE>
        struct VecPropertyWidgetTraits {};

        template<>
        struct VecPropertyWidgetTraits<2> {
            typedef Vec2Property PropertyType;
89
            typedef cgt::vec2 BaseType;
90
91
92
93
94
        };

        template<>
        struct VecPropertyWidgetTraits<3> {
            typedef Vec3Property PropertyType;
95
            typedef cgt::vec3 BaseType;
96
97
98
99
100
        };

        template<>
        struct VecPropertyWidgetTraits<4> {
            typedef Vec4Property PropertyType;
101
            typedef cgt::vec4 BaseType;
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
        };
    }

// ================================================================================================

    /**
     * Generic base class for Vec property widgets.
     * Unfortunately Q_OBJECT and templates do not fit together, so we an additional level of 
     * indirection helps as usual...
     */
    template<size_t SIZE>
    class VecPropertyWidget : public AbstractPropertyWidget {
    public:
        enum { size = SIZE };
        typedef typename VecPropertyWidgetTraits<SIZE>::PropertyType PropertyType;

        /**
         * Creates a new VecPropertyWidget for the property \a property.
         * \param   property    The property the widget shall handle
         * \param   parent      Parent Qt widget
         */
123
        VecPropertyWidget(PropertyType* property, DataContainer* dataContainer = nullptr, QWidget* parent = 0);
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

        /**
         * Destructor
         */
        virtual ~VecPropertyWidget();

    protected:
        /**
         * Gets called when the property has changed, so that widget can update its state.
         */
        virtual void updateWidgetFromProperty();

        void onValueChangedImpl();

        /// Slot getting called when the property's min or max value has changed, so that the widget can be updated.
        virtual void onPropertyMinMaxChanged(const AbstractProperty* property);

141
142
143
        /// Slot getting called when the property's step value has changed, so that the widget can be updated.
        virtual void onPropertyStepChanged(const AbstractProperty* property);

144
145
146
147
148
149
        /**
         * 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);

150
        DoubleAdjusterWidget* _adjusters[size];
151
152
153
154
155
    };

// ================================================================================================

    template<size_t SIZE>
156
157
    campvis::VecPropertyWidget<SIZE>::VecPropertyWidget(PropertyType* property, DataContainer* dataContainer, QWidget* parent /*= 0*/)
        : AbstractPropertyWidget(property, true, dataContainer, parent)
158
159
    {
        for (size_t i = 0; i < size; ++i) {
160
161
162
            _adjusters[i] = new DoubleAdjusterWidget();
            _adjusters[i]->setMinimum(property->getMinValue()[i]);
            _adjusters[i]->setMaximum(property->getMaxValue()[i]);
163
            _adjusters[i]->setDecimals(property->getDecimals()[i]);
164
            _adjusters[i]->setSingleStep(property->getStepValue()[i]);
165
166
            _adjusters[i]->setValue(property->getValue()[i]);
            addWidget(_adjusters[i]);
167
168
169
        }

        property->s_minMaxChanged.connect(this, &VecPropertyWidget::onPropertyMinMaxChanged);
170
        property->s_stepChanged.connect(this, &VecPropertyWidget::onPropertyStepChanged);
171
        property->s_decimalsChanged.connect(this, &VecPropertyWidget::onPropertyDecimalsChanged);
172
173
174
    }

    template<size_t SIZE>
schultezub's avatar
schultezub committed
175
    campvis::VecPropertyWidget<SIZE>::~VecPropertyWidget() {
176
177
178
179
180
        PropertyType* property = static_cast<PropertyType*>(_property);

        property->s_minMaxChanged.disconnect(this);
        property->s_stepChanged.disconnect(this);
        property->s_decimalsChanged.disconnect(this);
181
182
183
    }

    template<size_t SIZE>
schultezub's avatar
schultezub committed
184
    void campvis::VecPropertyWidget<SIZE>::updateWidgetFromProperty() {
185
186
        PropertyType* prop = static_cast<PropertyType*>(_property);
        for (size_t i = 0; i < size; ++i) {
187
188
189
            _adjusters[i]->blockSignals(true);
            _adjusters[i]->setValue(prop->getValue()[i]);
            _adjusters[i]->blockSignals(false);
190
191
192
193
        }
    }

    template<size_t SIZE>
schultezub's avatar
schultezub committed
194
    void campvis::VecPropertyWidget<SIZE>::onValueChangedImpl() {
schultezub's avatar
schultezub committed
195
        ++_ignorePropertyUpdates;
196
197
198
        PropertyType* prop = static_cast<PropertyType*>(_property);
        typename VecPropertyWidgetTraits<SIZE>::BaseType newValue;
        for (size_t i = 0; i < size; ++i)
199
            newValue[i] = _adjusters[i]->value();
200
        prop->setValue(newValue);
schultezub's avatar
schultezub committed
201
        --_ignorePropertyUpdates;
202
203
204
    }

    template<size_t SIZE>
schultezub's avatar
schultezub committed
205
    void campvis::VecPropertyWidget<SIZE>::onPropertyMinMaxChanged(const AbstractProperty* property) {
schultezub's avatar
schultezub committed
206
        if (_ignorePropertyUpdates == 0) {
207
208
            PropertyType* prop = static_cast<PropertyType*>(_property);
            for (size_t i = 0; i < size; ++i) {
209
210
                _adjusters[i]->setMinimum(prop->getMinValue()[i]);
                _adjusters[i]->setMaximum(prop->getMaxValue()[i]);
211
212
213
214
            }
        }
    }

215
216
217
218
219
220
221
222
223
224
    template<size_t SIZE>
    void campvis::VecPropertyWidget<SIZE>::onPropertyStepChanged(const AbstractProperty* property) {
        if (_ignorePropertyUpdates == 0) {
            PropertyType* prop = static_cast<PropertyType*>(_property);
            for (size_t i = 0; i < size; ++i) {
                _adjusters[i]->setSingleStep(prop->getStepValue()[i]);
            }
        }
    }

225
226
227
228
229
230
231
232
233
234
    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]);
            }
        }
    }

235
236
// ================================================================================================

237
    class CAMPVIS_APPLICATION_API Vec2PropertyWidget : public VecPropertyWidget<2> {
238
239
        Q_OBJECT
    public:
240
        Vec2PropertyWidget(PropertyType* property, DataContainer* dataContainer = nullptr, QWidget* parent = 0);
241
242
243
244
245
246
247

    private slots:
        void onValueChanged(double value) { onValueChangedImpl(); };
    }; 

// ================================================================================================
    
248
    class CAMPVIS_APPLICATION_API Vec3PropertyWidget : public VecPropertyWidget<3> {
249
250
        Q_OBJECT
    public:
251
        Vec3PropertyWidget(PropertyType* property, DataContainer* dataContainer = nullptr, QWidget* parent = 0);
252
253
254
255
256
257
258

        private slots:
            void onValueChanged(double value) { onValueChangedImpl(); };
    }; 

// ================================================================================================

259
    class CAMPVIS_APPLICATION_API Vec4PropertyWidget : public VecPropertyWidget<4> {
260
261
        Q_OBJECT
    public:
262
        Vec4PropertyWidget(PropertyType* property, DataContainer* dataContainer = nullptr, QWidget* parent = 0);
263
264
265
266
267

        private slots:
            void onValueChanged(double value) { onValueChangedImpl(); };
    }; 

schultezub's avatar
schultezub committed
268
269
270
}

#endif // FLOATPROPERTYWIDGET_H__