diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp index 50d06f563e600b38ba2a40ed55dc9c4062c2a09d..c1bb6b086271f18bfeea77219e6a3f8e10285636 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp @@ -57,17 +57,16 @@ void ExperimentPresenter::onReductionResumed() { m_view->disableAll(); } PolarizationCorrections ExperimentPresenter::polarizationCorrectionsFromView() { auto const correctionType = polarizationCorrectionTypeFromString( m_view->getPolarizationCorrectionType()); - auto const cRho = m_view->getCRho(); - auto const cAlpha = m_view->getCAlpha(); - auto const cAp = m_view->getCAp(); - auto const cPp = m_view->getCPp(); - auto corrections = - PolarizationCorrections(correctionType, cRho, cAlpha, cAp, cPp); - if (corrections.enableInputs()) + + if (polarizationCorrectionRequiresInputs(correctionType)) { m_view->enablePolarizationCorrectionInputs(); - else - m_view->disablePolarizationCorrectionInputs(); - return corrections; + return PolarizationCorrections(correctionType, m_view->getCRho(), + m_view->getCAlpha(), m_view->getCAp(), + m_view->getCPp()); + } + + m_view->disablePolarizationCorrectionInputs(); + return PolarizationCorrections(correctionType); } boost::optional<RangeInLambda> diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp index e5f5daa629fe9ca086a5c8a660ffbe88388d35fe..0564e72aa63b44c4b84c2cbe954ede9bd5f676c8 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp @@ -23,11 +23,6 @@ boost::optional<double> PolarizationCorrections::cAp() const { return m_cAp; } boost::optional<double> PolarizationCorrections::cPp() const { return m_cPp; } -bool PolarizationCorrections::enableInputs() const { - return m_correctionType == PolarizationCorrectionType::PA || - m_correctionType == PolarizationCorrectionType::PNR; -} - bool operator!=(PolarizationCorrections const &lhs, PolarizationCorrections const &rhs) { return !(lhs == rhs); diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h index 893eac03d336d4cfe4eaf84211b0af2224720450..a0d1a96156315f25d1cf3b8988d8e88a144179b7 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h @@ -22,20 +22,25 @@ polarizationCorrectionTypeFromString(std::string const &correctionType) { throw std::runtime_error("Unexpected polarization correction type."); } +inline bool polarizationCorrectionRequiresInputs( + PolarizationCorrectionType correctionType) { + return (correctionType == PolarizationCorrectionType::PA || + correctionType == PolarizationCorrectionType::PNR); +} + class MANTIDQT_ISISREFLECTOMETRY_DLL PolarizationCorrections { public: PolarizationCorrections(PolarizationCorrectionType correctionType, - boost::optional<double> CRho, - boost::optional<double> CAlpha, - boost::optional<double> CAp, - boost::optional<double> CPp); + boost::optional<double> CRho = boost::none, + boost::optional<double> CAlpha = boost::none, + boost::optional<double> CAp = boost::none, + boost::optional<double> CPp = boost::none); PolarizationCorrectionType correctionType(); boost::optional<double> cRho() const; boost::optional<double> cAlpha() const; boost::optional<double> cAp() const; boost::optional<double> cPp() const; - bool enableInputs() const; private: PolarizationCorrectionType m_correctionType; diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h index 69814b3ea284a3ed946233aad9f86235d10c1206..6e35cbe2c4d0007a6d52516b10d292e8f1a0d73d 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h @@ -97,7 +97,7 @@ public: verifyAndClear(); } - void testSetPolarizationCorrections() { + void testSetPolarizationCorrectionsUpdatesModel() { auto presenter = makePresenter(); PolarizationCorrections polCorr(PolarizationCorrectionType::PA, 1.2, 1.3, 2.4, 2.5); @@ -115,6 +115,74 @@ public: verifyAndClear(); } + void testSettingPolarizationCorrectionsToNoneDisablesInputs() { + auto presenter = makePresenter(); + PolarizationCorrections polCorr(PolarizationCorrectionType::None); + + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInLambdaDefaults(); + EXPECT_CALL(m_view, getPolarizationCorrectionType()) + .WillOnce(Return("None")); + EXPECT_CALL(m_view, disablePolarizationCorrectionInputs()).Times(1); + EXPECT_CALL(m_view, getCRho()).Times(0); + EXPECT_CALL(m_view, getCAlpha()).Times(0); + EXPECT_CALL(m_view, getCAp()).Times(0); + EXPECT_CALL(m_view, getCPp()).Times(0); + presenter.notifySettingsChanged(); + + verifyAndClear(); + } + + void testSetPolarizationCorrectionsToParameterFileDisablesInputs() { + auto presenter = makePresenter(); + + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInLambdaDefaults(); + EXPECT_CALL(m_view, getPolarizationCorrectionType()) + .WillOnce(Return("ParameterFile")); + EXPECT_CALL(m_view, disablePolarizationCorrectionInputs()).Times(1); + EXPECT_CALL(m_view, getCRho()).Times(0); + EXPECT_CALL(m_view, getCAlpha()).Times(0); + EXPECT_CALL(m_view, getCAp()).Times(0); + EXPECT_CALL(m_view, getCPp()).Times(0); + presenter.notifySettingsChanged(); + + verifyAndClear(); + } + + void testSettingPolarizationCorrectionsToPAEnablesInputs() { + auto presenter = makePresenter(); + + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInLambdaDefaults(); + EXPECT_CALL(m_view, getPolarizationCorrectionType()).WillOnce(Return("PA")); + EXPECT_CALL(m_view, enablePolarizationCorrectionInputs()).Times(1); + EXPECT_CALL(m_view, getCRho()).Times(1); + EXPECT_CALL(m_view, getCAlpha()).Times(1); + EXPECT_CALL(m_view, getCAp()).Times(1); + EXPECT_CALL(m_view, getCPp()).Times(1); + presenter.notifySettingsChanged(); + + verifyAndClear(); + } + + void testSettingPolarizationCorrectionsToPNREnablesInputs() { + auto presenter = makePresenter(); + + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInLambdaDefaults(); + EXPECT_CALL(m_view, getPolarizationCorrectionType()) + .WillOnce(Return("PNR")); + EXPECT_CALL(m_view, enablePolarizationCorrectionInputs()).Times(1); + EXPECT_CALL(m_view, getCRho()).Times(1); + EXPECT_CALL(m_view, getCAlpha()).Times(1); + EXPECT_CALL(m_view, getCAp()).Times(1); + EXPECT_CALL(m_view, getCPp()).Times(1); + presenter.notifySettingsChanged(); + + verifyAndClear(); + } + void testSetTransmissionRunRange() { auto presenter = makePresenter(); RangeInLambda range(7.2, 10);