diff --git a/docs/source/release/v5.1.0/reflectometry.rst b/docs/source/release/v5.1.0/reflectometry.rst index a71d0666d39acf5c92d06923762b89e72527297e..0be9fb8adc55ec2a5d15a65ac55e564804735e20 100644 --- a/docs/source/release/v5.1.0/reflectometry.rst +++ b/docs/source/release/v5.1.0/reflectometry.rst @@ -16,6 +16,9 @@ Bug fixes --------- - Save/Load settings: A bug has been fixed where Experiment/Instrument settings were not being restored if the instrument changes on load. -- New Batch loses settings: A bug has been fixed where creating a new Batch would result in the Experiment/Instrument settings of all batches being reset to their defaults. +- Lost settings on New Batch and Restore Defaults: + + - A bug has been fixed where creating a new Batch would result in the Experiment/Instrument settings of all batches being reset to their defaults. + - A bug has been fixed where clicking Restore Defaults on an Experiment/Instrument tab would cause all Experiment and Instrument tabs in every batch to be reset to defaults. Now, only the tab where you click Restore Defaults is changed. :ref:`Release 5.1.0 <v5.1.0>` diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp index da2ad7b330a24bbdc46033c18828192ebfc172cc..61e6016cc89b37bdf659753c196125f5664b696f 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp @@ -42,8 +42,8 @@ void ExperimentPresenter::notifySettingsChanged() { void ExperimentPresenter::notifyRestoreDefaultsRequested() { // Trigger a reload of the instrument to get up-to-date settings. - // After the instrument is updated, the defaults will be restored. m_mainPresenter->notifyUpdateInstrumentRequested(); + restoreDefaults(); } void ExperimentPresenter::notifySummationTypeChanged() { diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp index c886b80071be63f6a237d63a19416b81c520bc1e..0efe747cc9d4a74d1575dd0ea6f1aa1e5770b628 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/InstrumentPresenter.cpp @@ -45,8 +45,8 @@ void InstrumentPresenter::notifySettingsChanged() { void InstrumentPresenter::notifyRestoreDefaultsRequested() { // Trigger a reload of the instrument to get up-to-date settings. - // After the instrument is updated, the defaults will be restored. m_mainPresenter->notifyUpdateInstrumentRequested(); + restoreDefaults(); } Instrument const &InstrumentPresenter::instrument() const { return m_model; } diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp index da2c9aff0f665074fe905445abcc030dabb056de..c6fe9441d611a5ceca34144357ed011f5cd7a872 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp @@ -126,9 +126,15 @@ void MainWindowPresenter::notifyAnyBatchReductionPaused() { void MainWindowPresenter::notifyChangeInstrumentRequested( std::string const &newInstrumentName) { - // Re-load instrument with the new name, if it has changed - if (newInstrumentName != instrumentName()) - updateInstrument(newInstrumentName); + auto const hasChanged = (newInstrumentName != instrumentName()); + // Re-load instrument regardless of whether it has changed, e.g. if we are + // creating a new batch the instrument may not have changed but we still want + // the most up to date settings + updateInstrument(newInstrumentName); + // However, only perform updates if the instrument has changed, otherwise we + // may trigger overriding of user-specified settings + if (hasChanged) + onInstrumentChanged(); } void MainWindowPresenter::notifyUpdateInstrumentRequested() { @@ -246,14 +252,6 @@ void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { loadAlg->execute(); MatrixWorkspace_sptr instWorkspace = loadAlg->getProperty("OutputWorkspace"); m_instrument = instWorkspace->getInstrument(); - - // Notify child presenters - for (auto &batchPresenter : m_batchPresenters) - batchPresenter->notifyInstrumentChanged(instrumentName); - - // Notify the slit calculator - m_slitCalculator->setCurrentInstrumentName(instrumentName); - m_slitCalculator->processInstrumentHasBeenChanged(); } void MainWindowPresenter::setDefaultInstrument( @@ -273,6 +271,16 @@ void MainWindowPresenter::setDefaultInstrument( g_log.notice() << "Instrument changed to " << requiredInstrument; } } + +void MainWindowPresenter::onInstrumentChanged() { + // Notify child presenters + for (auto &batchPresenter : m_batchPresenters) + batchPresenter->notifyInstrumentChanged(instrumentName()); + + // Notify the slit calculator + m_slitCalculator->setCurrentInstrumentName(instrumentName()); + m_slitCalculator->processInstrumentHasBeenChanged(); +} } // namespace ISISReflectometry } // namespace CustomInterfaces } // namespace MantidQt diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h index 7e276e8adeb3e0f5a87121fab836526aadb9eab8..b07f6ee488a30ba2fe8cda6bc81b6b80dbe81fb5 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h @@ -90,6 +90,7 @@ private: std::string const &instrument); void updateInstrument(const std::string &instrumentName); void setDefaultInstrument(const std::string &newInstrument); + void onInstrumentChanged(); void disableSaveAndLoadBatch(); void enableSaveAndLoadBatch(); @@ -100,4 +101,4 @@ private: }; } // namespace ISISReflectometry } // namespace CustomInterfaces -} // namespace MantidQt \ No newline at end of file +} // namespace MantidQt diff --git a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h index f2c2b6aba0b9e39afa11d111ed0bd300f3d88da2..464a01a69d21a291a902058545e65bd1673cf674 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h @@ -252,6 +252,7 @@ public: void testChangeInstrumentRequestedUpdatesInstrumentInChildPresenters() { auto presenter = makePresenter(); + setupInstrument(presenter, "INTER"); auto const instrument = std::string("POLREF"); EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) .Times(1); @@ -261,13 +262,24 @@ public: verifyAndClear(); } - void testUpdateInstrumentUpdatesInstrumentInChildPresenters() { + void testChangeInstrumentRequestedDoesNotUpdateInstrumentIfNotChanged() { auto presenter = makePresenter(); auto const instrument = setupInstrument(presenter, "POLREF"); EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) - .Times(1); + .Times(0); EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)) - .Times(1); + .Times(0); + presenter.notifyChangeInstrumentRequested(instrument); + verifyAndClear(); + } + + void testUpdateInstrumentDoesNotUpdateInstrumentInChildPresenters() { + auto presenter = makePresenter(); + auto const instrument = setupInstrument(presenter, "POLREF"); + EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) + .Times(0); + EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)) + .Times(0); presenter.notifyUpdateInstrumentRequested(); verifyAndClear(); }