From be47fc1abbd45928a596f239c7db18afbe96236d Mon Sep 17 00:00:00 2001 From: Gemma Guest <gemma.guest@stfc.ac.uk> Date: Wed, 8 May 2019 10:58:40 +0100 Subject: [PATCH] Re-load parameters file on restore defaults This means that the user can edit the parameters file and click Restore Defaults to re-load it without closing the GUI Re #23051 --- .../GUI/Batch/BatchPresenter.cpp | 6 +++ .../GUI/Batch/BatchPresenter.h | 1 + .../GUI/Batch/IBatchPresenter.h | 1 + .../GUI/Experiment/ExperimentPresenter.cpp | 3 +- .../GUI/Instrument/InstrumentPresenter.cpp | 3 +- .../Batch/BatchPresenterTest.h | 14 +++++ .../Experiment/ExperimentPresenterTest.h | 54 +++++++++---------- .../Instrument/InstrumentPresenterTest.h | 30 +++++------ .../test/ISISReflectometry/ReflMockObjects.h | 1 + 9 files changed, 67 insertions(+), 46 deletions(-) diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Batch/BatchPresenter.cpp index e80d3b4d952..1eca98b6708 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 bf3d1096afd..9e88c3495df 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 b7e3459579c..c11937b941b 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 433cbd8ff29..619b141cc9c 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 dfe5902e27b..1cf96516c16 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 a4e89dcc082..2afbe5cd8fa 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 8162d0dafab..9c70cc6b9a5 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 933d4faa8e5..9d42bedd911 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 0e217197b6e..9183f740187 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()); -- GitLab