From 4fb257645cd6fd94f5325d173a6b4e65fe9ae7a8 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Thu, 1 Dec 2022 12:03:31 +0100
Subject: [PATCH] DoubleSpinbox: accepts DoubleProperty&

---
 GUI/View/Common/DoubleSpinBox.cpp | 28 ++++++++++++++--------------
 GUI/View/Common/DoubleSpinBox.h   | 12 ++++++------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/GUI/View/Common/DoubleSpinBox.cpp b/GUI/View/Common/DoubleSpinBox.cpp
index 01290aeac75..2fcd49d55df 100644
--- a/GUI/View/Common/DoubleSpinBox.cpp
+++ b/GUI/View/Common/DoubleSpinBox.cpp
@@ -16,22 +16,22 @@
 #include "GUI/View/Tool/EditUtil.h"
 #include <QWheelEvent>
 
-DoubleSpinBox::DoubleSpinBox(const DoubleDescriptor& d, bool easyScrollable, int precision,
+DoubleSpinBox::DoubleSpinBox(const DoubleProperty &d, bool easyScrollable, int precision,
                              double stepSize, QWidget* parent)
     : QDoubleSpinBox(parent)
-    , m_valueDescriptor(d)
+    , m_valueProperty(d)
     , easyScrollable(easyScrollable)
     , m_precision(precision)
 {
     setFocusPolicy(Qt::StrongFocus);
-    GUI::View::EditUtil::configSpinbox(this, d.decimals, d.limits);
-    setToolTip(d.tooltip);
+    GUI::View::EditUtil::configSpinbox(this, d.decimals(), d.limits());
+    setToolTip(d.tooltip());
     setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
 
-    if (std::holds_alternative<QString>(m_valueDescriptor.unit))
+    if (std::holds_alternative<QString>(m_valueProperty.unit()))
         setDisplayUnit(Unit::other);
     else
-        setDisplayUnit(std::get<Unit>(m_valueDescriptor.unit));
+        setDisplayUnit(std::get<Unit>(m_valueProperty.unit()));
 
     QObject::connect(this, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
                      &DoubleSpinBox::onDisplayValueChanged);
@@ -50,7 +50,7 @@ void DoubleSpinBox::setDisplayUnit(Unit displayUnit)
     }
 
     QSignalBlocker b(this);
-    setValue(toDisplayValue(m_valueDescriptor.get()));
+    setValue(toDisplayValue(m_valueProperty.get()));
 }
 
 double DoubleSpinBox::toDisplayValue(double baseValue) const
@@ -65,15 +65,15 @@ double DoubleSpinBox::toBaseValue(double displayValue) const
 
 QString DoubleSpinBox::displayUnitAsString() const
 {
-    if (std::holds_alternative<QString>(m_valueDescriptor.unit))
-        return std::get<QString>(m_valueDescriptor.unit);
+    if (std::holds_alternative<QString>(m_valueProperty.unit()))
+        return std::get<QString>(m_valueProperty.unit());
 
     return unitAsString(m_displayUnit);
 }
 
-const DoubleDescriptor& DoubleSpinBox::valueDescriptor() const
+DoubleDescriptor DoubleSpinBox::valueDescriptor() const
 {
-    return m_valueDescriptor;
+    return m_valueProperty;
 }
 
 void DoubleSpinBox::setBaseValue(double baseValue)
@@ -96,16 +96,16 @@ void DoubleSpinBox::onDisplayValueChanged(double newDisplayValue)
 
 Unit DoubleSpinBox::baseUnit() const
 {
-    if (std::holds_alternative<QString>(m_valueDescriptor.unit))
+    if (std::holds_alternative<QString>(m_valueProperty.unit()))
         return Unit::other;
 
-    return std::get<Unit>(m_valueDescriptor.unit);
+    return std::get<Unit>(m_valueProperty.unit());
 }
 
 void DoubleSpinBox::updateValue()
 {
     QSignalBlocker b(this);
-    setBaseValue(m_valueDescriptor.get());
+    setBaseValue(m_valueProperty.get());
 }
 
 QString DoubleSpinBox::textFromValue(double val) const
diff --git a/GUI/View/Common/DoubleSpinBox.h b/GUI/View/Common/DoubleSpinBox.h
index 4b55286fdd0..c22ecdf2f13 100644
--- a/GUI/View/Common/DoubleSpinBox.h
+++ b/GUI/View/Common/DoubleSpinBox.h
@@ -17,17 +17,17 @@
 #include "GUI/Model/Descriptor/DoubleProperty.h"
 #include <QDoubleSpinBox>
 
-//! SpinBox for DoubleDescriptors, supporting units.
+//! SpinBox for DoubleProperties, supporting units.
 class DoubleSpinBox : public QDoubleSpinBox {
     Q_OBJECT
 public:
-    //! Create a DoubleSpinBox with the information found in a DoubleDescriptor.
+    //! Create a DoubleSpinBox with the information found in a DoubleProperty.
     //!
     //! The spin box will be fully initialized (tooltip, limits, unit, current value, size policy).
     //! Furthermore, the spin box will prohibit accidental changes by the mouse wheel. Otherwise it
     //! would be dangerous if the spin box is on a scrollable form - unintended and unnoticed
     //! changes would take place when just scrolling through the form.
-    DoubleSpinBox(const DoubleDescriptor& d, bool easyScrollable = false, int precision = 2,
+    DoubleSpinBox(const DoubleProperty& d, bool easyScrollable = false, int precision = 2,
                   double singleStepSize = 0.1, QWidget* parent = nullptr);
     //! Set a display unit.
     //!
@@ -41,9 +41,9 @@ public:
     QString displayUnitAsString() const;
 
     //! The descriptor on which this spinbox operates.
-    const DoubleDescriptor& valueDescriptor() const;
+    DoubleDescriptor valueDescriptor() const;
 
-    //! Returns the unit of the contained DoubleDescriptor.
+    //! Returns the unit of the contained DoubleProperty.
     //!
     //! If the unit is defined as a string, this method returns Unit::other. To get the string, use
     //! valueDescriptor().unit
@@ -75,7 +75,7 @@ private:
 private:
     Unit m_displayUnit = Unit::unitless;
 
-    DoubleDescriptor m_valueDescriptor;
+    const DoubleProperty& m_valueProperty;
     bool easyScrollable;
 
     //! it was decided to not show the unit as a suffix. However, this may be user
-- 
GitLab