diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp index eb5706542fd318b5bc8aff7b5bcb945aaf9bad4f..83fc0d9bfd9f7e6e8d44ea7c8d568af31757460b 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp @@ -7,15 +7,15 @@ namespace MantidQt { namespace CustomInterfaces { ExperimentPresenter::ExperimentPresenter(IExperimentView *view, + Experiment experiment, double defaultsThetaTolerance) - : m_view(view), m_model(), m_thetaTolerance(defaultsThetaTolerance) { + : m_view(view), m_model(std::move(experiment)), + m_thetaTolerance(defaultsThetaTolerance) { m_view->subscribe(this); notifySettingsChanged(); } -Experiment const &ExperimentPresenter::experiment() const { - return m_model.get(); -} +Experiment const &ExperimentPresenter::experiment() const { return m_model; } void ExperimentPresenter::notifySettingsChanged() { auto validationResult = updateModelFromView(); @@ -24,7 +24,7 @@ void ExperimentPresenter::notifySettingsChanged() { void ExperimentPresenter::notifySummationTypeChanged() { notifySettingsChanged(); - if (m_model.get().summationType() == SummationType::SumInQ) + if (m_model.summationType() == SummationType::SumInQ) m_view->enableReductionType(); else m_view->disableReductionType(); @@ -99,7 +99,8 @@ ExperimentValidationResult ExperimentPresenter::validateExperimentFromView() { ExperimentValidationResult ExperimentPresenter::updateModelFromView() { auto validationResult = validateExperimentFromView(); - m_model = validationResult.validElseNone(); + if (validationResult.isValid()) + m_model = validationResult.assertValid(); return validationResult; } diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h index a15522fd0c31cd4c8900d52a7cdf8a7b7ad18042..933f5b1cbc85f0042deb2b07c152508c421ad3c2 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.h @@ -67,7 +67,8 @@ class MANTIDQT_ISISREFLECTOMETRY_DLL ExperimentPresenter public IExperimentPresenter { public: // TODO Inject the Experiment model into the constructor. - ExperimentPresenter(IExperimentView *view, double defaultsThetaTolerance); + ExperimentPresenter(IExperimentView *view, Experiment experiment, + double defaultsThetaTolerance); Experiment const &experiment() const; @@ -91,7 +92,7 @@ private: showPerThetaTableErrors(PerThetaDefaultsTableValidationError const &errors); IExperimentView *m_view; - boost::optional<Experiment> m_model; + Experiment m_model; double m_thetaTolerance; }; } // namespace CustomInterfaces diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h index b3d27b198c02468e9208715836f6b0ecc60361aa..5158d84360c9fb13e9fc4165cb125e2f2fa7012c 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenterFactory.h @@ -1,5 +1,6 @@ #ifndef MANTID_ISISREFLECTOMETRY_EXPERIMENTPRESENTERFACTORY_H #define MANTID_ISISREFLECTOMETRY_EXPERIMENTPRESENTERFACTORY_H +#include "../../Reduction/Experiment.h" #include "DllConfig.h" #include "ExperimentPresenter.h" #include "IExperimentPresenter.h" @@ -15,11 +16,27 @@ public: : m_thetaTolerance(thetaTolerance) {} std::unique_ptr<IExperimentPresenter> make(IExperimentView *view) { - return std::make_unique<ExperimentPresenter>(view, m_thetaTolerance); + return std::make_unique<ExperimentPresenter>(view, makeModel(), + m_thetaTolerance); } private: double m_thetaTolerance; + + Experiment makeModel() { + // TODO get defaults from algorithm + auto polarizationCorrections = PolarizationCorrections(0.0, 0.0, 0.0, 0.0); + auto transmissionRunRange = RangeInLambda(0.0, 0.0); + auto stitchParameters = std::map<std::string, std::string>(); + auto perThetaDefaults = std::vector<PerThetaDefaults>( + {PerThetaDefaults(boost::none, std::pair<std::string, std::string>(), + boost::none, boost::none, ReductionOptionsMap())}); + return Experiment(AnalysisMode::PointDetector, ReductionType::Normal, + SummationType::SumInLambda, + std::move(polarizationCorrections), + std::move(transmissionRunRange), + std::move(stitchParameters), std::move(perThetaDefaults)); + } }; } // namespace CustomInterfaces } // namespace MantidQt diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h index 246b8c6d58ff29a2c09e03a91b595305e0825265..98868d449f15ba27f57eb1c7d8b716817f472f00 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h @@ -243,11 +243,26 @@ public: private: NiceMock<MockExperimentView> m_view; + Experiment makeModel() { + auto polarizationCorrections = PolarizationCorrections(0.0, 0.0, 0.0, 0.0); + auto transmissionRunRange = RangeInLambda(0.0, 0.0); + auto stitchParameters = std::map<std::string, std::string>(); + auto perThetaDefaults = std::vector<PerThetaDefaults>( + {PerThetaDefaults(boost::none, std::pair<std::string, std::string>(), + boost::none, boost::none, ReductionOptionsMap())}); + return Experiment(AnalysisMode::PointDetector, ReductionType::Normal, + SummationType::SumInLambda, + std::move(polarizationCorrections), + std::move(transmissionRunRange), + std::move(stitchParameters), std::move(perThetaDefaults)); + } + ExperimentPresenter makePresenter() { // The presenter gets values from the view on construction so the view must // return something sensible expectViewReturnsDefaultValues(); - auto presenter = ExperimentPresenter(&m_view, /*thetaTolerance=*/0.01); + auto presenter = + ExperimentPresenter(&m_view, makeModel(), /*thetaTolerance=*/0.01); verifyAndClear(); return presenter; }