From 3aa38642865c6f05ae3b3b96c1fa5ea50e923cea Mon Sep 17 00:00:00 2001 From: Gemma Guest <gemma.guest@stfc.ac.uk> Date: Fri, 16 Aug 2019 17:59:50 +0100 Subject: [PATCH] Create the slit calculator and inject into presenter Re #26533 --- .../GUI/MainWindow/MainWindowPresenter.cpp | 4 ++++ .../GUI/MainWindow/MainWindowPresenter.h | 8 +++++++- .../GUI/MainWindow/QtMainWindowView.cpp | 5 ++++- .../MainWindow/MainWindowPresenterTest.h | 11 ++++++++--- .../inc/MantidQtWidgets/Common/ISlitCalculator.h | 1 + 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp index f705a96d57f..63d76498a5e 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.cpp @@ -16,6 +16,7 @@ #include "MantidKernel/ConfigService.h" #include "MantidQtWidgets/Common/HelpWindow.h" #include "MantidQtWidgets/Common/QtJSONUtils.h" +#include "MantidQtWidgets/Common/ISlitCalculator.h" #include "Reduction/Batch.h" #include <QFileDialog> @@ -26,6 +27,7 @@ namespace ISISReflectometry { using Mantid::API::AlgorithmManager; using Mantid::API::MatrixWorkspace_sptr; +using MantidWidgets::ISlitCalculator; // unnamed namespace namespace { @@ -41,8 +43,10 @@ Mantid::Kernel::Logger g_log("Reflectometry GUI"); */ MainWindowPresenter::MainWindowPresenter( IMainWindowView *view, IMessageHandler *messageHandler, + 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() { view->subscribe(this); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h index f7703674a97..9c7ea3e110e 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/MainWindowPresenter.h @@ -15,6 +15,9 @@ #include <memory> namespace MantidQt { +namespace MantidWidgets { +class ISlitCalculator; +} namespace CustomInterfaces { namespace ISISReflectometry { @@ -34,6 +37,7 @@ public: /// Constructor MainWindowPresenter( IMainWindowView *view, IMessageHandler *messageHandler, + std::unique_ptr<MantidWidgets::ISlitCalculator> slitCalculator, std::unique_ptr<IBatchPresenterFactory> batchPresenterFactory); ~MainWindowPresenter(); MainWindowPresenter(MainWindowPresenter const &) = delete; @@ -67,9 +71,11 @@ protected: IMainWindowView *m_view; IMessageHandler *m_messageHandler; std::vector<std::unique_ptr<IBatchPresenter>> m_batchPresenters; - std::unique_ptr<IBatchPresenterFactory> m_batchPresenterFactory; private: + std::unique_ptr<MantidWidgets::ISlitCalculator> m_slitCalculator; + std::unique_ptr<IBatchPresenterFactory> m_batchPresenterFactory; + Mantid::Geometry::Instrument_const_sptr m_instrument; void showHelp(); diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp index 59be273fcb1..581070e0ebe 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/MainWindow/QtMainWindowView.cpp @@ -11,6 +11,7 @@ #include "GUI/Common/Decoder.h" #include "GUI/Common/Encoder.h" #include "GUI/Common/Plotter.h" +#include "MantidQtWidgets/Common/SlitCalculator.h" #include <QMessageBox> #include <QToolButton> @@ -95,8 +96,10 @@ void QtMainWindowView::initLayout() { std::move(makeSaveSettingsPresenter)); // Create the presenter + auto slitCalculator = std::make_unique<SlitCalculator>(this); m_presenter = std::make_unique<MainWindowPresenter>( - this, messageHandler, std::move(makeBatchPresenter)); + this, messageHandler, std::move(slitCalculator), + std::move(makeBatchPresenter)); m_notifyee->notifyNewBatchRequested(); m_notifyee->notifyNewBatchRequested(); diff --git a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h index 161e5fc90a9..9850c08b197 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/MainWindow/MainWindowPresenterTest.h @@ -23,12 +23,13 @@ using namespace MantidQt::CustomInterfaces::ISISReflectometry; using namespace MantidQt::CustomInterfaces::ISISReflectometry:: ModelCreationHelper; using MantidQt::API::IConfiguredAlgorithm_sptr; +using MantidQt::MantidWidgets::ISlitCalculator; +using testing::_; using testing::AtLeast; using testing::Mock; using testing::NiceMock; using testing::Return; using testing::ReturnRef; -using testing::_; class MainWindowPresenterTest : public CxxTest::TestSuite { public: @@ -271,6 +272,7 @@ private: std::vector<IBatchView *> m_batchViews; std::vector<NiceMock<MockBatchPresenter> *> m_batchPresenters; NiceMock<MockBatchPresenterFactory> *m_makeBatchPresenter; + NiceMock<MockSlitCalculator> *m_slitCalculator; class MainWindowPresenterFriend : public MainWindowPresenter { friend class MainWindowPresenterTest; @@ -278,13 +280,15 @@ private: public: MainWindowPresenterFriend( IMainWindowView *view, IMessageHandler *messageHandler, + std::unique_ptr<ISlitCalculator> slitCalculator, std::unique_ptr<IBatchPresenterFactory> makeBatchPresenter) - : MainWindowPresenter(view, messageHandler, + : MainWindowPresenter(view, messageHandler, std::move(slitCalculator), std::move(makeBatchPresenter)) {} }; MainWindowPresenterFriend makePresenter() { - // Make the batch presenter factory + auto slitCalculator = std::make_unique<NiceMock<MockSlitCalculator>>(); + m_slitCalculator = slitCalculator.get(); auto makeBatchPresenter = std::make_unique<NiceMock<MockBatchPresenterFactory>>(); m_makeBatchPresenter = makeBatchPresenter.get(); @@ -298,6 +302,7 @@ private: } // Make the presenter auto presenter = MainWindowPresenterFriend(&m_view, &m_messageHandler, + std::move(slitCalculator), std::move(makeBatchPresenter)); return presenter; } diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h b/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h index d3d6bdcb981..f6a8f3cee1d 100644 --- a/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h +++ b/qt/widgets/common/inc/MantidQtWidgets/Common/ISlitCalculator.h @@ -14,6 +14,7 @@ namespace MantidQt { namespace MantidWidgets { class EXPORT_OPT_MANTIDQT_COMMON ISlitCalculator { public: + virtual ~ISlitCalculator() = default; virtual void setCurrentInstrumentName(std::string instrumentName) = 0; virtual void processInstrumentHasBeenChanged() = 0; }; -- GitLab