From 642876946a681564cfdb448f7cbae6e72d9a4c52 Mon Sep 17 00:00:00 2001
From: Tobias Knopff <t.knopff@fz-juelich.de>
Date: Mon, 31 May 2021 10:05:09 +0200
Subject: [PATCH] Make RectangularDetectorItem::P_ALIGNMENT private

---
 GUI/Models/RectangularDetectorItem.cpp        | 20 +++++++++++++++++++
 GUI/Models/RectangularDetectorItem.h          |  8 +++++++-
 .../RectangularDetectorEditor.cpp             |  7 +++----
 Tests/UnitTests/GUI/TestDetectorItems.cpp     |  9 +++------
 4 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/GUI/Models/RectangularDetectorItem.cpp b/GUI/Models/RectangularDetectorItem.cpp
index 897be27b9a7..bb94253aa49 100644
--- a/GUI/Models/RectangularDetectorItem.cpp
+++ b/GUI/Models/RectangularDetectorItem.cpp
@@ -179,6 +179,26 @@ BasicAxisItem* RectangularDetectorItem::yAxisItem()
         static_cast<const RectangularDetectorItem*>(this)->yAxisItem());
 }
 
+bool RectangularDetectorItem::isAlignmentPropertyName(const QString& name)
+{
+    return name == P_ALIGNMENT;
+}
+
+SessionItem* RectangularDetectorItem::alignmentItem() const
+{
+    return getItem(P_ALIGNMENT);
+}
+
+ComboProperty RectangularDetectorItem::alignment() const
+{
+    return getItemValue(P_ALIGNMENT).value<ComboProperty>();
+}
+
+void RectangularDetectorItem::setAlignment(const ComboProperty& alignment)
+{
+    setItemValue(P_ALIGNMENT, QVariant::fromValue<ComboProperty>(alignment));
+}
+
 std::unique_ptr<IDetector2D> RectangularDetectorItem::createDomainDetector() const
 {
     // basic axes parameters
diff --git a/GUI/Models/RectangularDetectorItem.h b/GUI/Models/RectangularDetectorItem.h
index 30126cf14c9..e53c779e305 100644
--- a/GUI/Models/RectangularDetectorItem.h
+++ b/GUI/Models/RectangularDetectorItem.h
@@ -16,6 +16,7 @@
 #define BORNAGAIN_GUI_MODELS_RECTANGULARDETECTORITEM_H
 
 #include "Base/Vector/Vectors3D.h"
+#include "GUI/Models/ComboProperty.h"
 #include "GUI/Models/DetectorItems.h"
 
 class BasicAxisItem;
@@ -24,9 +25,9 @@ class BA_CORE_API_ RectangularDetectorItem : public DetectorItem {
 private:
     static const QString P_X_AXIS;
     static const QString P_Y_AXIS;
+    static const QString P_ALIGNMENT;
 
 public:
-    static const QString P_ALIGNMENT;
     static const QString P_NORMAL;
     static const QString P_DIRECTION;
     static const QString P_U0;
@@ -49,6 +50,11 @@ public:
     const BasicAxisItem* yAxisItem() const;
     BasicAxisItem* yAxisItem();
 
+    static bool isAlignmentPropertyName(const QString& name);
+    SessionItem* alignmentItem() const;
+    ComboProperty alignment() const;
+    void setAlignment(const ComboProperty& alignment);
+
 private:
     std::unique_ptr<IDetector2D> createDomainDetector() const override;
     void update_properties_appearance();
diff --git a/GUI/Views/InstrumentWidgets/RectangularDetectorEditor.cpp b/GUI/Views/InstrumentWidgets/RectangularDetectorEditor.cpp
index df7ba4e6fc0..ecd4a895b49 100644
--- a/GUI/Views/InstrumentWidgets/RectangularDetectorEditor.cpp
+++ b/GUI/Views/InstrumentWidgets/RectangularDetectorEditor.cpp
@@ -41,7 +41,7 @@ RectangularDetectorEditor::RectangularDetectorEditor(QWidget* parent)
 
 void RectangularDetectorEditor::onPropertyChanged(const QString& propertyName)
 {
-    if (propertyName == RectangularDetectorItem::P_ALIGNMENT)
+    if (RectangularDetectorItem::isAlignmentPropertyName(propertyName))
         init_alignment_editors();
 }
 
@@ -112,7 +112,7 @@ void RectangularDetectorEditor::init_editors()
     m_resolutionFunctionEditor->setItem(resFuncGroup);
 
     m_alignmentEditor->clearEditor();
-    m_alignmentEditor->setItem(detectorItem()->getItem(RectangularDetectorItem::P_ALIGNMENT));
+    m_alignmentEditor->setItem(detectorItem()->alignmentItem());
 
     init_alignment_editors();
 }
@@ -128,8 +128,7 @@ void RectangularDetectorEditor::init_alignment_editors()
     m_directionEditor->clearEditor();
     m_directionEditor->hide();
 
-    ComboProperty alignment =
-        detectorItem()->getItemValue(RectangularDetectorItem::P_ALIGNMENT).value<ComboProperty>();
+    ComboProperty alignment = detectorItem()->alignment();
 
     if (alignment.getValue() == "Generic") {
         m_positionsEditor->show();
diff --git a/Tests/UnitTests/GUI/TestDetectorItems.cpp b/Tests/UnitTests/GUI/TestDetectorItems.cpp
index 7f5866fdd22..c7837dd8ef0 100644
--- a/Tests/UnitTests/GUI/TestDetectorItems.cpp
+++ b/Tests/UnitTests/GUI/TestDetectorItems.cpp
@@ -16,18 +16,15 @@ TEST_F(TestDetectorItems, test_detectorAlignment)
     InstrumentModel model;
     auto detector = model.insertItem<RectangularDetectorItem>();
 
-    ComboProperty alignment =
-        detector->getItemValue(RectangularDetectorItem::P_ALIGNMENT).value<ComboProperty>();
+    ComboProperty alignment = detector->alignment();
     // generic has some more items visible
     alignment.setValue("Generic");
-    detector->setItemValue(RectangularDetectorItem::P_ALIGNMENT,
-                           QVariant::fromValue<ComboProperty>(alignment));
+    detector->setAlignment(alignment);
     EXPECT_TRUE(detector->getItem(RectangularDetectorItem::P_NORMAL)->isVisible());
 
     // should be disabled if we switch
     alignment.setValue("Perpendicular to reflected beam");
-    detector->setItemValue(RectangularDetectorItem::P_ALIGNMENT,
-                           QVariant::fromValue<ComboProperty>(alignment));
+    detector->setAlignment(alignment);
     EXPECT_FALSE(detector->getItem(RectangularDetectorItem::P_NORMAL)->isVisible());
 }
 
-- 
GitLab