diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp index 63d76498a5e3b486bfc560c669a358bfa6bc3a0a..1d54229f2f79b293865ba84b3f03cd2854332471 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp @@ -46,9 +46,8 @@ MainWindowPresenter::MainWindowPresenter( std::unique_ptr<ISlitCalculator> slitCalculator, std::unique_ptr<IBatchPresenterFactory> batchPresenterFactory) : m_view(view), m_messageHandler(messageHandler), - m_slitCalculator(std::move(slitCalculator)), - m_batchPresenterFactory(std::move(batchPresenterFactory)), - m_instrument() { + m_instrument(), m_slitCalculator(std::move(slitCalculator)), + m_batchPresenterFactory(std::move(batchPresenterFactory)) { view->subscribe(this); for (auto *batchView : m_view->batches()) addNewBatch(batchView); @@ -81,9 +80,15 @@ void MainWindowPresenter::notifyCloseBatchRequested(int batchIndex) { } } -void MainWindowPresenter::notifyShowOptionsRequested() {} +void MainWindowPresenter::notifyShowOptionsRequested() { + // TODO Show the options dialog when it is implemented +} -void MainWindowPresenter::notifyShowSlitCalculatorRequested() {} +void MainWindowPresenter::notifyShowSlitCalculatorRequested() { + m_slitCalculator->setCurrentInstrumentName(instrumentName()); + m_slitCalculator->processInstrumentHasBeenChanged(); + m_slitCalculator->show(); +} void MainWindowPresenter::notifyAnyBatchAutoreductionResumed() { for (const auto &batchPresenter : m_batchPresenters) { @@ -232,8 +237,13 @@ void MainWindowPresenter::updateInstrument(const std::string &instrumentName) { 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(); } } // namespace ISISReflectometry } // namespace CustomInterfaces diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h index 9c7ea3e110eb9fa8657fe07da6fe438f814431a0..02d7e205ac3f95f003fd3f524966e89ab90fda3b 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h @@ -71,13 +71,12 @@ protected: IMainWindowView *m_view; IMessageHandler *m_messageHandler; std::vector<std::unique_ptr<IBatchPresenter>> m_batchPresenters; + Mantid::Geometry::Instrument_const_sptr m_instrument; private: std::unique_ptr<MantidWidgets::ISlitCalculator> m_slitCalculator; std::unique_ptr<IBatchPresenterFactory> m_batchPresenterFactory; - Mantid::Geometry::Instrument_const_sptr m_instrument; - void showHelp(); void addNewBatch(IBatchView *batchView); void initNewBatch(IBatchPresenter *batchPresenter, diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp index 581070e0ebedb46ad75cf559153b5d40dce80dd0..71794d9eeb242616bf9b8ffb1563fedee8b9f1a5 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp @@ -16,6 +16,9 @@ #include <QToolButton> namespace MantidQt { + +using MantidWidgets::SlitCalculator; + namespace CustomInterfaces { namespace ISISReflectometry { diff --git a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h index 9850c08b197947dadd7575607299ee85253a4852..b31333d7751bc5ed3707611ce43ad7e653310851 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h @@ -12,6 +12,7 @@ #include "../Batch/MockBatchView.h" #include "../ReflMockObjects.h" #include "MantidAPI/FrameworkManager.h" +#include "MantidGeometry/Instrument_fwd.h" #include "MantidQtWidgets/Common/MockSlitCalculator.h" #include "MockMainWindowView.h" @@ -154,14 +155,25 @@ public: verifyAndClear(); } - void testShowOptionsRequested() { + void testShowOptionsOpensDialog() { auto presenter = makePresenter(); + // TODO Add test when options dialog is impelemented + //EXPECT_CALL(*m_optionsDialog, show()).Times(1); presenter.notifyShowOptionsRequested(); verifyAndClear(); } - void testShowSlitCalculatorRequested() { + void testShowSlitCalculatorSetsInstrument() { auto presenter = makePresenter(); + auto const instrument = setupInstrument(presenter, "TEST_INSTRUMENT"); + expectSlitCalculatorInstrumentUpdated(); + presenter.notifyShowSlitCalculatorRequested(); + verifyAndClear(); + } + + void testShowSlitCalculatorOpensDialog() { + auto presenter = makePresenter(); + EXPECT_CALL(*m_slitCalculator, show()).Times(1); presenter.notifyShowSlitCalculatorRequested(); verifyAndClear(); } @@ -237,11 +249,9 @@ public: verifyAndClear(); } - void testUpdateInstrumentRequestedUpdatesInstrumentInChildPresenters() { + void testUpdateInstrumentUpdatesInstrumentInChildPresenters() { auto presenter = makePresenter(); - // must set the instrument to something valid first - presenter.notifyChangeInstrumentRequested("POLREF"); - auto const instrument = presenter.instrumentName(); + auto const instrument = setupInstrument(presenter, "POLREF"); EXPECT_CALL(*m_batchPresenters[0], notifyInstrumentChanged(instrument)) .Times(1); EXPECT_CALL(*m_batchPresenters[1], notifyInstrumentChanged(instrument)) @@ -250,17 +260,23 @@ public: verifyAndClear(); } - void testUpdateInstrumentRequestedDoesNotChangeInstrumentName() { + void testUpdateInstrumentUpdatesInstrumentInSlitCalculator() { + auto presenter = makePresenter(); + auto const instrument = setupInstrument(presenter, "POLREF"); + expectSlitCalculatorInstrumentUpdated(); + presenter.notifyUpdateInstrumentRequested(); + verifyAndClear(); + } + + void testUpdateInstrumentDoesNotChangeInstrumentName() { auto presenter = makePresenter(); - // must set the instrument to something valid first - presenter.notifyChangeInstrumentRequested("POLREF"); - auto const instrument = presenter.instrumentName(); + auto const instrument = setupInstrument(presenter, "POLREF"); presenter.notifyUpdateInstrumentRequested(); TS_ASSERT_EQUALS(presenter.instrumentName(), instrument); verifyAndClear(); } - void testUpdateInstrumentRequestedThrowsIfInstrumentNotSet() { + void testUpdateInstrumentThrowsIfInstrumentNotSet() { auto presenter = makePresenter(); TS_ASSERT_THROWS_ANYTHING(presenter.notifyUpdateInstrumentRequested()); verifyAndClear(); @@ -315,6 +331,13 @@ private: m_batchPresenters.clear(); } + std::string setupInstrument(MainWindowPresenterFriend &presenter, + std::string const& instrumentName) { + presenter.m_instrument = + boost::make_shared<Mantid::Geometry::Instrument>(instrumentName); + return presenter.instrumentName(); + } + void expectBatchAdded(MockBatchPresenter *batchPresenter) { EXPECT_CALL(*batchPresenter, acceptMainPresenter(_)).Times(1); EXPECT_CALL(*batchPresenter, initInstrumentList()).Times(1); @@ -381,6 +404,11 @@ private: .Times(1); } + void expectSlitCalculatorInstrumentUpdated() { + EXPECT_CALL(*m_slitCalculator, setCurrentInstrumentName(instrument)).Times(1); + EXPECT_CALL(*m_slitCalculator, processInstrumentHasBeenChanged()).Times(1); + } + void assertFirstBatchWasRemovedFromModel( MainWindowPresenterFriend const &presenter) { TS_ASSERT_EQUALS(presenter.m_batchPresenters.size(), 1); diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h b/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h index f6a8f3cee1d25d8e064fe7ccda7831b1c5f215a6..a56b6caf67f7a26408b62b18b6b5fa12333e9b15 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h @@ -17,6 +17,7 @@ public: virtual ~ISlitCalculator() = default; virtual void setCurrentInstrumentName(std::string instrumentName) = 0; virtual void processInstrumentHasBeenChanged() = 0; + virtual void show() = 0; }; } // namespace MantidWidgets } // namespace MantidQt diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/MockSlitCalculator.h b/qt/widgets/common/inc/MantidQtWidgets/Common/MockSlitCalculator.h index 3947c099757fe5652de4766a5caabe3ee2d5cce8..2a0dc11605066258fcb8748fc9f1eeea5fb42f16 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/MockSlitCalculator.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/MockSlitCalculator.h @@ -16,6 +16,7 @@ public: GNU_DIAG_OFF_SUGGEST_OVERRIDE MOCK_METHOD1(setCurrentInstrumentName, void(std::string)); MOCK_METHOD0(processInstrumentHasBeenChanged, void()); + MOCK_METHOD0(show, void()); GNU_DIAG_ON_SUGGEST_OVERRIDE }; diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/SlitCalculator.h b/qt/widgets/common/inc/MantidQtWidgets/Common/SlitCalculator.h index f8af6cdcf07ac57bcf834d948921d6adf069fd01..7f6d5243903ed2a3e0807dc6059e3101e747d65d 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/SlitCalculator.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/SlitCalculator.h @@ -29,6 +29,7 @@ public: ~SlitCalculator() override; void setCurrentInstrumentName(std::string instrumentName) override; void processInstrumentHasBeenChanged() override; + void show() override; protected: Ui::SlitCalculator ui; diff --git a/qt/widgets/common/src/SlitCalculator.cpp b/qt/widgets/common/src/SlitCalculator.cpp index 57a0b4e2382ebffcae3232c9b329e56018d916d4..c863c64cf3022f8b66f681458163799eb385ef81 100644 --- a/qt/widgets/common/src/SlitCalculator.cpp +++ b/qt/widgets/common/src/SlitCalculator.cpp @@ -61,6 +61,8 @@ void SlitCalculator::setInstrument(std::string instrumentName) { setupSlitCalculatorWithInstrumentValues(instrument); } +void SlitCalculator::show() { QDialog::show(); } + void SlitCalculator::setupSlitCalculatorWithInstrumentValues( Mantid::Geometry::Instrument_const_sptr instrument) { // fetch the components that we need for values from IDF