Skip to content

Commit

Permalink
Refs #6616. Make it possible to turn error display on and off
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Mar 10, 2014
1 parent 2bbe163 commit da32970
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
Expand Up @@ -382,6 +382,7 @@ private slots:
QtProperty *m_xColumn;
QtProperty *m_yColumn;
QtProperty *m_errColumn;
QtProperty *m_showParamErrors;
QList<QtProperty*> m_minimizerProperties;

/// A copy of the edited function
Expand Down
18 changes: 16 additions & 2 deletions Code/Mantid/MantidQt/MantidWidgets/src/FitPropertyBrowser.cpp
Expand Up @@ -245,6 +245,11 @@ void FitPropertyBrowser::init()
QVariant(false)).toBool();
m_boolManager->setValue(m_convolveMembers, convolveCompositeItems);

m_showParamErrors = m_boolManager->addProperty("Show Parameter Errors");
bool showParamErrors = settings.value(m_showParamErrors->propertyName(), false).toBool();
m_boolManager->setValue(m_showParamErrors, showParamErrors);
m_parameterManager->setErrorsEnabled(showParamErrors);

m_xColumn = m_columnManager->addProperty("XColumn");
m_yColumn = m_columnManager->addProperty("YColumn");
m_errColumn = m_columnManager->addProperty("ErrColumn");
Expand All @@ -262,6 +267,7 @@ void FitPropertyBrowser::init()
settingsGroup->addSubProperty(m_plotDiff);
settingsGroup->addSubProperty(m_plotCompositeMembers);
settingsGroup->addSubProperty(m_convolveMembers);
settingsGroup->addSubProperty(m_showParamErrors);

/* Create editors and assign them to the managers */
createEditors(w);
Expand Down Expand Up @@ -1226,11 +1232,19 @@ void FitPropertyBrowser::boolChanged(QtProperty* prop)
{
if ( ! m_changeSlotsEnabled ) return;

if ( prop == m_plotDiff || prop == m_plotCompositeMembers || prop == m_ignoreInvalidData )
if ( prop == m_plotDiff || prop == m_plotCompositeMembers || prop == m_ignoreInvalidData
|| prop == m_showParamErrors )
{
bool val = m_boolManager->value(prop);

QSettings settings;
settings.beginGroup("Mantid/FitBrowser");
settings.setValue(prop->propertyName(), m_boolManager->value(prop));
settings.setValue(prop->propertyName(), val);

if ( m_showParamErrors )
{
m_parameterManager->setErrorsEnabled(val);
}
}
else
{// it could be an attribute
Expand Down
21 changes: 18 additions & 3 deletions Code/Mantid/QtPropertyBrowser/src/ParameterPropertyManager.cpp
Expand Up @@ -5,7 +5,8 @@
#include <stdexcept>

ParameterPropertyManager::ParameterPropertyManager(QObject *parent)
: QtDoublePropertyManager(parent)
: QtDoublePropertyManager(parent),
m_errors(), m_errorsEnabled(false)
{}

/**
Expand Down Expand Up @@ -55,6 +56,20 @@ void ParameterPropertyManager::clearError(QtProperty* property)
m_errors.remove(property);
}

/**
* Sets errors enabled state. Updates all the properties as well to show/hide errors.
* @param enabled :: New errors enabled state
*/
void ParameterPropertyManager::setErrorsEnabled(bool enabled)
{
m_errorsEnabled = enabled;

foreach(QtProperty* prop, m_errors.keys())
{
emit propertyChanged(prop);
}
}

/**
* Adds error parameter value to property display
* @param property :: Property we want to display
Expand All @@ -65,7 +80,7 @@ QString ParameterPropertyManager::valueText(const QtProperty* property) const
{
QString originalValueText = QtDoublePropertyManager::valueText(property);

if (isErrorSet(property))
if (areErrorsEnabled() && isErrorSet(property))
{
double propError = error(property);
int precision = decimals(property);
Expand All @@ -74,7 +89,7 @@ QString ParameterPropertyManager::valueText(const QtProperty* property) const
}
else
{
// No error set, so don't append error value
// No error set or errors disabled, so don't append error value
return originalValueText;
}
}
9 changes: 9 additions & 0 deletions Code/Mantid/QtPropertyBrowser/src/ParameterPropertyManager.h
Expand Up @@ -42,20 +42,29 @@ class ParameterPropertyManager : public QtDoublePropertyManager
/// Checks if given property has error value set
bool isErrorSet(const QtProperty* property) const;

/// Returns errors enabled status
bool areErrorsEnabled() const { return m_errorsEnabled; }

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

/// Clears error of the property, if one was set
void clearError(QtProperty* property);

/// Enabled/disables error display
void setErrorsEnabled(bool enabled);

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

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

/// Errors enabled flag. When is false, errors can be set, but will not be displayed
bool m_errorsEnabled;
};

#endif // PARAMETERPROPERTYMANAGER_H

0 comments on commit da32970

Please sign in to comment.