diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp index e80d3b4d9529ecd32553570b007a500604e88002..1eca98b6708214a404765b06679fc26fcf65a2fe 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp @@ -80,6 +80,12 @@ void BatchPresenter::notifyInstrumentChanged( instrumentChanged(instrumentName); } +void BatchPresenter::notifyRestoreDefaultsRequested() { + // We need to re-load the instrument and restore defaults from it, just as if + // we had changed instrument. + instrumentChanged(m_instrument->getName()); +} + void BatchPresenter::notifySettingsChanged() { settingsChanged(); } void BatchPresenter::notifyReductionResumed() { resumeReduction(); } diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h index bf3d1096afdf24521f0ec4172f6009b77919a9e1..9e88c3495df6241de028c7a36ae897ddeef894a3 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.h @@ -60,6 +60,7 @@ public: void notifyAutoreductionPaused() override; void notifyAutoreductionCompleted() override; void notifyInstrumentChanged(const std::string &instName) override; + void notifyRestoreDefaultsRequested() override; void notifySettingsChanged() override; bool hasPerAngleOptions() const override; MantidWidgets::DataProcessor::OptionsQMap diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h index b7e3459579c9d4ce29b9df5ab398c381f2e31078..c11937b941b11b88b259dfacfadfaf3c67f84557 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/IBatchPresenter.h @@ -33,6 +33,7 @@ public: virtual void notifyAutoreductionPaused() = 0; virtual void notifyAutoreductionCompleted() = 0; virtual void notifyInstrumentChanged(const std::string &instName) = 0; + virtual void notifyRestoreDefaultsRequested() = 0; virtual void notifySettingsChanged() = 0; /// Transmission runs for a specific run angle diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp index 433cbd8ff29cc1b16b77a7c31571a3ac1b1bb06d..619b141cc9c40f6190de04f00ef83553e00b940e 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp @@ -36,8 +36,7 @@ void ExperimentPresenter::notifySettingsChanged() { } void ExperimentPresenter::notifyRestoreDefaultsRequested() { - restoreDefaults(); - m_mainPresenter->notifySettingsChanged(); + m_mainPresenter->notifyRestoreDefaultsRequested(); } void ExperimentPresenter::notifySummationTypeChanged() { diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp index dfe5902e27b7e7cdb48b57a7fbaa07bb54312a20..1cf96516c16a0aec435892b5e45729173d92d68d 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp @@ -41,8 +41,7 @@ void InstrumentPresenter::notifySettingsChanged() { } void InstrumentPresenter::notifyRestoreDefaultsRequested() { - restoreDefaults(); - m_mainPresenter->notifySettingsChanged(); + m_mainPresenter->notifyRestoreDefaultsRequested(); } Instrument const &InstrumentPresenter::instrument() const { return m_model; } diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h index a4e89dcc082f3d8532eae504ab0b47d2ba7f436d..2afbe5cd8fa0bef2a8c5d93f15d5d430f08cbdb8 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Batch/BatchPresenterTest.h @@ -69,6 +69,20 @@ public: verifyAndClear(); } + void testInstrumentChangedWhenRestoreDefaultsRequested() { + auto presenter = makePresenter(); + // Set the instrument first + auto const instrument = std::string("INTER"); + presenter.notifyInstrumentChanged(instrument); + // Now when we restore defaults, it should call instrument changed with the + // existing instrument + EXPECT_CALL(*m_runsPresenter, instrumentChanged(instrument)).Times(1); + EXPECT_CALL(*m_experimentPresenter, instrumentChanged(instrument)).Times(1); + EXPECT_CALL(*m_instrumentPresenter, instrumentChanged(instrument)).Times(1); + presenter.notifyRestoreDefaultsRequested(); + verifyAndClear(); + } + void testChildPresentersUpdatedWhenSettingsChanged() { auto presenter = makePresenter(); EXPECT_CALL(*m_runsPresenter, settingsChanged()).Times(1); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h index 8162d0dafab909370ed1581c274744bd0746438d..9c70cc6b9a550a724e85208eaeba368efff10d94 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h @@ -435,33 +435,33 @@ public: } void testRestoreDefaultsNotifiesMainPresenter() { - auto defaultOptions = expectDefaults(makeModel()); - auto presenter = makePresenter(std::move(defaultOptions)); - EXPECT_CALL(m_mainPresenter, notifySettingsChanged()).Times(AtLeast(1)); + auto presenter = makePresenter(); + EXPECT_CALL(m_mainPresenter, notifyRestoreDefaultsRequested()) + .Times(AtLeast(1)); presenter.notifyRestoreDefaultsRequested(); verifyAndClear(); } - void testRestoreDefaultsUpdatesAnalysisModeInView() { + void testInstrumentChangedUpdatesAnalysisModeInView() { auto model = makeModelWithAnalysisMode(AnalysisMode::MultiDetector); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setAnalysisMode("MultiDetectorAnalysis")).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesAnalysisModeInModel() { + void testInstrumentChangedUpdatesAnalysisModeInModel() { auto model = makeModelWithAnalysisMode(AnalysisMode::MultiDetector); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); TS_ASSERT_EQUALS(presenter.experiment().analysisMode(), AnalysisMode::MultiDetector); verifyAndClear(); } - void testRestoreDefaultsUpdatesReductionOptionsInView() { + void testInstrumentChangedUpdatesReductionOptionsInView() { auto model = makeModelWithReduction(SummationType::SumInQ, ReductionType::NonFlatSample, true); auto defaultOptions = expectDefaults(model); @@ -469,16 +469,16 @@ public: EXPECT_CALL(m_view, setSummationType("SumInQ")).Times(1); EXPECT_CALL(m_view, setReductionType("NonFlatSample")).Times(1); EXPECT_CALL(m_view, setIncludePartialBins(true)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesReductionOptionsInModel() { + void testInstrumentChangedUpdatesReductionOptionsInModel() { auto model = makeModelWithReduction(SummationType::SumInQ, ReductionType::NonFlatSample, true); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); TS_ASSERT_EQUALS(presenter.experiment().summationType(), SummationType::SumInQ); TS_ASSERT_EQUALS(presenter.experiment().reductionType(), @@ -487,25 +487,25 @@ public: verifyAndClear(); } - void testRestoreDefaultsUpdatesDebugOptionsInView() { + void testInstrumentChangedUpdatesDebugOptionsInView() { auto model = makeModelWithDebug(true); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setDebugOption(true)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesDebugOptionsInModel() { + void testInstrumentChangedUpdatesDebugOptionsInModel() { auto model = makeModelWithDebug(true); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); TS_ASSERT_EQUALS(presenter.experiment().debug(), true); verifyAndClear(); } - void testRestoreDefaultsUpdatesPerThetaInView() { + void testInstrumentChangedUpdatesPerThetaInView() { auto perThetaDefaults = PerThetaDefaults(boost::none, TransmissionRunPair(), RangeInQ(0.01, 0.03, 0.2), 0.7, std::string("390-415")); @@ -516,17 +516,17 @@ public: {"", "", "", "0.010000", "0.200000", "0.030000", "0.700000", "390-415"}}; EXPECT_CALL(m_view, setPerAngleOptions(expected)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesPerThetaInModel() { + void testInstrumentChangedUpdatesPerThetaInModel() { auto model = makeModelWithPerThetaDefaults(PerThetaDefaults( boost::none, TransmissionRunPair(), RangeInQ(0.01, 0.03, 0.2), 0.7, std::string("390-415"))); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); auto expected = PerThetaDefaults(boost::none, TransmissionRunPair(), RangeInQ(0.01, 0.03, 0.2), 0.7, std::string("390-415")); @@ -536,28 +536,28 @@ public: verifyAndClear(); } - void testRestoreDefaultsUpdatesTransmissionRunRangeInView() { + void testInstrumentChangedUpdatesTransmissionRunRangeInView() { auto model = makeModelWithTransmissionRunRange(RangeInLambda{10.0, 12.0}); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setTransmissionStartOverlap(10.0)).Times(1); EXPECT_CALL(m_view, setTransmissionEndOverlap(12.0)).Times(1); EXPECT_CALL(m_view, showTransmissionRangeValid()).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesTransmissionRunRangeInModel() { + void testInstrumentChangedUpdatesTransmissionRunRangeInModel() { auto model = makeModelWithTransmissionRunRange(RangeInLambda{10.0, 12.0}); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); auto const expected = RangeInLambda{10.0, 12.0}; TS_ASSERT_EQUALS(presenter.experiment().transmissionRunRange(), expected); verifyAndClear(); } - void testRestoreDefaultsUpdatesCorrectionInView() { + void testInstrumentChangedUpdatesCorrectionInView() { auto model = makeModelWithCorrections( PolarizationCorrections(PolarizationCorrectionType::ParameterFile), FloodCorrections(FloodCorrectionType::ParameterFile)); @@ -566,17 +566,17 @@ public: EXPECT_CALL(m_view, setPolarizationCorrectionType("ParameterFile")) .Times(1); EXPECT_CALL(m_view, setFloodCorrectionType("ParameterFile")).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesCorrectionInModel() { + void testInstrumentChangedUpdatesCorrectionInModel() { auto model = makeModelWithCorrections( PolarizationCorrections(PolarizationCorrectionType::ParameterFile), FloodCorrections(FloodCorrectionType::ParameterFile)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); TS_ASSERT_EQUALS( presenter.experiment().polarizationCorrections().correctionType(), PolarizationCorrectionType::ParameterFile); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h index 933d4faa8e54471e1f1e7f550bf66096b52af728..9d42bedd911560d84774aad963f4db518488ac22 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Instrument/InstrumentPresenterTest.h @@ -253,14 +253,14 @@ public: } void testRestoreDefaultsNotifiesMainPresenter() { - auto defaultOptions = expectDefaults(makeModel()); - auto presenter = makePresenter(std::move(defaultOptions)); - EXPECT_CALL(m_mainPresenter, notifySettingsChanged()).Times(AtLeast(1)); + auto presenter = makePresenter(); + EXPECT_CALL(m_mainPresenter, notifyRestoreDefaultsRequested()) + .Times(AtLeast(1)); presenter.notifyRestoreDefaultsRequested(); verifyAndClear(); } - void testRestoreDefaultsUpdatesMonitorOptionsInView() { + void testInstrumentChangedUpdatesMonitorOptionsInView() { auto model = makeModelWithMonitorOptions(MonitorCorrections( 2, true, RangeInLambda(17.0, 18.0), RangeInLambda(4.0, 10.0))); auto defaultOptions = expectDefaults(model); @@ -271,16 +271,16 @@ public: EXPECT_CALL(m_view, setMonitorBackgroundMax(18.0)).Times(1); EXPECT_CALL(m_view, setMonitorIntegralMin(4.0)).Times(1); EXPECT_CALL(m_view, setMonitorIntegralMax(10.0)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesMonitorOptionsInModel() { + void testInstrumentChangedUpdatesMonitorOptionsInModel() { auto model = makeModelWithMonitorOptions(MonitorCorrections( 2, true, RangeInLambda(17.0, 18.0), RangeInLambda(4.0, 10.0))); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); TS_ASSERT_EQUALS(presenter.instrument().monitorIndex(), 2); TS_ASSERT_EQUALS(presenter.instrument().integratedMonitors(), true); TS_ASSERT_EQUALS(presenter.instrument().monitorBackgroundRange(), @@ -290,27 +290,27 @@ public: verifyAndClear(); } - void testRestoreDefaultsUpdatesWavelengthRangeInView() { + void testInstrumentChangedUpdatesWavelengthRangeInView() { auto model = makeModelWithWavelengthRange(RangeInLambda(1.5, 17.0)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); EXPECT_CALL(m_view, setLambdaMin(1.5)).Times(1); EXPECT_CALL(m_view, setLambdaMax(17.0)).Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesWavelengthRangeInModel() { + void testInstrumentChangedUpdatesWavelengthRangeInModel() { auto model = makeModelWithWavelengthRange(RangeInLambda(1.5, 17.0)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); TS_ASSERT_EQUALS(presenter.instrument().wavelengthRange(), RangeInLambda(1.5, 17.0)); verifyAndClear(); } - void testRestoreDefaultsUpdatesUpdatesDetectorOptionsInView() { + void testInstrumentChangedUpdatesUpdatesDetectorOptionsInView() { auto model = makeModelWithDetectorCorrections( DetectorCorrections(true, DetectorCorrectionType::RotateAroundSample)); auto defaultOptions = expectDefaults(model); @@ -318,16 +318,16 @@ public: EXPECT_CALL(m_view, setCorrectDetectors(true)).Times(1); EXPECT_CALL(m_view, setDetectorCorrectionType("RotateAroundSample")) .Times(1); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); verifyAndClear(); } - void testRestoreDefaultsUpdatesUpdatesDetectorOptionsInModel() { + void testInstrumentChangedUpdatesUpdatesDetectorOptionsInModel() { auto model = makeModelWithDetectorCorrections( DetectorCorrections(true, DetectorCorrectionType::RotateAroundSample)); auto defaultOptions = expectDefaults(model); auto presenter = makePresenter(std::move(defaultOptions)); - presenter.notifyRestoreDefaultsRequested(); + presenter.instrumentChanged("INTER"); auto const expected = DetectorCorrections(true, DetectorCorrectionType::RotateAroundSample); TS_ASSERT_EQUALS(presenter.instrument().detectorCorrections(), expected); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h b/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h index 0e217197b6e9ba75d52bda379a4ac151b07872b0..9183f74018730ded976f17ad91e342dcbc1d6aff 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/ReflMockObjects.h @@ -86,6 +86,7 @@ public: MOCK_CONST_METHOD1(getOptionsForAngle, OptionsQMap(const double)); MOCK_CONST_METHOD0(hasPerAngleOptions, bool()); MOCK_METHOD1(notifyInstrumentChanged, void(const std::string &)); + MOCK_METHOD0(notifyRestoreDefaultsRequested, void()); MOCK_METHOD0(notifySettingsChanged, void()); MOCK_CONST_METHOD0(isProcessing, bool()); MOCK_CONST_METHOD0(isAutoreducing, bool());