From 13d78f4651c2277adeae5fbe865d0a80cb341eec Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Fri, 8 Dec 2023 09:59:42 +0100
Subject: [PATCH] convert all spin boxes in MaskEditorToolpanel

---
 GUI/Model/Mask/MaskItems.cpp           | 16 +++---
 GUI/View/Setup/MaskEditorToolpanel.cpp | 67 +++++---------------------
 GUI/View/Setup/MaskEditorToolpanel.h   |  5 --
 3 files changed, 21 insertions(+), 67 deletions(-)

diff --git a/GUI/Model/Mask/MaskItems.cpp b/GUI/Model/Mask/MaskItems.cpp
index 115ecefe037..9b99b1c1b2a 100644
--- a/GUI/Model/Mask/MaskItems.cpp
+++ b/GUI/Model/Mask/MaskItems.cpp
@@ -118,10 +118,10 @@ void MaskItem::readFrom(QXmlStreamReader* r)
 RectangleItem::RectangleItem()
 {
     setMaskName("RectangleMask");
-    m_xLow.init("lower x", "lower x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xLow");
-    m_xUp.init("lower x", "upper x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xUp");
-    m_yLow.init("lower y", "lower y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yLow");
-    m_yUp.init("lower y", "upper y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yUp");
+    m_xLow.init("x left", "left x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xLow");
+    m_xUp.init("x right", "right x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xUp");
+    m_yLow.init("y bottom", "bottom y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yLow");
+    m_yUp.init("y top", "top y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yUp");
 }
 
 std::unique_ptr<IShape2D> RectangleItem::createShape() const
@@ -241,8 +241,8 @@ std::unique_ptr<IShape2D> RegionOfInterestItem::createShape() const
 
 PolygonPointItem::PolygonPointItem()
 {
-    m_posX.init("lower x", "x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xPos");
-    m_posY.init("lower y", "y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yPos");
+    m_posX.init("x", "x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xPos");
+    m_posY.init("y", "y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yPos");
 }
 
 void PolygonPointItem::setPosX(double val)
@@ -372,7 +372,7 @@ void PolygonItem::readFrom(QXmlStreamReader* r)
 VerticalLineItem::VerticalLineItem()
 {
     setMaskName("VerticalLineMask");
-    m_posX.init("lower x", "x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xPos");
+    m_posX.init("x", "x coordinate", 0, 4, RealLimits::limited(0., 4091.), "xPos");
 }
 
 std::unique_ptr<IShape2D> VerticalLineItem::createShape() const
@@ -429,7 +429,7 @@ void VerticalLineItem::readFrom(QXmlStreamReader* r)
 HorizontalLineItem::HorizontalLineItem()
 {
     setMaskName("HorizontalLineMask");
-    m_posY.init("lower y", "y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yPos");
+    m_posY.init("y", "y coordinate", 0, 4, RealLimits::limited(0., 4091.), "yPos");
 }
 
 std::unique_ptr<IShape2D> HorizontalLineItem::createShape() const
diff --git a/GUI/View/Setup/MaskEditorToolpanel.cpp b/GUI/View/Setup/MaskEditorToolpanel.cpp
index 591ae570556..822448e7f91 100644
--- a/GUI/View/Setup/MaskEditorToolpanel.cpp
+++ b/GUI/View/Setup/MaskEditorToolpanel.cpp
@@ -19,19 +19,17 @@
 #include "GUI/Model/Mask/MaskItems.h"
 #include "GUI/Model/Project/ProjectDocument.h"
 #include "GUI/View/Numeric/DoubleSpinBox.h"
-#include "GUI/View/Numeric/NumberUtil.h"
 #include "GUI/View/Tool/LayoutUtil.h"
 #include "GUI/View/Widget/GroupBoxes.h"
 #include <QCheckBox>
