diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysisOptionTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysisOptionTab.h index 8b91011a04a8..469c692da3f0 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysisOptionTab.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/MuonAnalysisOptionTab.h @@ -48,6 +48,9 @@ class MuonAnalysisOptionTab : public QWidget { Q_OBJECT public: + /// Types of the start time + enum StartTimeType { FirstGoodData, TimeZero, Custom }; + /// Constructor MuonAnalysisOptionTab(Ui::MuonAnalysis& uiForm, const QString& settingsGroup); @@ -57,6 +60,15 @@ class MuonAnalysisOptionTab : public QWidget /// Get plot style parameters from widgets QMap parsePlotStyleParams() const; + /// Retrieve selected type of the start time + StartTimeType getStartTimeType(); + + /// Retrieve custom start time value + double getCustomStartTime(); + + /// Retrieve custom finish time value + double getCustomFinishTime(); + signals: /// Update the plot because something has changed. void settingsTabUpdatePlot(); @@ -65,6 +77,9 @@ class MuonAnalysisOptionTab : public QWidget void plotStyleChanged(); private: + /// Logger to use + static Logger& g_log; + /// The Muon Analysis UI file. Ui::MuonAnalysis& m_uiForm; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp index 9a46ec142cf0..461a7338ddec 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp @@ -2400,26 +2400,25 @@ double MuonAnalysis::firstGoodBin() const */ void MuonAnalysis::setXMin(IAlgorithm_sptr alg, const std::string& propName) const { - QString startTimeType = m_uiForm.timeComboBox->currentText(); + auto startTimeType = m_optionTab->getStartTimeType(); double value(0); - if (startTimeType == "Start at First Good Data") + switch(startTimeType) { - value = firstGoodBin(); - } - else if (startTimeType == "Start at Time Zero") - { - value = 0; - } - else if (startTimeType == "Custom Value") - { - value = getValidatedDouble(m_uiForm.timeAxisStartAtInput, "0.0", "custom start time", g_log); - } - else - { - // Just in case misspelled type or added a new one - throw std::runtime_error("Unknown start time type."); + case MuonAnalysisOptionTab::FirstGoodData: + value = firstGoodBin(); break; + + case MuonAnalysisOptionTab::TimeZero: + value = 0; break; + + case MuonAnalysisOptionTab::Custom: + value = m_optionTab->getCustomStartTime(); break; + + default: + // Just in case added a new one + throw std::runtime_error("Unknown start time type"); } + alg->setProperty(propName, value); } @@ -2431,15 +2430,14 @@ void MuonAnalysis::setXMin(IAlgorithm_sptr alg, const std::string& propName) con */ void MuonAnalysis::setXMax(IAlgorithm_sptr alg, const std::string& propName) const { - if ( !m_uiForm.timeAxisFinishAtInput->text().isEmpty() ) + double value = m_optionTab->getCustomFinishTime(); + + if ( value != EMPTY_DBL() ) { - double value = getValidatedDouble(m_uiForm.timeAxisFinishAtInput, "16.0", "custom finish time", - g_log); alg->setProperty(propName, value); } } - /** * Check if grouping in table is consistent with data file * diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysisOptionTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysisOptionTab.cpp index 3b49b93252d8..f43a997a5951 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysisOptionTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysisOptionTab.cpp @@ -24,6 +24,9 @@ namespace CustomInterfaces namespace Muon { +// Acquire logger instance +Logger& MuonAnalysisOptionTab::g_log(Logger::get("MuonAnalysis")); + MuonAnalysisOptionTab::MuonAnalysisOptionTab(Ui::MuonAnalysis &uiForm, const QString &settingsGroup) : m_uiForm(uiForm), m_autoSaver(settingsGroup) {} @@ -216,6 +219,66 @@ QMap MuonAnalysisOptionTab::parsePlotStyleParams() const return(params); } +/** + * Retrieve selected type of the start time + * @return Type of the start time as selected by user + */ +MuonAnalysisOptionTab::StartTimeType MuonAnalysisOptionTab::getStartTimeType() +{ + StartTimeType type; + + QString selectedType = m_uiForm.timeComboBox->currentText(); + + if (selectedType == "Start at First Good Data") + { + type = FirstGoodData; + } + else if (selectedType == "Start at Time Zero") + { + type = TimeZero; + } + else if (selectedType == "Custom Value") + { + type = Custom; + } + else + { + // Just in case misspelled type or added a new one + throw std::runtime_error("Unknown start time type selection"); + } + + return type; +} + +/** + * Retrieve custom start time value. This only makes sense when getStartTimeType() is Custom. + * @return Value in the custom start time field + */ +double MuonAnalysisOptionTab::getCustomStartTime() +{ + QLineEdit* w = m_uiForm.timeAxisStartAtInput; + + return getValidatedDouble(w, "0.0", "custom start time", g_log); +} + +/** + * Retrieve custom finish time value. If the value is not specified - returns EMPTY_DBL(). + * @return Value in the custom finish field or EMPTY_DBL() + */ +double MuonAnalysisOptionTab::getCustomFinishTime() +{ + QLineEdit* w = m_uiForm.timeAxisFinishAtInput; + + if (w->text().isEmpty()) + { + return Mantid::EMPTY_DBL(); + } + else + { + return getValidatedDouble(w, "16.0", "custom finish time", g_log); + } +} + } } }