29 #define ROUND(x) (((x) > 0) ? int((x) + 0.5) : int((x)-0.5))
30 #define ROUND_SHORT(x) (((x) > 0) ? short((x) + 0.5) : short((x)-0.5))
32 class QmitkNumberPropertySlider::Impl
38 void adjustFactors(
short,
bool);
47 virtual void PropertyChanged()
override;
48 virtual void PropertyRemoved()
override;
64 std::unique_ptr<Editor> m_PropEditor;
66 short m_DecimalPlaces;
67 double m_FactorPropertyToSlider;
68 double m_FactorSliderToDisplay;
71 bool m_SelfChangeLock;
79 QmitkNumberPropertySlider::Impl::Editor::Editor(
mitk::IntProperty *property, Impl *impl)
80 :
mitk::PropertyEditor(property), m_IntProperty(property), m_DataType(
DT_INT),
m_Impl(impl)
85 :
mitk::PropertyEditor(property), m_FloatProperty(property), m_DataType(
DT_FLOAT),
m_Impl(impl)
90 :
mitk::PropertyEditor(property), m_DoubleProperty(property), m_DataType(
DT_DOUBLE),
m_Impl(impl)
100 if (property ==
nullptr)
102 d->m_PropEditor.reset();
103 this->setEnabled(
false);
107 d->m_PropEditor.reset(
new Impl::Editor(property, d.get()));
108 d->m_PropEditor->PropertyChanged();
109 this->setEnabled(
true);
115 if (property ==
nullptr)
117 d->m_PropEditor.reset();
118 this->setEnabled(
false);
122 d->m_PropEditor.reset(
new Impl::Editor(property, d.get()));
123 d->m_PropEditor->PropertyChanged();
124 this->setEnabled(
true);
130 if (property ==
nullptr)
132 d->m_PropEditor.reset();
133 this->setEnabled(
false);
137 d->m_PropEditor.reset(
new Impl::Editor(property, d.get()));
138 d->m_PropEditor->PropertyChanged();
139 this->setEnabled(
true);
144 : m_DecimalPlaces(0),
145 m_FactorPropertyToSlider(1.0),
146 m_FactorSliderToDisplay(1.0),
147 m_ShowPercents(false),
148 m_SelfChangeLock(false),
155 connect(
this, SIGNAL(valueChanged(
int)),
this, SLOT(
onValueChanged(
int)));
156 this->setEnabled(
false);
159 void QmitkNumberPropertySlider::Impl::adjustFactors(
short newDecimalPlaces,
bool newShowPercents)
161 int oldMax = q->maxValue();
162 int oldMin = q->minValue();
164 m_DecimalPlaces = newDecimalPlaces;
165 m_ShowPercents = newShowPercents;
167 m_FactorPropertyToSlider = pow(10.0, m_DecimalPlaces);
168 m_FactorSliderToDisplay = 1.0 / m_FactorPropertyToSlider;
171 m_FactorPropertyToSlider *= 100.0;
173 q->setMinimum(oldMin);
174 q->setMaximum(oldMax);
179 return d->m_DecimalPlaces;
184 if (d->m_PropEditor.get() ==
nullptr)
187 switch (d->m_PropEditor->m_DataType)
192 d->adjustFactors(places, d->m_ShowPercents);
203 return d->m_ShowPercents;
208 if (showPercent == d->m_ShowPercents)
211 if (d->m_PropEditor.get() ==
nullptr)
214 switch (d->m_PropEditor->m_DataType)
219 d->adjustFactors(d->m_DecimalPlaces, showPercent);
233 return ROUND(QSlider::minimum() / d->m_FactorPropertyToSlider);
238 QSlider::setMinimum(
ROUND(value * d->m_FactorPropertyToSlider));
243 return ROUND(QSlider::maximum() / d->m_FactorPropertyToSlider);
248 QSlider::setMaximum(
ROUND(value * d->m_FactorPropertyToSlider));
253 return static_cast<double>((QSlider::value()) / d->m_FactorPropertyToSlider);
258 QSlider::setValue(
ROUND(value * d->m_FactorPropertyToSlider));
263 if (d->m_PropEditor.get() ==
nullptr)
266 if (d->m_SelfChangeLock)
277 d->m_PropEditor->BeginModifyProperty();
279 double newValue(value / d->m_FactorPropertyToSlider);
281 switch (d->m_PropEditor->m_DataType)
285 d->m_PropEditor->m_IntProperty->SetValue(
ROUND(newValue));
290 d->m_PropEditor->m_FloatProperty->SetValue(newValue);
295 d->m_PropEditor->m_DoubleProperty->SetValue(newValue);
301 d->m_PropEditor->EndModifyProperty();
304 void QmitkNumberPropertySlider::Impl::Editor::PropertyChanged()
310 void QmitkNumberPropertySlider::Impl::Editor::PropertyRemoved()
312 this->m_Property =
nullptr;
315 void QmitkNumberPropertySlider::Impl::DisplayNumber()
317 if (m_PropEditor.get() ==
nullptr)
320 m_SelfChangeLock =
true;
321 switch (m_PropEditor->m_DataType)
325 int i = m_PropEditor->m_IntProperty->GetValue();
331 float f = m_PropEditor->m_FloatProperty->GetValue();
332 q->setDoubleValue(f);
337 double d = m_PropEditor->m_DoubleProperty->GetValue();
338 q->setDoubleValue(d);
344 m_SelfChangeLock =
false;
void setDoubleValue(double)
DataCollection - Class to facilitate loading/accessing structured data.
short getDecimalPlaces() const
bool getShowPercent() const
void SetProperty(mitk::IntProperty *property)
virtual ~QmitkNumberPropertySlider()
QmitkNumberPropertySlider(QWidget *parent=nullptr)
static RenderingManager * GetInstance()
double doubleValue() const
void BeginModifyProperty()
void setShowPercent(bool)
void setDecimalPlaces(short)
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)