diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp index 38fc3987f46c53f9d8e41ceeffe846b41ea65601..13fadc8e8cc6a40726b15bc6e6d0469002f14f36 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentPresenter.cpp @@ -63,8 +63,13 @@ PolarizationCorrections ExperimentPresenter::polarizationCorrectionsFromView() { } RangeInLambda ExperimentPresenter::transmissionRunRangeFromView() { - return RangeInLambda(m_view->getTransmissionStartOverlap(), - m_view->getTransmissionEndOverlap()); + auto const range = RangeInLambda(m_view->getTransmissionStartOverlap(), + m_view->getTransmissionEndOverlap()); + if (range.isValid()) + m_view->showTransmissionRangeValid(); + else + m_view->showTransmissionRangeInvalid(); + return range; } ExperimentValidationResult ExperimentPresenter::validateExperimentFromView() { diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.cpp b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.cpp index a18f545e79936058d7978fcd2c8525b444674bea..a5a2de8dd84289910ca272274827adc5d7976426 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.cpp @@ -7,6 +7,24 @@ namespace MantidQt { namespace CustomInterfaces { +namespace { +// TODO: these don't seem to work for spin boxes - is there another way to set +// the backround colour?gg +void showAsInvalid(QDoubleSpinBox &spinBox) { + auto palette = spinBox.palette(); + palette.setColor(spinBox.backgroundRole(), QColor("#ffb8ad")); + spinBox.setAutoFillBackground(true); + spinBox.setPalette(palette); +} + +void showAsValid(QDoubleSpinBox &spinBox) { + auto palette = spinBox.palette(); + palette.setColor(spinBox.backgroundRole(), Qt::transparent); + spinBox.setAutoFillBackground(false); + spinBox.setPalette(palette); +} +} // namespace + /** Constructor * @param algorithmForTooltips :: [input] An algorithm that will be * used to find tooltips for the input properties @@ -492,6 +510,16 @@ double ExperimentView::getTransmissionEndOverlap() const { return m_ui.endOverlapEdit->value(); } +void ExperimentView::showTransmissionRangeInvalid() { + showAsInvalid(*m_ui.startOverlapEdit); + showAsInvalid(*m_ui.endOverlapEdit); +} + +void ExperimentView::showTransmissionRangeValid() { + showAsValid(*m_ui.startOverlapEdit); + showAsValid(*m_ui.endOverlapEdit); +} + void ExperimentView::setTransmissionEndOverlap(double end) { m_ui.endOverlapEdit->setValue(end); } diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.h index a58bb44a29e28b0971a4066605c72d3647b0d646..2ac78c3264afb5be4878da258ce72d27559a6bc2 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/ExperimentView.h @@ -67,6 +67,8 @@ public: void setTransmissionStartOverlap(double start) override; double getTransmissionEndOverlap() const override; void setTransmissionEndOverlap(double end) override; + void showTransmissionRangeInvalid() override; + void showTransmissionRangeValid() override; std::string getPolarisationCorrectionType() const override; void setPolarisationCorrectionType(std::string const &type) override; diff --git a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/IExperimentView.h b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/IExperimentView.h index fb1bdc5198064822b605302a908ab10b7cfae941..02b55bc702030f65c885fe5049dbfa9dc62193b2 100644 --- a/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/IExperimentView.h +++ b/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/IExperimentView.h @@ -84,6 +84,8 @@ public: virtual void setTransmissionStartOverlap(double start) = 0; virtual double getTransmissionEndOverlap() const = 0; virtual void setTransmissionEndOverlap(double end) = 0; + virtual void showTransmissionRangeInvalid() = 0; + virtual void showTransmissionRangeValid() = 0; virtual std::string getPolarisationCorrectionType() const = 0; virtual void setPolarisationCorrectionType(std::string const &type) = 0; diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.cpp b/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.cpp index 7fb25e2434567cd10433a33437a8e01d8fe5a3e8..8617f5cb3df7196355a87e55ca6a78361a895380 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.cpp @@ -25,7 +25,11 @@ PolarizationCorrections const &Experiment::polarizationCorrections() const { return m_polarizationCorrections; } -RangeInLambda const &Experiment::transissionRunRange() const { +bool Experiment::isValid() const { + return m_transmissionRunRange.isValid(); +} + +RangeInLambda const &Experiment::transmissionRunRange() const { return m_transmissionRunRange; } diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.h b/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.h index 2cf2d9661bf051961aa1911ce11e81f900f69df9..16b969ff2b9d90c32b217a11ee6d9a29544c2c4b 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.h +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.h @@ -45,11 +45,12 @@ public: std::map<std::string, std::string> stitchParameters, std::vector<PerThetaDefaults> perThetaDefaults); + bool isValid() const; AnalysisMode analysisMode() const; ReductionType reductionType() const; SummationType summationType() const; PolarizationCorrections const &polarizationCorrections() const; - RangeInLambda const &transissionRunRange() const; + RangeInLambda const &transmissionRunRange() const; std::map<std::string, std::string> stitchParameters() const; std::vector<PerThetaDefaults> const &perThetaDefaults() const; diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp index 85bc102222387610afac6cc7fc1a30db87d096cb..b2022c72a8615c198431a4c743344000ebf7b320 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.cpp @@ -13,5 +13,16 @@ double PolarizationCorrections::cAlpha() const { return CAlpha; } double PolarizationCorrections::cAp() const { return CAp; } double PolarizationCorrections::cPp() const { return CPp; } + +bool operator!=(PolarizationCorrections const &lhs, + PolarizationCorrections const &rhs) { + return !(lhs == rhs); +} + +bool operator==(PolarizationCorrections const &lhs, + PolarizationCorrections const &rhs) { + return lhs.cRho() == rhs.cRho() && lhs.cAlpha() == rhs.cAlpha() && + lhs.cAp() == rhs.cAp() && lhs.cPp() == rhs.cPp(); +} } // namespace CustomInterfaces } // namespace MantidQt diff --git a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h index 63249b94bbf86565139a630be9c799d0b15a60c7..25fe794e048baa6a38980eb22c1c3e6fa4bc79c6 100644 --- a/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h +++ b/qt/scientific_interfaces/ISISReflectometry/Reduction/PolarizationCorrections.h @@ -19,6 +19,13 @@ private: double CAp; double CPp; }; + +MANTIDQT_ISISREFLECTOMETRY_DLL bool +operator==(PolarizationCorrections const &lhs, + PolarizationCorrections const &rhs); +MANTIDQT_ISISREFLECTOMETRY_DLL bool +operator!=(PolarizationCorrections const &lhs, + PolarizationCorrections const &rhs); } // namespace CustomInterfaces } // namespace MantidQt #endif // MANTID_CUSTOMINTERFACES_POLARIZATIONCORRECTIONS_H_ diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h index 2e0a4f75f0e94eafc1693951792a46cd144bc585..94387c36570e8a5ff0be3bf03d17103e6a820b6f 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/ExperimentPresenterTest.h @@ -46,10 +46,24 @@ public: verifyAndClear(); } + void testModelUpdatedWhenAnalysisModeChanged() { + auto presenter = makePresenter(); + + expectViewReturnsSumInLambdaDefaults(); + EXPECT_CALL(m_view, getAnalysisMode()) + .WillOnce(Return(std::string("MultiDetectorAnalysis"))); + presenter.notifySettingsChanged(); + + TS_ASSERT_EQUALS(presenter.experiment().analysisMode(), + AnalysisMode::MultiDetector); + verifyAndClear(); + } + void testModelUpdatedWhenSummationTypeChanged() { auto presenter = makePresenter(); - expectViewReturnsDefaultValuesForSumInQ(); + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInQDefaults(); presenter.notifySummationTypeChanged(); TS_ASSERT_EQUALS(presenter.experiment().summationType(), @@ -60,7 +74,8 @@ public: void testReductionTypeDisabledWhenChangeToSumInLambda() { auto presenter = makePresenter(); - expectViewReturnsDefaultValues(); + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInLambdaDefaults(); EXPECT_CALL(m_view, disableReductionType()).Times(1); presenter.notifySummationTypeChanged(); @@ -70,13 +85,74 @@ public: void testReductionTypeEnbledWhenChangeToSumInQ() { auto presenter = makePresenter(); - expectViewReturnsDefaultValuesForSumInQ(); + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInQDefaults(); EXPECT_CALL(m_view, enableReductionType()).Times(1); presenter.notifySummationTypeChanged(); verifyAndClear(); } + void testSetPolarizationCorrections() { + auto presenter = makePresenter(); + PolarizationCorrections polCorr(1.2, 1.3, 2.4, 2.5); + + expectViewReturnsDefaultValues(); + EXPECT_CALL(m_view, getCRho()).WillOnce(Return(polCorr.cRho())); + EXPECT_CALL(m_view, getCAlpha()).WillOnce(Return(polCorr.cAlpha())); + EXPECT_CALL(m_view, getCAp()).WillOnce(Return(polCorr.cAp())); + EXPECT_CALL(m_view, getCPp()).WillOnce(Return(polCorr.cPp())); + presenter.notifySettingsChanged(); + + TS_ASSERT_EQUALS(presenter.experiment().polarizationCorrections(), polCorr); + verifyAndClear(); + } + + void testSetTransmissionRunRange() { + auto presenter = makePresenter(); + RangeInLambda range(7.2, 10); + + expectViewReturnsDefaultValues(); + EXPECT_CALL(m_view, getTransmissionStartOverlap()).WillOnce(Return(range.min())); + EXPECT_CALL(m_view, getTransmissionEndOverlap()).WillOnce(Return(range.max())); + EXPECT_CALL(m_view, showTransmissionRangeValid()).Times(1); + presenter.notifySettingsChanged(); + + TS_ASSERT_EQUALS(presenter.experiment().transmissionRunRange(), range); + verifyAndClear(); + } + + void testSetTransmissionRunRangeInvalid() { + auto presenter = makePresenter(); + RangeInLambda range(10.2, 7.1); + + expectViewReturnsDefaultValues(); + EXPECT_CALL(m_view, getTransmissionStartOverlap()).WillOnce(Return(range.min())); + EXPECT_CALL(m_view, getTransmissionEndOverlap()).WillOnce(Return(range.max())); + EXPECT_CALL(m_view, showTransmissionRangeInvalid()).Times(1); + presenter.notifySettingsChanged(); + + TS_ASSERT_EQUALS(presenter.experiment().transmissionRunRange(), range); + verifyAndClear(); + } + + void testSetStitchOptions() { + auto presenter = makePresenter(); + auto const optionsString = "Params=0.02"; + std::map<std::string, std::string> optionsMap = {{"Params", "0.02"}}; + + expectViewReturnsDefaultValues(); + EXPECT_CALL(m_view, getStitchOptions()).WillOnce(Return(optionsString)); + presenter.notifySettingsChanged(); + + TS_ASSERT_EQUALS(presenter.experiment().stitchParameters(), optionsMap); + verifyAndClear(); + } + + void testSetStitchOptionsInvalid() { + // TODO + } + void testNewPerAngleDefaultsRequested() { auto presenter = makePresenter(); @@ -123,6 +199,43 @@ public: verifyAndClear(); } + // TODO + void testSetMultipleUniqueAngles() {} + + void testSetMultipoleNonUniqueAngles() {} + + void testSetAngleAndWildcardRow() {} + + void testSetSingleWildcardRow() {} + + void testSetMultipleWildcardRows() {} + + void testSetFirstTransmissionRun() {} + + void testSetSecondTransmissionRun() {} + + void testSetBothTransmissionRuns() {} + + void testSetQMin() {} + + void testSetQMinInvalid() {} + + void testSetQMax() {} + + void testSetQMaxInvalid() {} + + void testSetQStep() {} + + void testSetQStepInvalid() {} + + void testSetScale() {} + + void testSetScaleInvalid() {} + + void testSetProcessingInstructions() {} + + void testSetProcessingInstructionsInvalid() {} + private: NiceMock<MockExperimentView> m_view; @@ -139,24 +252,30 @@ private: TS_ASSERT(Mock::VerifyAndClearExpectations(&m_view)); } - void expectViewReturnsDefaultValues() { + void expectViewReturnsDefaultAnalysisMode() { EXPECT_CALL(m_view, getAnalysisMode()) .WillOnce(Return(std::string("PointDetectorAnalysis"))); + } + + void expectViewReturnsSumInLambdaDefaults() { EXPECT_CALL(m_view, getSummationType()) .WillOnce(Return(std::string("SumInLambda"))); EXPECT_CALL(m_view, getReductionType()) .WillOnce(Return(std::string("Normal"))); } - void expectViewReturnsDefaultValuesForSumInQ() { - EXPECT_CALL(m_view, getAnalysisMode()) - .WillOnce(Return(std::string("PointDetectorAnalysis"))); + void expectViewReturnsSumInQDefaults() { EXPECT_CALL(m_view, getSummationType()) .WillOnce(Return(std::string("SumInQ"))); EXPECT_CALL(m_view, getReductionType()) .WillOnce(Return(std::string("DivergentBeam"))); } + void expectViewReturnsDefaultValues() { + expectViewReturnsDefaultAnalysisMode(); + expectViewReturnsSumInLambdaDefaults(); + } + // These functions create various rows in the per-theta defaults tables, // either as an input array of strings or an output model OptionsRow optionsWithAngleAndOneTrans() { return {"0.5", "13463"}; } diff --git a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/MockExperimentView.h b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/MockExperimentView.h index 61b5bb0cdb828ebabe58389436f210595f68033f..f000bc0350ecedb55bc23dd6644954effab5d31b 100644 --- a/qt/scientific_interfaces/test/ISISReflectometry/Experiment/MockExperimentView.h +++ b/qt/scientific_interfaces/test/ISISReflectometry/Experiment/MockExperimentView.h @@ -33,6 +33,8 @@ public: MOCK_METHOD1(setTransmissionStartOverlap, void(double)); MOCK_CONST_METHOD0(getTransmissionEndOverlap, double()); MOCK_METHOD1(setTransmissionEndOverlap, void(double)); + MOCK_METHOD0(showTransmissionRangeValid, void(void)); + MOCK_METHOD0(showTransmissionRangeInvalid, void(void)); MOCK_CONST_METHOD0(getPolarisationCorrectionType, std::string()); MOCK_METHOD1(setPolarisationCorrectionType, void(std::string const &)); MOCK_CONST_METHOD0(getCRho, double());