From d25e1e0948825e3a27c9a917d644e75fb4b3c82e Mon Sep 17 00:00:00 2001
From: Gemma Guest <gemma.guest@stfc.ac.uk>
Date: Wed, 3 Oct 2018 11:19:53 +0100
Subject: [PATCH] Correction type enabled/disabled according to check box

Detector correction type is only applicable if CorrectDetectors is checked, so disable it if it's not checked

Re #22263
---
 .../GUI/Instrument/IInstrumentView.h          |  2 ++
 .../GUI/Instrument/InstrumentPresenter.cpp    |  4 ++++
 .../GUI/Instrument/InstrumentView.cpp         |  8 +++++++
 .../GUI/Instrument/InstrumentView.h           |  2 ++
 .../Instrument/InstrumentPresenterTest.h      | 24 +++++++++++++++++--
 .../Instrument/MockInstrumentView.h           |  2 ++
 6 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/IInstrumentView.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/IInstrumentView.h
index 4b915d2c19a..ad71e20a225 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/IInstrumentView.h
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/IInstrumentView.h
@@ -70,6 +70,8 @@ public:
 
   virtual void disableAll() = 0;
   virtual void enableAll() = 0;
+  virtual void enableDetectorCorrectionType() = 0;
+  virtual void disableDetectorCorrectionType() = 0;
 };
 } // namespace CustomInterfaces
 } // namespace MantidQt
diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp
index cbee08b9808..340c4750605 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp
@@ -87,6 +87,10 @@ DetectorCorrectionType InstrumentPresenter::detectorCorrectionTypeFromView() {
 DetectorCorrections InstrumentPresenter::detectorCorrectionsFromView() {
   auto const correctPositions = m_view->getCorrectDetectors();
   auto const correctionType = detectorCorrectionTypeFromView();
+  if (correctPositions)
+    m_view->enableDetectorCorrectionType();
+  else
+    m_view->disableDetectorCorrectionType();
   return DetectorCorrections(correctPositions, correctionType);
 }
 
diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.cpp
index 63feb810743..d860df33050 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.cpp
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.cpp
@@ -90,6 +90,14 @@ void InstrumentView::disableAll() { m_ui.instSettingsGroup->setEnabled(false); }
 
 void InstrumentView::enableAll() { m_ui.instSettingsGroup->setEnabled(true); }
 
+void InstrumentView::enableDetectorCorrectionType() {
+  m_ui.detectorCorrectionTypeComboBox->setEnabled(true);
+}
+
+void InstrumentView::disableDetectorCorrectionType() {
+  m_ui.detectorCorrectionTypeComboBox->setEnabled(false);
+}
+
 void InstrumentView::registerSettingsWidgets(Mantid::API::IAlgorithm_sptr alg) {
   registerInstrumentSettingsWidgets(alg);
 }
diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.h
index 1aac787d29a..3027d84bc0e 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.h
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentView.h
@@ -66,6 +66,8 @@ public:
 
   void disableAll() override;
   void enableAll() override;
+  void enableDetectorCorrectionType() override;
+  void disableDetectorCorrectionType() override;
 
 public slots:
   void onSettingsChanged();
diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h
index ea0fdf334e9..07b37264198 100644
--- a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h
+++ b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h
@@ -137,7 +137,7 @@ public:
     runTestForValidMonitorBackgroundRange(range, boost::none);
   }
 
-  void testCorrectDetectorsToggled() {
+  void testCorrectDetectorsToggledUpdatesModel() {
     auto presenter = makePresenter();
     auto const correctDetectors = !presenter.instrument().correctDetectors();
 
@@ -150,7 +150,27 @@ public:
     verifyAndClear();
   }
 
-  void testSetDetectorCorrectionType() {
+  void testEnablingCorrectDetectorsEnablesCorrectionType() {
+    auto presenter = makePresenter();
+
+    EXPECT_CALL(m_view, getCorrectDetectors()).WillOnce(Return(true));
+    EXPECT_CALL(m_view, enableDetectorCorrectionType()).Times(1);
+    presenter.notifySettingsChanged();
+
+    verifyAndClear();
+  }
+
+  void testDiablingCorrectDetectorsDisablesCorrectionType() {
+    auto presenter = makePresenter();
+
+    EXPECT_CALL(m_view, getCorrectDetectors()).WillOnce(Return(false));
+    EXPECT_CALL(m_view, disableDetectorCorrectionType()).Times(1);
+    presenter.notifySettingsChanged();
+
+    verifyAndClear();
+  }
+
+  void testSetDetectorCorrectionTypeUpdatesModel() {
     auto presenter = makePresenter();
 
     EXPECT_CALL(m_view, getDetectorCorrectionType())
diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/MockInstrumentView.h b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/MockInstrumentView.h
index 631914875a7..5e3956a8236 100644
--- a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/MockInstrumentView.h
+++ b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/MockInstrumentView.h
@@ -28,6 +28,8 @@ public:
   MOCK_CONST_METHOD0(getDetectorCorrectionType, std::string());
   MOCK_METHOD0(disableAll, void());
   MOCK_METHOD0(enableAll, void());
+  MOCK_METHOD0(enableDetectorCorrectionType, void());
+  MOCK_METHOD0(disableDetectorCorrectionType, void());
 };
 } // namespace CustomInterfaces
 } // namespace MantidQt
-- 
GitLab