From bcbb220a5b5339a9f7e75ac0d593ee6b47e15d5a Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 17:19:03 +0100
Subject: [PATCH 1/9] RectangularDetectorItem: rm old item names

---
 GUI/Model/Device/RectangularDetectorItem.h | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/GUI/Model/Device/RectangularDetectorItem.h b/GUI/Model/Device/RectangularDetectorItem.h
index 2c555d386eb..2c0d8f6bad3 100644
--- a/GUI/Model/Device/RectangularDetectorItem.h
+++ b/GUI/Model/Device/RectangularDetectorItem.h
@@ -20,17 +20,6 @@
 #include "GUI/Model/Device/DetectorItems.h"
 
 class RectangularDetectorItem : public DetectorItem {
-private:
-    static constexpr auto P_X_AXIS{"X axis"};
-    static constexpr auto P_Y_AXIS{"Y axis"};
-    static constexpr auto P_NORMAL{"Normal vector"};
-    static constexpr auto P_DIRECTION{"Direction vector"};
-    static constexpr auto P_U0{"u0"};
-    static constexpr auto P_V0{"v0"};
-    static constexpr auto P_DBEAM_U0{"u0 (dbeam)"};
-    static constexpr auto P_DBEAM_V0{"v0 (dbeam)"};
-    static constexpr auto P_DISTANCE{"Distance"};
-
 public:
     RectangularDetectorItem();
 
-- 
GitLab


From 4653ed60d905ecf5d74f5aaccc22c3fc8ce95ecd Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 17:45:58 +0100
Subject: [PATCH 2/9] RectangularDetectorItem: create alignment_names_map

---
 GUI/Model/Device/RectangularDetectorItem.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index f76d86d52f6..cf3fca3ce21 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -45,6 +45,13 @@ const double default_detector_width = 20.0;
 const double default_detector_height = 20.0;
 const double default_detector_distance = 1000.0;
 
+const QMap<QString, RectangularDetector::EDetectorArrangement> alignment_names_map = {
+    {"Generic", RectangularDetector::GENERIC},
+    {"Perpendicular to sample x-axis", RectangularDetector::PERPENDICULAR_TO_SAMPLE},
+    {"Perpendicular to direct beam", RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM},
+    {"Perpendicular to reflected beam", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM},
+    {"Perpendicular to reflected beam (intersection unknown)", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS}};
+
 QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
 {
     switch (a) {
@@ -126,7 +133,9 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwValue(s, Tag::YSize, m_ySize);
     Serialize::rwProperty(s, Tag::Width, m_width);
     Serialize::rwProperty(s, Tag::Height, m_height);
+
     Serialize::rwValue(s, Tag::Alignment, alignment);
+
     m_normalVector.rwProperty(s, Tag::NormalVector);
     m_directionVector.rwProperty(s, Tag::DirectionVector);
     Serialize::rwProperty(s, Tag::u0, m_u0);
-- 
GitLab


From 3d0d9461696e59a0d496a6bab7e4b4be3252d0d7 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 18:07:07 +0100
Subject: [PATCH 3/9] RectangularDetectorItem: storing alignment in
 ComboProperty

---
 GUI/Model/CatJob/MinimizerItemCatalog.h      |  2 --
 GUI/Model/Device/RectangularDetectorItem.cpp | 26 +++++++++++++-------
 GUI/Model/Device/RectangularDetectorItem.h   |  5 ++--
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/GUI/Model/CatJob/MinimizerItemCatalog.h b/GUI/Model/CatJob/MinimizerItemCatalog.h
index 8011ae429bb..c14ed1f5ff3 100644
--- a/GUI/Model/CatJob/MinimizerItemCatalog.h
+++ b/GUI/Model/CatJob/MinimizerItemCatalog.h
@@ -17,8 +17,6 @@
 
 #include "GUI/Util/ComboProperty.h"
 
-class MinimizerItem;
-
 //! The MinimizerItemCatalog class is a static class to provide MinimizerItem
 //! with the list of available minimizers/algorithms.
 
diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index cf3fca3ce21..97fba5e21bf 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -114,14 +114,15 @@ RectangularDetectorItem::RectangularDetectorItem()
     m_distance.init("Distance", "Distance from the sample origin to the detector plane",
                     default_detector_distance, "mm", "distance");
 
-    m_detectorAlignment = RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM;
+    m_detectorAlignment.fromList(alignment_names_map.keys(),
+                                 alignment_names_map.key(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
 
     updateTooltips();
 }
 
 void RectangularDetectorItem::serialize(Streamer& s)
 {
-    int alignment = m_detectorAlignment;
+//    int alignment = m_detectorAlignment_TEMP;
 
     s.assertVersion(0);
     // base class members
@@ -134,7 +135,7 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwProperty(s, Tag::Width, m_width);
     Serialize::rwProperty(s, Tag::Height, m_height);
 
-    Serialize::rwValue(s, Tag::Alignment, alignment);
+//    Serialize::rwValue(s, Tag::Alignment, alignment);
 
     m_normalVector.rwProperty(s, Tag::NormalVector);
     m_directionVector.rwProperty(s, Tag::DirectionVector);
@@ -143,21 +144,28 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwProperty(s, Tag::Distance, m_distance);
 
     if (s.xmlReader()) {
-        setDetectorAlignment(static_cast<RectangularDetector::EDetectorArrangement>(alignment));
+//        setDetectorAlignment(static_cast<RectangularDetector::EDetectorArrangement>(alignment));
         m_resolutionFunction->setUnit("mm");
     }
 }
 
+void RectangularDetectorItem::setDetectorAlignment(const QString &alignment)
+{
+    ASSERT(alignment_names_map.keys().contains(alignment));
+    setDetectorAlignment(alignment_names_map.value(alignment));
+}
+
 void RectangularDetectorItem::setDetectorAlignment(
     RectangularDetector::EDetectorArrangement alignment)
 {
-    m_detectorAlignment = alignment;
+    m_detectorAlignment.setCurrentValue(alignment_names_map.key(alignment));
     updateTooltips();
 }
 
 RectangularDetector::EDetectorArrangement RectangularDetectorItem::detectorAlignment() const
 {
-    return m_detectorAlignment;
+    ASSERT(alignment_names_map.keys().contains(m_detectorAlignment.currentValue()));
+    return alignment_names_map.value(m_detectorAlignment.currentValue());
 }
 
 int RectangularDetectorItem::xSize() const
@@ -193,7 +201,7 @@ RectangularDetectorItem::detectorAlignmentSelection() const
         const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignments()[newIndex]);
     };
 
-    d.currentIndexGetter = [&]() { return alignments().indexOf(m_detectorAlignment); };
+    d.currentIndexGetter = [&]() { return alignments().indexOf(detectorAlignment()); };
     return d;
 }
 
@@ -202,7 +210,7 @@ std::unique_ptr<IDetector> RectangularDetectorItem::createDomainDetector() const
     auto result = std::make_unique<RectangularDetector>(xSize(), width(), ySize(), height());
 
     // distance and alignment
-    switch (m_detectorAlignment) {
+    switch (detectorAlignment()) {
     case RectangularDetector::GENERIC:
         result->setDetectorPosition(m_normalVector, m_u0, m_v0, m_directionVector);
         break;
@@ -228,7 +236,7 @@ std::unique_ptr<IDetector> RectangularDetectorItem::createDomainDetector() const
 
 void RectangularDetectorItem::updateTooltips()
 {
-    switch (m_detectorAlignment) {
+    switch (detectorAlignment()) {
     case RectangularDetector::GENERIC:
         m_u0.setTooltip(
             "u-coordinate of point of intersection of normal vector and detector plane");
diff --git a/GUI/Model/Device/RectangularDetectorItem.h b/GUI/Model/Device/RectangularDetectorItem.h
index 2c0d8f6bad3..17c8fb9d522 100644
--- a/GUI/Model/Device/RectangularDetectorItem.h
+++ b/GUI/Model/Device/RectangularDetectorItem.h
@@ -39,7 +39,9 @@ public:
     const DoubleProperty& height() const { return m_height; }
     void setHeight(double v) { m_height.setValue(v); }
 
+    void setDetectorAlignment(const QString& alignment);
     void setDetectorAlignment(RectangularDetector::EDetectorArrangement alignment);
+
     RectangularDetector::EDetectorArrangement detectorAlignment() const;
     SelectionDescriptor<RectangularDetector::EDetectorArrangement>
     detectorAlignmentSelection() const;
@@ -69,11 +71,10 @@ private:
     void updateTooltips();
 
 private:
-    RectangularDetector::EDetectorArrangement m_detectorAlignment;
+    ComboProperty m_detectorAlignment;
     int m_xSize;
     int m_ySize;
 
-protected:
     VectorProperty m_normalVector;
     VectorProperty m_directionVector;
 
-- 
GitLab


From 362905fe77f8028a61c1d9f8f12d2a000ea9c32c Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 18:09:10 +0100
Subject: [PATCH 4/9] RectangularDetectorItem: mv setter & getters to header

---
 GUI/Model/Device/RectangularDetectorItem.cpp | 36 +++++---------------
 GUI/Model/Device/RectangularDetectorItem.h   |  8 ++---
 2 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index 97fba5e21bf..d485b001c42 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -50,7 +50,8 @@ const QMap<QString, RectangularDetector::EDetectorArrangement> alignment_names_m
     {"Perpendicular to sample x-axis", RectangularDetector::PERPENDICULAR_TO_SAMPLE},
     {"Perpendicular to direct beam", RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM},
     {"Perpendicular to reflected beam", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM},
-    {"Perpendicular to reflected beam (intersection unknown)", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS}};
+    {"Perpendicular to reflected beam (intersection unknown)",
+     RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS}};
 
 QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
 {
@@ -114,15 +115,16 @@ RectangularDetectorItem::RectangularDetectorItem()
     m_distance.init("Distance", "Distance from the sample origin to the detector plane",
                     default_detector_distance, "mm", "distance");
 
-    m_detectorAlignment.fromList(alignment_names_map.keys(),
-                                 alignment_names_map.key(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
+    m_detectorAlignment.fromList(
+        alignment_names_map.keys(),
+        alignment_names_map.key(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
 
     updateTooltips();
 }
 
 void RectangularDetectorItem::serialize(Streamer& s)
 {
-//    int alignment = m_detectorAlignment_TEMP;
+    //    int alignment = m_detectorAlignment_TEMP;
 
     s.assertVersion(0);
     // base class members
@@ -135,7 +137,7 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwProperty(s, Tag::Width, m_width);
     Serialize::rwProperty(s, Tag::Height, m_height);
 
-//    Serialize::rwValue(s, Tag::Alignment, alignment);
+    //    Serialize::rwValue(s, Tag::Alignment, alignment);
 
     m_normalVector.rwProperty(s, Tag::NormalVector);
     m_directionVector.rwProperty(s, Tag::DirectionVector);
@@ -144,12 +146,12 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwProperty(s, Tag::Distance, m_distance);
 
     if (s.xmlReader()) {
-//        setDetectorAlignment(static_cast<RectangularDetector::EDetectorArrangement>(alignment));
+        //        setDetectorAlignment(static_cast<RectangularDetector::EDetectorArrangement>(alignment));
         m_resolutionFunction->setUnit("mm");
     }
 }
 
-void RectangularDetectorItem::setDetectorAlignment(const QString &alignment)
+void RectangularDetectorItem::setDetectorAlignment(const QString& alignment)
 {
     ASSERT(alignment_names_map.keys().contains(alignment));
     setDetectorAlignment(alignment_names_map.value(alignment));
@@ -168,26 +170,6 @@ RectangularDetector::EDetectorArrangement RectangularDetectorItem::detectorAlign
     return alignment_names_map.value(m_detectorAlignment.currentValue());
 }
 
-int RectangularDetectorItem::xSize() const
-{
-    return m_xSize;
-}
-
-int RectangularDetectorItem::ySize() const
-{
-    return m_ySize;
-}
-
-void RectangularDetectorItem::setXSize(size_t nx)
-{
-    m_xSize = static_cast<int>(nx);
-}
-
-void RectangularDetectorItem::setYSize(size_t ny)
-{
-    m_ySize = static_cast<int>(ny);
-}
-
 SelectionDescriptor<RectangularDetector::EDetectorArrangement>
 RectangularDetectorItem::detectorAlignmentSelection() const
 {
diff --git a/GUI/Model/Device/RectangularDetectorItem.h b/GUI/Model/Device/RectangularDetectorItem.h
index 17c8fb9d522..532b3e19a99 100644
--- a/GUI/Model/Device/RectangularDetectorItem.h
+++ b/GUI/Model/Device/RectangularDetectorItem.h
@@ -25,11 +25,11 @@ public:
 
     void serialize(Streamer& s) override;
 
-    int xSize() const override;
-    void setXSize(size_t nx) override;
+    int xSize() const override { return m_xSize; }
+    void setXSize(size_t nx) override { m_xSize = static_cast<int>(nx); }
 
-    int ySize() const override;
-    void setYSize(size_t ny) override;
+    int ySize() const override { return m_ySize; }
+    void setYSize(size_t ny) override { m_ySize = static_cast<int>(ny); }
 
     DoubleProperty& width() { return m_width; }
     const DoubleProperty& width() const { return m_width; }
-- 
GitLab


From 459e71c13936fa21b355a1d873c0eebeb0c8cd6c Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 18:17:04 +0100
Subject: [PATCH 5/9] RectangularDetectorItem: alignment_names_map: swap values
 and keys

---
 GUI/Model/Device/RectangularDetectorItem.cpp | 43 ++++++++------------
 1 file changed, 17 insertions(+), 26 deletions(-)

diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index d485b001c42..39c85fdfa1d 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -45,13 +45,13 @@ const double default_detector_width = 20.0;
 const double default_detector_height = 20.0;
 const double default_detector_distance = 1000.0;
 
-const QMap<QString, RectangularDetector::EDetectorArrangement> alignment_names_map = {
-    {"Generic", RectangularDetector::GENERIC},
-    {"Perpendicular to sample x-axis", RectangularDetector::PERPENDICULAR_TO_SAMPLE},
-    {"Perpendicular to direct beam", RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM},
-    {"Perpendicular to reflected beam", RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM},
-    {"Perpendicular to reflected beam (intersection unknown)",
-     RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS}};
+//! Holds the alignments as expected on the UI (map is sorted by keys)
+const QMap<RectangularDetector::EDetectorArrangement, QString> alignment_names_map = {
+    {RectangularDetector::GENERIC, "Generic"},
+    {RectangularDetector::PERPENDICULAR_TO_SAMPLE, "Perpendicular to sample x-axis"},
+    {RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM, "Perpendicular to direct beam"},
+    {RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM, "Perpendicular to reflected beam"},
+    {RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS, "Perpendicular to reflected beam (intersection unknown)"}};
 
 QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
 {
@@ -71,15 +71,6 @@ QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
     }
 }
 
-//! Returns the alignments as expected on the UI
-QList<RectangularDetector::EDetectorArrangement> alignments()
-{
-    return {RectangularDetector::GENERIC, RectangularDetector::PERPENDICULAR_TO_SAMPLE,
-            RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM,
-            RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM,
-            RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS};
-}
-
 void initResolutionFunction(ResolutionFunctionItem* newFunc, const ResolutionFunctionItem*)
 {
     newFunc->setUnit("mm");
@@ -116,8 +107,8 @@ RectangularDetectorItem::RectangularDetectorItem()
                     default_detector_distance, "mm", "distance");
 
     m_detectorAlignment.fromList(
-        alignment_names_map.keys(),
-        alignment_names_map.key(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
+        alignment_names_map.values(),
+        alignment_names_map.value(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
 
     updateTooltips();
 }
@@ -153,21 +144,21 @@ void RectangularDetectorItem::serialize(Streamer& s)
 
 void RectangularDetectorItem::setDetectorAlignment(const QString& alignment)
 {
-    ASSERT(alignment_names_map.keys().contains(alignment));
-    setDetectorAlignment(alignment_names_map.value(alignment));
+    ASSERT(alignment_names_map.values().contains(alignment));
+    setDetectorAlignment(alignment_names_map.key(alignment));
 }
 
 void RectangularDetectorItem::setDetectorAlignment(
     RectangularDetector::EDetectorArrangement alignment)
 {
-    m_detectorAlignment.setCurrentValue(alignment_names_map.key(alignment));
+    m_detectorAlignment.setCurrentValue(alignment_names_map.value(alignment));
     updateTooltips();
 }
 
 RectangularDetector::EDetectorArrangement RectangularDetectorItem::detectorAlignment() const
 {
-    ASSERT(alignment_names_map.keys().contains(m_detectorAlignment.currentValue()));
-    return alignment_names_map.value(m_detectorAlignment.currentValue());
+    ASSERT(alignment_names_map.values().contains(m_detectorAlignment.currentValue()));
+    return alignment_names_map.key(m_detectorAlignment.currentValue());
 }
 
 SelectionDescriptor<RectangularDetector::EDetectorArrangement>
@@ -176,14 +167,14 @@ RectangularDetectorItem::detectorAlignmentSelection() const
     SelectionDescriptor<RectangularDetector::EDetectorArrangement> d;
 
     d.label = "Alignment";
-    for (auto a : alignments())
+    for (auto a : alignment_names_map.keys())
         d.options << alignmentTitle(a);
 
     d.currentIndexSetter = [&](int newIndex) {
-        const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignments()[newIndex]);
+        const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignment_names_map.keys()[newIndex]);
     };
 
-    d.currentIndexGetter = [&]() { return alignments().indexOf(detectorAlignment()); };
+    d.currentIndexGetter = [&]() { return alignment_names_map.keys().indexOf(detectorAlignment()); };
     return d;
 }
 
-- 
GitLab


From b1cdb96e95fbac33beaec353e8265d39daf6b617 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 18:41:07 +0100
Subject: [PATCH 6/9] RectangularDetectorItem: m_detectorAlignment
 initialization fix

---
 GUI/Model/Device/RectangularDetectorItem.cpp | 24 +++-----------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index 39c85fdfa1d..5300c498a78 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -53,24 +53,6 @@ const QMap<RectangularDetector::EDetectorArrangement, QString> alignment_names_m
     {RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM, "Perpendicular to reflected beam"},
     {RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS, "Perpendicular to reflected beam (intersection unknown)"}};
 
-QString alignmentTitle(RectangularDetector::EDetectorArrangement a)
-{
-    switch (a) {
-    case RectangularDetector::GENERIC:
-        return "Generic";
-    case RectangularDetector::PERPENDICULAR_TO_SAMPLE:
-        return "Perpendicular to sample x-axis";
-    case RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM:
-        return "Perpendicular to direct beam";
-    case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM:
-        return "Perpendicular to reflected beam";
-    case RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS:
-        return "Perpendicular to reflected beam (intersection unknown)";
-    default:
-        ASSERT(false);
-    }
-}
-
 void initResolutionFunction(ResolutionFunctionItem* newFunc, const ResolutionFunctionItem*)
 {
     newFunc->setUnit("mm");
@@ -106,7 +88,7 @@ RectangularDetectorItem::RectangularDetectorItem()
     m_distance.init("Distance", "Distance from the sample origin to the detector plane",
                     default_detector_distance, "mm", "distance");
 
-    m_detectorAlignment.fromList(
+    m_detectorAlignment = ComboProperty::fromList(
         alignment_names_map.values(),
         alignment_names_map.value(RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM));
 
@@ -167,8 +149,8 @@ RectangularDetectorItem::detectorAlignmentSelection() const
     SelectionDescriptor<RectangularDetector::EDetectorArrangement> d;
 
     d.label = "Alignment";
-    for (auto a : alignment_names_map.keys())
-        d.options << alignmentTitle(a);
+    for (auto a : alignment_names_map.values())
+        d.options << a;
 
     d.currentIndexSetter = [&](int newIndex) {
         const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignment_names_map.keys()[newIndex]);
-- 
GitLab


From 64fccb98b8bb2b171ada6534e4ac8e09bf4b5df0 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 18:52:12 +0100
Subject: [PATCH 7/9] RectangularDetectorItem: m_detectorAlignment is
 serialized

---
 GUI/Model/Device/RectangularDetectorItem.cpp | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index 5300c498a78..3f21dd27c33 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -12,10 +12,10 @@
 //
 //  ************************************************************************************************
 
-#include "GUI/Model/Device/RectangularDetectorItem.h"
 #include "Device/Detector/RectangularDetector.h"
 #include "GUI/Model/CatDevice/ResolutionFunctionItemCatalog.h"
 #include "GUI/Model/Device/AxesItems.h"
+#include "GUI/Model/Device/RectangularDetectorItem.h"
 #include "GUI/Model/Device/ResolutionFunctionItems.h"
 #include "GUI/Support/XML/Serialize.h"
 #include "GUI/Support/XML/UtilXML.h"
@@ -97,8 +97,6 @@ RectangularDetectorItem::RectangularDetectorItem()
 
 void RectangularDetectorItem::serialize(Streamer& s)
 {
-    //    int alignment = m_detectorAlignment_TEMP;
-
     s.assertVersion(0);
     // base class members
     Serialize::rwClass(s, Tag::Masks, m_maskItems);
@@ -110,7 +108,18 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwProperty(s, Tag::Width, m_width);
     Serialize::rwProperty(s, Tag::Height, m_height);
 
-    //    Serialize::rwValue(s, Tag::Alignment, alignment);
+    if(auto* w = s.xmlWriter()){
+        w->writeStartElement(Tag::Alignment);
+        m_detectorAlignment.writeTo(w);
+        w->writeEndElement();
+    } else {
+        auto* r = s.xmlReader();
+        r->readNextStartElement();
+        if (r->name() == Tag::Alignment) {
+            m_detectorAlignment.readFrom(r);
+            GUI::Session::XML::gotoEndElementOfTag(r, Tag::Alignment);
+        }
+    }
 
     m_normalVector.rwProperty(s, Tag::NormalVector);
     m_directionVector.rwProperty(s, Tag::DirectionVector);
@@ -119,7 +128,6 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwProperty(s, Tag::Distance, m_distance);
 
     if (s.xmlReader()) {
-        //        setDetectorAlignment(static_cast<RectangularDetector::EDetectorArrangement>(alignment));
         m_resolutionFunction->setUnit("mm");
     }
 }
-- 
GitLab


From ba6005dce45ca954cb90ee0fe5cfc2759af94144 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 19:05:55 +0100
Subject: [PATCH 8/9] RectangularDetectorItem: descriptor removed

---
 GUI/Model/Device/RectangularDetectorItem.cpp    | 17 -----------------
 GUI/Model/Device/RectangularDetectorItem.h      |  6 ++----
 GUI/View/Instrument/DetectorAlignmentEditor.cpp | 15 ++++++++-------
 GUI/View/Tool/WidgetUtils.cpp                   |  8 ++++++++
 GUI/View/Tool/WidgetUtils.h                     |  3 +++
 5 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index 3f21dd27c33..057e8d67343 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -151,23 +151,6 @@ RectangularDetector::EDetectorArrangement RectangularDetectorItem::detectorAlign
     return alignment_names_map.key(m_detectorAlignment.currentValue());
 }
 
-SelectionDescriptor<RectangularDetector::EDetectorArrangement>
-RectangularDetectorItem::detectorAlignmentSelection() const
-{
-    SelectionDescriptor<RectangularDetector::EDetectorArrangement> d;
-
-    d.label = "Alignment";
-    for (auto a : alignment_names_map.values())
-        d.options << a;
-
-    d.currentIndexSetter = [&](int newIndex) {
-        const_cast<RectangularDetectorItem*>(this)->setDetectorAlignment(alignment_names_map.keys()[newIndex]);
-    };
-
-    d.currentIndexGetter = [&]() { return alignment_names_map.keys().indexOf(detectorAlignment()); };
-    return d;
-}
-
 std::unique_ptr<IDetector> RectangularDetectorItem::createDomainDetector() const
 {
     auto result = std::make_unique<RectangularDetector>(xSize(), width(), ySize(), height());
diff --git a/GUI/Model/Device/RectangularDetectorItem.h b/GUI/Model/Device/RectangularDetectorItem.h
index 532b3e19a99..71a1a4ace12 100644
--- a/GUI/Model/Device/RectangularDetectorItem.h
+++ b/GUI/Model/Device/RectangularDetectorItem.h
@@ -39,13 +39,11 @@ public:
     const DoubleProperty& height() const { return m_height; }
     void setHeight(double v) { m_height.setValue(v); }
 
+    const ComboProperty& detectorAlignmentCombo() const { return m_detectorAlignment; }
+    RectangularDetector::EDetectorArrangement detectorAlignment() const;
     void setDetectorAlignment(const QString& alignment);
     void setDetectorAlignment(RectangularDetector::EDetectorArrangement alignment);
 
-    RectangularDetector::EDetectorArrangement detectorAlignment() const;
-    SelectionDescriptor<RectangularDetector::EDetectorArrangement>
-    detectorAlignmentSelection() const;
-
     VectorProperty& normalVector() { return m_normalVector; }
     const VectorProperty& normalVector() const { return m_normalVector; }
     void setNormalVector(const R3& v) { m_normalVector.setR3(v); }
diff --git a/GUI/View/Instrument/DetectorAlignmentEditor.cpp b/GUI/View/Instrument/DetectorAlignmentEditor.cpp
index e1a19757387..df69f75fd6d 100644
--- a/GUI/View/Instrument/DetectorAlignmentEditor.cpp
+++ b/GUI/View/Instrument/DetectorAlignmentEditor.cpp
@@ -50,13 +50,14 @@ DetectorAlignmentEditor::DetectorAlignmentEditor(QWidget* parent, RectangularDet
     m_formLayout->setContentsMargins(0, 15, 0, 0);
     m_formLayout->setSpacing(8);
 
-    auto* m_combo =
-        GUI::Util::createComboBoxFromDescriptor(item->detectorAlignmentSelection(), [=](int) {
-            createAligmentWidgets();
-            emit dataChanged();
-        });
-
-    m_formLayout->addRow("Alignment:", m_combo);
+    m_formLayout->addRow("Alignment:",
+                         GUI::Util::createSafeComboBox(
+                             [=] { return item->detectorAlignmentCombo(); },
+    [=](const QString& t) {
+        item->setDetectorAlignment(t);
+        createAligmentWidgets();
+        emit dataChanged();
+    }));
 
     createAligmentWidgets();
 }
diff --git a/GUI/View/Tool/WidgetUtils.cpp b/GUI/View/Tool/WidgetUtils.cpp
index 04628dd913d..c79e06c2ebc 100644
--- a/GUI/View/Tool/WidgetUtils.cpp
+++ b/GUI/View/Tool/WidgetUtils.cpp
@@ -54,6 +54,14 @@ QComboBox* GUI::Util::createComboBox(function<ComboProperty()> comboFunction,
     return combo;
 }
 
+QComboBox *GUI::Util::createSafeComboBox(function<ComboProperty ()> comboFunction,
+                                         function<void (const QString &)> slot,
+                                         QList<function<void ()> > *updaters, QString tooltip)
+{
+    return createComboBox(comboFunction, slot, updaters, tooltip, false);
+}
+
+
 DoubleSpinBox* GUI::Util::createDoubleSpinBoxRow(QFormLayout* parentLayout, DoubleProperty& d,
                                                  function<void(double)> slot)
 {
diff --git a/GUI/View/Tool/WidgetUtils.h b/GUI/View/Tool/WidgetUtils.h
index 0edb0e55296..c0d43f27d7b 100644
--- a/GUI/View/Tool/WidgetUtils.h
+++ b/GUI/View/Tool/WidgetUtils.h
@@ -46,6 +46,9 @@ QComboBox* createComboBox(std::function<ComboProperty()> comboFunction,
                           std::function<void(const QString&)> slot,
                           QList<std::function<void()>>* updaters = nullptr, QString tooltip = "",
                           bool isScrollable = true);
+QComboBox* createSafeComboBox(std::function<ComboProperty ()> comboFunction,
+                              std::function<void (const QString &)> slot,
+                              QList<std::function<void ()> > *updaters = nullptr, QString tooltip = "");
 
 //! Create a combo box with the information found in a selection descriptor.
 //!
-- 
GitLab


From 1841d973b38e6e431660ebc2077b62f756028f55 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 6 Dec 2022 19:10:43 +0100
Subject: [PATCH 9/9] clang-format

---
 GUI/Model/Device/RectangularDetectorItem.cpp    |  7 ++++---
 GUI/View/Instrument/DetectorAlignmentEditor.cpp | 15 +++++++--------
 GUI/View/Tool/WidgetUtils.cpp                   |  6 +++---
 GUI/View/Tool/WidgetUtils.h                     |  7 ++++---
 4 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp
index 057e8d67343..0fa21c62ffe 100644
--- a/GUI/Model/Device/RectangularDetectorItem.cpp
+++ b/GUI/Model/Device/RectangularDetectorItem.cpp
@@ -12,10 +12,10 @@
 //
 //  ************************************************************************************************
 
+#include "GUI/Model/Device/RectangularDetectorItem.h"
 #include "Device/Detector/RectangularDetector.h"
 #include "GUI/Model/CatDevice/ResolutionFunctionItemCatalog.h"
 #include "GUI/Model/Device/AxesItems.h"
-#include "GUI/Model/Device/RectangularDetectorItem.h"
 #include "GUI/Model/Device/ResolutionFunctionItems.h"
 #include "GUI/Support/XML/Serialize.h"
 #include "GUI/Support/XML/UtilXML.h"
@@ -51,7 +51,8 @@ const QMap<RectangularDetector::EDetectorArrangement, QString> alignment_names_m
     {RectangularDetector::PERPENDICULAR_TO_SAMPLE, "Perpendicular to sample x-axis"},
     {RectangularDetector::PERPENDICULAR_TO_DIRECT_BEAM, "Perpendicular to direct beam"},
     {RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM, "Perpendicular to reflected beam"},
-    {RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS, "Perpendicular to reflected beam (intersection unknown)"}};
+    {RectangularDetector::PERPENDICULAR_TO_REFLECTED_BEAM_DPOS,
+     "Perpendicular to reflected beam (intersection unknown)"}};
 
 void initResolutionFunction(ResolutionFunctionItem* newFunc, const ResolutionFunctionItem*)
 {
@@ -108,7 +109,7 @@ void RectangularDetectorItem::serialize(Streamer& s)
     Serialize::rwProperty(s, Tag::Width, m_width);
     Serialize::rwProperty(s, Tag::Height, m_height);
 
-    if(auto* w = s.xmlWriter()){
+    if (auto* w = s.xmlWriter()) {
         w->writeStartElement(Tag::Alignment);
         m_detectorAlignment.writeTo(w);
         w->writeEndElement();
diff --git a/GUI/View/Instrument/DetectorAlignmentEditor.cpp b/GUI/View/Instrument/DetectorAlignmentEditor.cpp
index df69f75fd6d..d4a591010cb 100644
--- a/GUI/View/Instrument/DetectorAlignmentEditor.cpp
+++ b/GUI/View/Instrument/DetectorAlignmentEditor.cpp
@@ -50,14 +50,13 @@ DetectorAlignmentEditor::DetectorAlignmentEditor(QWidget* parent, RectangularDet
     m_formLayout->setContentsMargins(0, 15, 0, 0);
     m_formLayout->setSpacing(8);
 
-    m_formLayout->addRow("Alignment:",
-                         GUI::Util::createSafeComboBox(
-                             [=] { return item->detectorAlignmentCombo(); },
-    [=](const QString& t) {
-        item->setDetectorAlignment(t);
-        createAligmentWidgets();
-        emit dataChanged();
-    }));
+    m_formLayout->addRow(
+        "Alignment:", GUI::Util::createSafeComboBox([=] { return item->detectorAlignmentCombo(); },
+                                                    [=](const QString& t) {
+                                                        item->setDetectorAlignment(t);
+                                                        createAligmentWidgets();
+                                                        emit dataChanged();
+                                                    }));
 
     createAligmentWidgets();
 }
diff --git a/GUI/View/Tool/WidgetUtils.cpp b/GUI/View/Tool/WidgetUtils.cpp
index c79e06c2ebc..2888eeb8b3d 100644
--- a/GUI/View/Tool/WidgetUtils.cpp
+++ b/GUI/View/Tool/WidgetUtils.cpp
@@ -54,9 +54,9 @@ QComboBox* GUI::Util::createComboBox(function<ComboProperty()> comboFunction,
     return combo;
 }
 
-QComboBox *GUI::Util::createSafeComboBox(function<ComboProperty ()> comboFunction,
-                                         function<void (const QString &)> slot,
-                                         QList<function<void ()> > *updaters, QString tooltip)
+QComboBox* GUI::Util::createSafeComboBox(function<ComboProperty()> comboFunction,
+                                         function<void(const QString&)> slot,
+                                         QList<function<void()>>* updaters, QString tooltip)
 {
     return createComboBox(comboFunction, slot, updaters, tooltip, false);
 }
diff --git a/GUI/View/Tool/WidgetUtils.h b/GUI/View/Tool/WidgetUtils.h
index c0d43f27d7b..5e514927a90 100644
--- a/GUI/View/Tool/WidgetUtils.h
+++ b/GUI/View/Tool/WidgetUtils.h
@@ -46,9 +46,10 @@ QComboBox* createComboBox(std::function<ComboProperty()> comboFunction,
                           std::function<void(const QString&)> slot,
                           QList<std::function<void()>>* updaters = nullptr, QString tooltip = "",
                           bool isScrollable = true);
-QComboBox* createSafeComboBox(std::function<ComboProperty ()> comboFunction,
-                              std::function<void (const QString &)> slot,
-                              QList<std::function<void ()> > *updaters = nullptr, QString tooltip = "");
+QComboBox* createSafeComboBox(std::function<ComboProperty()> comboFunction,
+                              std::function<void(const QString&)> slot,
+                              QList<std::function<void()>>* updaters = nullptr,
+                              QString tooltip = "");
 
 //! Create a combo box with the information found in a selection descriptor.
 //!
-- 
GitLab