Skip to content

Commit

Permalink
Refs #8849. Move option tab validation to the tab code.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Mar 4, 2014
1 parent 7257723 commit 09a7b11
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
Expand Up @@ -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);

Expand All @@ -57,6 +60,15 @@ class MuonAnalysisOptionTab : public QWidget
/// Get plot style parameters from widgets
QMap<QString, QString> 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();
Expand All @@ -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;

Expand Down
38 changes: 18 additions & 20 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp
Expand Up @@ -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);
}

Expand All @@ -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
*
Expand Down
Expand Up @@ -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)
{}
Expand Down Expand Up @@ -216,6 +219,66 @@ QMap<QString, QString> 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);
}
}

}
}
}

0 comments on commit 09a7b11

Please sign in to comment.