Skip to content
Snippets Groups Projects
Unverified Commit 822c8793 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #28444 from gemmaguest/28429_fix_incomplete_load_on_refl_gui

Fix bugs with restoring defaults on the reflectometry GUI
parents 022267a2 3c888dd8
No related branches found
No related tags found
No related merge requests found
...@@ -9,4 +9,16 @@ Reflectometry Changes ...@@ -9,4 +9,16 @@ Reflectometry Changes
putting new features at the top of the section, followed by putting new features at the top of the section, followed by
improvements, followed by bug fixes. improvements, followed by bug fixes.
:ref:`Release 5.1.0 <v5.1.0>` ISIS Reflectometry Interface
\ No newline at end of file ############################
Bug fixes
---------
- Save/Load settings: A bug has been fixed where Experiment/Instrument settings were not being restored if the instrument changes on load.
- 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>`
...@@ -77,14 +77,18 @@ void Decoder::decodeBatch(const IMainWindowView *mwv, int batchIndex, ...@@ -77,14 +77,18 @@ void Decoder::decodeBatch(const IMainWindowView *mwv, int batchIndex,
auto runsTablePresenter = auto runsTablePresenter =
dynamic_cast<RunsTablePresenter *>(runsPresenter->m_tablePresenter.get()); dynamic_cast<RunsTablePresenter *>(runsPresenter->m_tablePresenter.get());
auto reductionJobs = &runsTablePresenter->m_model.m_reductionJobs; auto reductionJobs = &runsTablePresenter->m_model.m_reductionJobs;
// We must do the Runs tab first because this sets the instrument, which
// other settings may need to be correct. There is also a notification to set
// defaults for this instrument so we need to do that before other settings
// or it will override them.
decodeRuns(gui->m_runs.get(), reductionJobs, runsTablePresenter,
map[QString("runsView")].toMap());
decodeEvent(gui->m_eventHandling.get(), map[QString("eventView")].toMap()); decodeEvent(gui->m_eventHandling.get(), map[QString("eventView")].toMap());
decodeExperiment(gui->m_experiment.get(), decodeExperiment(gui->m_experiment.get(),
map[QString("experimentView")].toMap()); map[QString("experimentView")].toMap());
decodeInstrument(gui->m_instrument.get(), decodeInstrument(gui->m_instrument.get(),
map[QString("instrumentView")].toMap()); map[QString("instrumentView")].toMap());
decodeSave(gui->m_save.get(), map[QString("saveView")].toMap()); decodeSave(gui->m_save.get(), map[QString("saveView")].toMap());
decodeRuns(gui->m_runs.get(), reductionJobs, runsTablePresenter,
map[QString("runsView")].toMap());
} }
void Decoder::decodeExperiment(const QtExperimentView *gui, void Decoder::decodeExperiment(const QtExperimentView *gui,
......
...@@ -42,8 +42,8 @@ void ExperimentPresenter::notifySettingsChanged() { ...@@ -42,8 +42,8 @@ void ExperimentPresenter::notifySettingsChanged() {
void ExperimentPresenter::notifyRestoreDefaultsRequested() { void ExperimentPresenter::notifyRestoreDefaultsRequested() {
// Trigger a reload of the instrument to get up-to-date settings. // 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(); m_mainPresenter->notifyUpdateInstrumentRequested();
restoreDefaults();
} }
void ExperimentPresenter::notifySummationTypeChanged() { void ExperimentPresenter::notifySummationTypeChanged() {
......
...@@ -45,8 +45,8 @@ void InstrumentPresenter::notifySettingsChanged() { ...@@ -45,8 +45,8 @@ void InstrumentPresenter::notifySettingsChanged() {
void InstrumentPresenter::notifyRestoreDefaultsRequested() { void InstrumentPresenter::notifyRestoreDefaultsRequested() {
// Trigger a reload of the instrument to get up-to-date settings. // 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(); m_mainPresenter->notifyUpdateInstrumentRequested();
restoreDefaults();
} }
Instrument const &InstrumentPresenter::instrument() const { return m_model; } Instrument const &InstrumentPresenter::instrument() const { return m_model; }
......
...@@ -125,9 +125,16 @@ void MainWindowPresenter::notifyAnyBatchReductionPaused() { ...@@ -125,9 +125,16 @@ void MainWindowPresenter::notifyAnyBatchReductionPaused() {
} }
void MainWindowPresenter::notifyChangeInstrumentRequested( void MainWindowPresenter::notifyChangeInstrumentRequested(
std::string const &instrumentName) { std::string const &newInstrumentName) {
// Re-load instrument with the new name auto const hasChanged = (newInstrumentName != instrumentName());
updateInstrument(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() { void MainWindowPresenter::notifyUpdateInstrumentRequested() {
...@@ -245,14 +252,6 @@ void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { ...@@ -245,14 +252,6 @@ void MainWindowPresenter::updateInstrument(const std::string &instrumentName) {
loadAlg->execute(); loadAlg->execute();
MatrixWorkspace_sptr instWorkspace = loadAlg->getProperty("OutputWorkspace"); MatrixWorkspace_sptr instWorkspace = loadAlg->getProperty("OutputWorkspace");
m_instrument = instWorkspace->getInstrument(); 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( void MainWindowPresenter::setDefaultInstrument(
...@@ -272,6 +271,16 @@ void MainWindowPresenter::setDefaultInstrument( ...@@ -272,6 +271,16 @@ void MainWindowPresenter::setDefaultInstrument(
g_log.notice() << "Instrument changed to " << requiredInstrument; 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 ISISReflectometry
} // namespace CustomInterfaces } // namespace CustomInterfaces
} // namespace MantidQt } // namespace MantidQt
...@@ -88,9 +88,9 @@ private: ...@@ -88,9 +88,9 @@ private:
void addNewBatch(IBatchView *batchView); void addNewBatch(IBatchView *batchView);
void initNewBatch(IBatchPresenter *batchPresenter, void initNewBatch(IBatchPresenter *batchPresenter,
std::string const &instrument); std::string const &instrument);
void changeInstrument(std::string const &instrumentName);
void updateInstrument(const std::string &instrumentName); void updateInstrument(const std::string &instrumentName);
void setDefaultInstrument(const std::string &newInstrument); void setDefaultInstrument(const std::string &newInstrument);
void onInstrumentChanged();
void disableSaveAndLoadBatch(); void disableSaveAndLoadBatch();
void enableSaveAndLoadBatch(); void enableSaveAndLoadBatch();
...@@ -101,4 +101,4 @@ private: ...@@ -101,4 +101,4 @@ private:
}; };
} // namespace ISISReflectometry } // namespace ISISReflectometry
} // namespace CustomInterfaces } // namespace CustomInterfaces
} // namespace MantidQt } // namespace MantidQt
\ No newline at end of file
...@@ -252,6 +252,7 @@ public: ...@@ -252,6 +252,7 @@ public:
void testChangeInstrumentRequestedUpdatesInstrumentInChildPresenters() { void testChangeInstrumentRequestedUpdatesInstrumentInChildPresenters() {
auto presenter = makePresenter(); auto presenter = makePresenter();
setupInstrument(presenter, "INTER");
auto const instrument = std::string("POLREF"); auto const instrument = std::string("POLREF");
EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument))
.Times(1); .Times(1);
...@@ -261,13 +262,24 @@ public: ...@@ -261,13 +262,24 @@ public:
verifyAndClear(); verifyAndClear();
} }
void testUpdateInstrumentUpdatesInstrumentInChildPresenters() { void testChangeInstrumentRequestedDoesNotUpdateInstrumentIfNotChanged() {
auto presenter = makePresenter(); auto presenter = makePresenter();
auto const instrument = setupInstrument(presenter, "POLREF"); auto const instrument = setupInstrument(presenter, "POLREF");
EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument))
.Times(1); .Times(0);
EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)) 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(); presenter.notifyUpdateInstrumentRequested();
verifyAndClear(); verifyAndClear();
} }
...@@ -316,32 +328,16 @@ public: ...@@ -316,32 +328,16 @@ public:
void testSaveBatch() { void testSaveBatch() {
auto presenter = makePresenter(); auto presenter = makePresenter();
auto const filename = std::string("test.json");
auto const map = QMap<QString, QVariant>();
auto const batchIndex = 1; auto const batchIndex = 1;
EXPECT_CALL(m_messageHandler, askUserForSaveFileName("JSON (*.json)")) expectBatchIsSavedToFile(batchIndex);
.Times(1)
.WillOnce(Return(filename));
EXPECT_CALL(*m_encoder, encodeBatch(&m_view, batchIndex, false))
.Times(1)
.WillOnce(Return(map));
EXPECT_CALL(m_fileHandler, saveJSONToFile(filename, map)).Times(1);
presenter.notifySaveBatchRequested(batchIndex); presenter.notifySaveBatchRequested(batchIndex);
verifyAndClear(); verifyAndClear();
} }
void testLoadBatch() { void testLoadBatch() {
auto presenter = makePresenter(); auto presenter = makePresenter();
auto const filename = std::string("test.json");
auto const map = QMap<QString, QVariant>();
auto const batchIndex = 1; auto const batchIndex = 1;
EXPECT_CALL(m_messageHandler, askUserForLoadFileName("JSON (*.json)")) expectBatchIsLoadedFromFile(batchIndex);
.Times(1)
.WillOnce(Return(filename));
EXPECT_CALL(m_fileHandler, loadJSONFromFile(filename))
.Times(1)
.WillOnce(Return(map));
EXPECT_CALL(*m_decoder, decodeBatch(&m_view, batchIndex, map)).Times(1);
presenter.notifyLoadBatchRequested(batchIndex); presenter.notifyLoadBatchRequested(batchIndex);
verifyAndClear(); verifyAndClear();
} }
...@@ -489,6 +485,30 @@ private: ...@@ -489,6 +485,30 @@ private:
EXPECT_CALL(*m_slitCalculator, processInstrumentHasBeenChanged()).Times(1); EXPECT_CALL(*m_slitCalculator, processInstrumentHasBeenChanged()).Times(1);
} }
void expectBatchIsSavedToFile(int batchIndex) {
auto const filename = std::string("test.json");
auto const map = QMap<QString, QVariant>();
EXPECT_CALL(m_messageHandler, askUserForSaveFileName("JSON (*.json)"))
.Times(1)
.WillOnce(Return(filename));
EXPECT_CALL(*m_encoder, encodeBatch(&m_view, batchIndex, false))
.Times(1)
.WillOnce(Return(map));
EXPECT_CALL(m_fileHandler, saveJSONToFile(filename, map)).Times(1);
}
void expectBatchIsLoadedFromFile(int batchIndex) {
auto const filename = std::string("test.json");
auto const map = QMap<QString, QVariant>();
EXPECT_CALL(m_messageHandler, askUserForLoadFileName("JSON (*.json)"))
.Times(1)
.WillOnce(Return(filename));
EXPECT_CALL(m_fileHandler, loadJSONFromFile(filename))
.Times(1)
.WillOnce(Return(map));
EXPECT_CALL(*m_decoder, decodeBatch(&m_view, batchIndex, map)).Times(1);
}
void assertFirstBatchWasRemovedFromModel( void assertFirstBatchWasRemovedFromModel(
MainWindowPresenterFriend const &presenter) { MainWindowPresenterFriend const &presenter) {
TS_ASSERT_EQUALS(presenter.m_batchPresenters.size(), 1); TS_ASSERT_EQUALS(presenter.m_batchPresenters.size(), 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment