Skip to content

Commit

Permalink
Refs #6616. Implement error setting and proper displaying
Browse files Browse the repository at this point in the history
Still a few things to do, but the basic functionality works perfectly
  • Loading branch information
arturbekasov committed Mar 7, 2014
1 parent a3210c0 commit 3db8431
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
11 changes: 8 additions & 3 deletions Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
Expand Up @@ -1868,14 +1868,19 @@ void FitPropertyBrowser::getFitResults()
try
{
std::string name;
double value;
row >> name >> value;
double value, error;
row >> name >> value >> error;

// In case of a single function Fit doesn't create a CompositeFunction
if (count() == 1)
{
name.insert(0,"f0.");
}
compositeFunction()->setParameter(name,value);

size_t paramIndex = compositeFunction()->parameterIndex(name);

compositeFunction()->setParameter(paramIndex,value);
compositeFunction()->setError(paramIndex, error);
}
catch(...)
{
Expand Down
11 changes: 8 additions & 3 deletions Code/Mantid/MantidQt/MantidWidgets/src/PropertyHandler.cpp
Expand Up @@ -928,9 +928,14 @@ void PropertyHandler::updateParameters()
for(int i=0;i<m_parameters.size();i++)
{
QtProperty* prop = m_parameters[i];
std::string parName = prop->propertyName().toStdString();
double parValue = function()->getParameter(parName);
m_browser->m_parameterManager->setValue(prop,parValue);

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

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

double parError = function()->getError(parIndex);
m_browser->m_parameterManager->setError(prop, parError);
}
if (m_cf)
{
Expand Down
49 changes: 48 additions & 1 deletion Code/Mantid/QtPropertyBrowser/src/ParameterPropertyManager.cpp
@@ -1,10 +1,44 @@
#include "ParameterPropertyManager.h"

#include "qtpropertymanager.h"

#include <stdexcept>

ParameterPropertyManager::ParameterPropertyManager(QObject *parent)
: QtDoublePropertyManager(parent)
{}

/**
* Throws if property error is not set
* @param property :: Property to get error for
* @return Error value of the property
*/
double ParameterPropertyManager::error(const QtProperty* property) const
{
if (!m_errors.contains(property))
throw std::runtime_error("Parameter doesn't have error value set");

return m_errors[property];
}

/**
* @param property :: Property to check
* @return True if error was set for the property, false otherwise
*/
bool ParameterPropertyManager::isErrorSet(const QtProperty* property) const
{
return m_errors.contains(property);
}

/**
* @param property :: Property to set error for
* @param error :: Error value to set
*/
void ParameterPropertyManager::setError(const QtProperty* property, double error)
{
m_errors[property] = error;
}

/**
* Adds error parameter value to property display
* @param property :: Property we want to display
Expand All @@ -13,5 +47,18 @@ ParameterPropertyManager::ParameterPropertyManager(QObject *parent)
*/
QString ParameterPropertyManager::valueText(const QtProperty* property) const
{
return QtDoublePropertyManager::valueText(property) + " (Error here)";
QString originalValueText = QtDoublePropertyManager::valueText(property);

if (isErrorSet(property))
{
double propError = error(property);
int precision = decimals(property);

return originalValueText + QString(" (%1)").arg(propError, 0, 'g', precision);
}
else
{
// No error set, so don't append error value
return originalValueText;
}
}
18 changes: 17 additions & 1 deletion Code/Mantid/QtPropertyBrowser/src/ParameterPropertyManager.h
Expand Up @@ -3,6 +3,8 @@

#include "qtpropertymanager.h"

#include <QMap>

/** ParameterPropertyManager : specialized version of QtDoublePropertyManager for fitting parameters.
Is capable to store/display parameter errors in addition to value.
Expand Down Expand Up @@ -34,9 +36,23 @@ class ParameterPropertyManager : public QtDoublePropertyManager
public:
ParameterPropertyManager(QObject *parent = 0);

/// Get property error
double error(const QtProperty* property) const;

/// Checks if given property has error value set
bool isErrorSet(const QtProperty* property) const;

public Q_SLOTS:
/// Set property error
void setError(const QtProperty* property, double error);

protected:
/// Text representation of the property
virtual QString valueText(const QtProperty *property) const;
virtual QString valueText(const QtProperty* property) const;

private:
/// Property error values
QMap<const QtProperty*, double> m_errors;
};

#endif // PARAMETERPROPERTYMANAGER_H

0 comments on commit 3db8431

Please sign in to comment.