Skip to content

Commit

Permalink
Refs #6616. Clear errors when doing undoFit
Browse files Browse the repository at this point in the history
Plus some code refactoring to avoid repeating myself
  • Loading branch information
arturbekasov committed Mar 10, 2014
1 parent 87c6819 commit 6eaa99e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 23 deletions.
Expand Up @@ -90,7 +90,7 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS FitPropertyBrowser: public QDockWidget,
/// Get the current function
boost::shared_ptr<const Mantid::API::IFunction> theFunction()const;
/// Update the function parameters
void updateParameters(bool setErrors = false);
void updateParameters();
/// Get function parameter values
QList<double> getParameterValues() const;
/// Get function parameter names
Expand Down
Expand Up @@ -127,8 +127,14 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS PropertyHandler:public QObject, public M
/// Set function vector attribute value
void setVectorAttribute(QtProperty* prop);

/// Update the parameter properties
void updateParameters(bool setErrors = false);
/// Sync all parameter values with the manager
void updateParameters();

/// Set all parameter error values in the manager
void updateErrors();

/// Clear all parameter error values in the manager
void clearErrors();

// Get property for function parameter parName
QtProperty* getParameterProperty(const QString& parName)const;
Expand Down Expand Up @@ -212,6 +218,18 @@ protected slots:
//mutable FunctionCurve* m_curve;//< the curve to plot the handled function
mutable bool m_hasPlot;

/// Sync function parameter value with the manager
void updateParameter(QtProperty* prop);

/// Set function parameter error in the manager
void updateError(QtProperty* prop);

/// Clear function parameter error in the manager
void clearError(QtProperty* prop);

/// Applies given function to all the parameter properties recursively
void applyToAllParameters(void (PropertyHandler::*func)(QtProperty*));

friend class CreateAttributeProperty;
};

Expand Down
11 changes: 6 additions & 5 deletions Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
Expand Up @@ -1849,12 +1849,11 @@ void FitPropertyBrowser::vectorDoubleChanged(QtProperty *prop)
}

/**
* Update the function parameter properties. If isFitDone is true, set parameter errors as well.
* @param setErrors :: Whether errors should be set as well
* Update the function parameter properties
*/
void FitPropertyBrowser::updateParameters(bool setErrors)
void FitPropertyBrowser::updateParameters()
{
getHandler()->updateParameters(setErrors);
getHandler()->updateParameters();
}

/**
Expand Down Expand Up @@ -1913,7 +1912,8 @@ void FitPropertyBrowser::getFitResults()
}
}
while(row.next());
updateParameters(true);
updateParameters();
getHandler()->updateErrors();
}
}

Expand All @@ -1929,6 +1929,7 @@ void FitPropertyBrowser::undoFit()
compositeFunction()->setParameter(i,m_initialParameters[i]);
}
updateParameters();
getHandler()->clearErrors();
}
disableUndo();
}
Expand Down
63 changes: 48 additions & 15 deletions Code/Mantid/MantidQt/MantidWidgets/src/PropertyHandler.cpp
Expand Up @@ -921,35 +921,68 @@ void PropertyHandler::setVectorAttribute(QtProperty *prop)
}

/**
* Update the parameter properties. If isFitDone is true, parameter errors are set as well.
* @param setErrors :: Whether errors should be set
* Applies given function to all the parameter properties recursively, within this context.
* @param func :: Function to apply
*/
void PropertyHandler::updateParameters(bool setErrors)
void PropertyHandler::applyToAllParameters(void (PropertyHandler::*func)(QtProperty*))
{
for(int i=0;i<m_parameters.size();i++)
{
QtProperty* prop = m_parameters[i];

size_t parIndex = function()->parameterIndex(prop->propertyName().toStdString());

double parValue = function()->getParameter(parIndex);
m_browser->m_parameterManager->setValue(prop, parValue);

if (setErrors)
{
double parError = function()->getError(parIndex);
m_browser->m_parameterManager->setError(prop, parError);
}
(this->*(func))(prop);
}

if (m_cf)
{
for(size_t i=0;i<m_cf->nFunctions();i++)
{
getHandler(i)->updateParameters(setErrors);
getHandler(i)->applyToAllParameters(func);
}
}
}

void PropertyHandler::updateParameters()
{
applyToAllParameters(&PropertyHandler::updateParameter);
}

void PropertyHandler::updateErrors()
{
applyToAllParameters(&PropertyHandler::updateError);
}

void PropertyHandler::clearErrors()
{
applyToAllParameters(&PropertyHandler::clearError);
}

/**
* @param prop :: Property of the parameter
*/
void PropertyHandler::updateParameter(QtProperty* prop)
{
double parValue = function()->getParameter(prop->propertyName().toStdString());
m_browser->m_parameterManager->setValue(prop, parValue);
}

/**
* @param prop :: Property of the parameter
*/
void PropertyHandler::updateError(QtProperty* prop)
{
size_t index = function()->parameterIndex(prop->propertyName().toStdString());
double error = function()->getError(index);
m_browser->m_parameterManager->setError(prop, error);
}

/**
* @param prop :: Property of the parameter
*/
void PropertyHandler::clearError(QtProperty* prop)
{
m_browser->m_parameterManager->clearError(prop);
}

/**
* Change the type of the function (replace the function)
* @param prop :: The "Type" property with new value
Expand Down
Expand Up @@ -54,6 +54,7 @@ void ParameterPropertyManager::setError(QtProperty* property, double error)
void ParameterPropertyManager::clearError(QtProperty* property)
{
m_errors.remove(property);
emit propertyChanged(property);
}

/**
Expand Down

0 comments on commit 6eaa99e

Please sign in to comment.