From 2f84067b103cef4b1bed3f5af687a27e147775da Mon Sep 17 00:00:00 2001
From: Gemma Guest <gemma.guest@stfc.ac.uk>
Date: Wed, 24 Apr 2019 17:46:15 +0100
Subject: [PATCH] Minor refactoring to reduce duplication

Re #23051
---
 .../GUI/Experiment/ExperimentPresenter.cpp             | 10 +++++++---
 .../GUI/Experiment/ExperimentPresenter.h               |  3 +++
 .../GUI/Instrument/InstrumentPresenter.cpp             | 10 +++++++---
 .../GUI/Instrument/InstrumentPresenter.h               |  1 +
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp
index 5f0a67f1647..780043b7242 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp
@@ -37,8 +37,7 @@ void ExperimentPresenter::notifySettingsChanged() {
 }
 
 void ExperimentPresenter::notifyRestoreDefaultsRequested() {
-  m_model = experimentDefaults(m_mainPresenter->instrument());
-  updateViewFromModel();
+  restoreDefaults();
   m_mainPresenter->notifySettingsChanged();
 }
 
@@ -112,7 +111,12 @@ void ExperimentPresenter::instrumentChanged(
     std::string const &instrumentName,
     Mantid::Geometry::Instrument_const_sptr instrument) {
   UNUSED_ARG(instrumentName);
-  m_model = experimentDefaults(instrument);
+  UNUSED_ARG(instrument);
+  restoreDefaults();
+}
+
+void ExperimentPresenter::restoreDefaults() {
+  m_model = experimentDefaults(m_mainPresenter->instrument());
   updateViewFromModel();
 }
 
diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h
index 416fa6b34b6..42f073cd511 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h
@@ -68,6 +68,9 @@ public:
 
 private:
   IBatchPresenter *m_mainPresenter;
+
+  void restoreDefaults();
+
   ExperimentValidationResult validateExperimentFromView();
   PolarizationCorrections polarizationCorrectionsFromView();
   FloodCorrections floodCorrectionsFromView();
diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp
index 91515da51d4..7649ebcce51 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp
@@ -39,8 +39,7 @@ void InstrumentPresenter::notifySettingsChanged() {
 }
 
 void InstrumentPresenter::notifyRestoreDefaultsRequested() {
-  m_model = instrumentDefaults(m_mainPresenter->instrument());
-  updateViewFromModel();
+  restoreDefaults();
   m_mainPresenter->notifySettingsChanged();
 }
 
@@ -106,7 +105,12 @@ void InstrumentPresenter::instrumentChanged(
     std::string const &instrumentName,
     Mantid::Geometry::Instrument_const_sptr instrument) {
   UNUSED_ARG(instrumentName);
-  m_model = instrumentDefaults(instrument);
+  UNUSED_ARG(instrument);
+  restoreDefaults();
+}
+
+void InstrumentPresenter::restoreDefaults() {
+  m_model = instrumentDefaults(m_mainPresenter->instrument());
   updateViewFromModel();
 }
 
diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.h
index dac58657f60..9236c3037fc 100644
--- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.h
+++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.h
@@ -48,6 +48,7 @@ private:
   Instrument m_model;
   IBatchPresenter *m_mainPresenter;
 
+  void restoreDefaults();
   boost::optional<RangeInLambda> wavelengthRangeFromView();
   boost::optional<RangeInLambda> monitorBackgroundRangeFromView();
   boost::optional<RangeInLambda> monitorIntegralRangeFromView();
-- 
GitLab