-#include <QDoubleSpinBox>
 #include <QLineEdit>
 
 namespace {
 
-void addSpinBox(MaskItem* mask, QFormLayout* layout, const QString& name, DoubleProperty& property)
+void addSpinBox(MaskItem* mask, QFormLayout* layout, DoubleProperty& property)
 {
     auto* spinbox = new DoubleSpinBox(&property);
-    layout->addRow(name + ":", spinbox);
+    layout->addRow(property.label() + ":", spinbox);
     QObject::connect(spinbox, &DoubleSpinBox::valueChanged, [mask](double) {
         gProjectDocument.value()->setModified();
 	emit mask->maskGeometryChanged();
@@ -184,59 +182,20 @@ void MaskEditorToolpanel::createMaskEditorUI()
     }
 
     if (auto* c = dynamic_cast<RectangleItem*>(maskItem)) {
-        addSpinBox(maskItem, m_editor_layout, "x low", c->xLow());
-        addMaskSpinBox(
-            "ylow", [c] { return c->yLow(); }, [c](double v) { c->setYLow(v); },
-            RealLimits::limitless());
-        addMaskSpinBox(
-            "xup", [c] { return c->xUp(); }, [c](double v) { c->setXUp(v); },
-            RealLimits::limitless());
-        addMaskSpinBox(
-            "yup", [c] { return c->yUp(); }, [c](double v) { c->setYUp(v); },
-            RealLimits::limitless());
+        addSpinBox(maskItem, m_editor_layout, c->xLow());
+        addSpinBox(maskItem, m_editor_layout, c->xUp());
+        addSpinBox(maskItem, m_editor_layout, c->yLow());
+        addSpinBox(maskItem, m_editor_layout, c->yUp());
     } else if (auto* c = dynamic_cast<EllipseItem*>(maskItem)) {
-        addMaskSpinBox(
-            "X center", [c] { return c->xCenter(); }, [c](double v) { c->setXCenter(v); },
-            RealLimits::limitless());
-        addMaskSpinBox(
-            "Y center", [c] { return c->yCenter(); }, [c](double v) { c->setYCenter(v); },
-            RealLimits::limitless());
-        addMaskSpinBox(
-            "X radius", [c] { return c->xRadius(); }, [c](double v) { c->setXRadius(v); },
-            RealLimits::nonnegative());
-        addMaskSpinBox(
-            "Y radius", [c] { return c->yRadius(); }, [c](double v) { c->setYRadius(v); },
-            RealLimits::nonnegative());
-        addMaskSpinBox(
-            "Angle", [c] { return c->angle(); }, [c](double v) { c->setAngle(v); },
-            RealLimits::limitless());
+        addSpinBox(maskItem, m_editor_layout, c->xCenter());
+        addSpinBox(maskItem, m_editor_layout, c->yCenter());
+        addSpinBox(maskItem, m_editor_layout, c->xRadius());
+        addSpinBox(maskItem, m_editor_layout, c->yRadius());
+        // addSpinBox(maskItem, m_editor_layout, c->angle());
     } else if (auto* c = dynamic_cast<VerticalLineItem*>(maskItem))
-        addMaskSpinBox(
-            "X position", [c] { return c->posX(); }, [c](double v) { c->setPosX(v); },
-            RealLimits::limitless());
+        addSpinBox(maskItem, m_editor_layout, c->posX());
     else if (auto* c = dynamic_cast<HorizontalLineItem*>(maskItem))
-        addMaskSpinBox(
-            "Y position", [c] { return c->posY(); }, [c](double v) { c->setPosY(v); },
-            RealLimits::limitless());
-}
-
-void MaskEditorToolpanel::addMaskSpinBox(const QString& label, function<double()> getter,
-                                         function<void(double)> setter, const RealLimits& limits)
-{
-    auto* spinbox = new QDoubleSpinBox;
-    GUI::View::NumberUtil::configSpinBox(spinbox, 3, limits);
-    spinbox->setValue(getter());
-
-    connect(spinbox, &QDoubleSpinBox::valueChanged, this, [setter](double newVal) {
-        setter(newVal);
-        gProjectDocument.value()->setModified();
-    });
-    connect(m_currentMaskItem, &MaskItem::maskGeometryChanged, spinbox, [=] {
-        QSignalBlocker b(spinbox);
-        spinbox->setValue(getter());
-    });
-
-    m_editor_layout->addRow(label + ":", spinbox);
+        addSpinBox(maskItem, m_editor_layout, c->posY());
 }
 
 void MaskEditorToolpanel::addMaskCheckBox(const QString& title, function<bool()> getter,
diff --git a/GUI/View/Setup/MaskEditorToolpanel.h b/GUI/View/Setup/MaskEditorToolpanel.h
index c8cf625c684..0ac6ec0be46 100644
--- a/GUI/View/Setup/MaskEditorToolpanel.h
+++ b/GUI/View/Setup/MaskEditorToolpanel.h
@@ -26,7 +26,6 @@
 class Data2DItem;
 class MaskContainerModel;
 class MaskItem;
-class RealLimits;
 
 //! Tool widget for MaskEditor
 
@@ -55,10 +54,6 @@ private:
     //! Set the current mask and creates the UI to edit the mask's properties
     void setCurrentMaskItem(MaskItem* maskItem);
 
-    //! Add a spinbox to edit a mask's double value
-    void addMaskSpinBox(const QString& label, std::function<double()> getter,
-                        std::function<void(double)> setter, const RealLimits& limits);
-
     //! Add a checkbox to edit a mask's boolean value
     void addMaskCheckBox(const QString& title, std::function<bool()> getter,
                          std::function<void(bool)> setter);
-- 
GitLab