diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp index 38e8863befeee4dd9da76df3cbff9d6a408117c6..f9e0bf63d2ff1e8e119616983e36fb76be192cb8 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp @@ -222,9 +222,7 @@ std::string MainWindowPresenter::instrumentName() const { } void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { - Mantid::Kernel::ConfigService::Instance().setString("default.instrument", - instrumentName); - g_log.information() << "Instrument changed to " << instrumentName; + setDefaultInstrument(instrumentName); // Load a workspace for this instrument so we can get the actual instrument auto loadAlg = @@ -246,6 +244,24 @@ void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { m_slitCalculator->setCurrentInstrumentName(instrumentName); m_slitCalculator->processInstrumentHasBeenChanged(); } + +void MainWindowPresenter::setDefaultInstrument( + const std::string &requiredInstrument) { + auto &config = Mantid::Kernel::ConfigService::Instance(); + + auto currentFacility = config.getString("default.facility"); + auto requiredFacility = "ISIS"; + if (currentFacility != requiredFacility) { + config.setString("default.facility", requiredFacility); + g_log.notice() << "Facility changed to " << requiredFacility; + } + + auto currentInstrument = config.getString("default.instrument"); + if (currentInstrument != requiredInstrument) { + config.setString("default.instrument", requiredInstrument); + g_log.notice() << "Instrument changed to " << requiredInstrument; + } +} } // 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 02d7e205ac3f95f003fd3f524966e89ab90fda3b..c1070a554bab67ee74248e476c961568e0879d03 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h @@ -83,6 +83,7 @@ private: std::string const &instrument); void changeInstrument(std::string const &instrumentName); void updateInstrument(const std::string &instrumentName); + void setDefaultInstrument(const std::string &newInstrument); void disableSaveAndLoadBatch(); void enableSaveAndLoadBatch(); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp index bf646821d4fb6a29f16f2aa9159de98a0e8d9034..607f5be498d08d9713e1c41c134e76499ac80376 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/QtRunsTableView.cpp @@ -6,7 +6,6 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "QtRunsTableView.h" #include "Common/IndexOf.h" -#include "MantidKernel/ConfigService.h" #include "MantidKernel/UsageService.h" #include "MantidQtIcons/Icon.h" #include "MantidQtWidgets/Common/AlgorithmHintStrategy.h" diff --git a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h index d0bf7862c3c68e554424f5faf32353284863f42e..a21fd3409a0fd5536d2ec488b420e54fc651898a 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h @@ -13,6 +13,7 @@ #include "../ReflMockObjects.h" #include "MantidAPI/FrameworkManager.h" #include "MantidGeometry/Instrument_fwd.h" +#include "MantidKernel/ConfigService.h" #include "MantidQtWidgets/Common/MockSlitCalculator.h" #include "MockMainWindowView.h" @@ -49,6 +50,18 @@ public: ON_CALL(m_view, batches()).WillByDefault(Return(m_batchViews)); } + void setUp() override { + auto &config = Mantid::Kernel::ConfigService::Instance(); + backup_facility = config.getString("default.facility"); + backup_instrument = config.getString("default.instrument"); + } + + void tearDown() override { + auto &config = Mantid::Kernel::ConfigService::Instance(); + config.setString("default.facility", backup_facility); + config.setString("default.instrument", backup_instrument); + } + void testPresenterSubscribesToView() { EXPECT_CALL(m_view, subscribe(_)).Times(1); auto presenter = makePresenter(); @@ -282,6 +295,26 @@ public: verifyAndClear(); } + void testUpdateInstrumentSetsFacilityInConfig() { + auto presenter = makePresenter(); + auto const instrument = setupInstrument(presenter, "POLREF"); + auto &config = Mantid::Kernel::ConfigService::Instance(); + config.setString("default.facility", "OLD_FACILITY"); + presenter.notifyUpdateInstrumentRequested(); + TS_ASSERT_EQUALS(config.getString("default.facility"), "ISIS"); + verifyAndClear(); + } + + void testUpdateInstrumentSetsInstrumentInConfig() { + auto presenter = makePresenter(); + auto const instrument = setupInstrument(presenter, "POLREF"); + auto &config = Mantid::Kernel::ConfigService::Instance(); + config.setString("default.instrument", "OLD_INSTRUMENT"); + presenter.notifyUpdateInstrumentRequested(); + TS_ASSERT_EQUALS(config.getString("default.instrument"), instrument); + verifyAndClear(); + } + private: NiceMock<MockMainWindowView> m_view; NiceMock<MockMessageHandler> m_messageHandler; @@ -428,6 +461,10 @@ private: TS_ASSERT_EQUALS(presenter.m_batchPresenters[index].get(), m_batchPresenters[index]); } + +private: + std::string backup_facility; + std::string backup_instrument; }; #endif // MANTID_CUSTOMINTERFACES_MAINWINDOWPRESENTERTEST_H_