Skip to content

Commit

Permalink
Refs #6616. Move param descr. handling to parameter manager
Browse files Browse the repository at this point in the history
This will allow me to update it more easily and when it's needed
  • Loading branch information
arturbekasov committed Mar 12, 2014
1 parent 78e2469 commit 8da86b3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
8 changes: 3 additions & 5 deletions Code/Mantid/MantidQt/MantidWidgets/src/PropertyHandler.cpp
Expand Up @@ -249,12 +249,10 @@ void PropertyHandler::initParameters()
QString parName = QString::fromStdString(function()->parameterName(i));
if (parName.contains('.')) continue;
QtProperty* prop = m_browser->addDoubleProperty(parName, m_browser->m_parameterManager);
QString toolTip = QString::fromStdString(function()->parameterDescription(i));
if (!toolTip.isEmpty())
{
prop->setToolTip(toolTip);
}

m_browser->m_parameterManager->setDescription(prop, function()->parameterDescription(i));
m_browser->m_parameterManager->setValue(prop,function()->getParameter(i));

m_item->property()->addSubProperty(prop);
m_parameters << prop;
// add tie property if this parameter has a tie
Expand Down
39 changes: 38 additions & 1 deletion Code/Mantid/QtPropertyBrowser/src/ParameterPropertyManager.cpp
Expand Up @@ -26,6 +26,21 @@ double ParameterPropertyManager::error(const QtProperty* property) const
return m_errors[prop];
}

/**
* @param property :: Parameter property
* @return Parameter description
*/
std::string ParameterPropertyManager::description(const QtProperty* property) const
{
// Cast for searching purposes
auto prop = const_cast<QtProperty*>(property);

if(!m_descriptions.contains(prop))
throw std::runtime_error("Parameter doesn't have description set");

return m_descriptions[prop];
}

/**
* @param property :: Property to check
* @return True if error was set for the property, false otherwise
Expand All @@ -42,10 +57,21 @@ bool ParameterPropertyManager::isErrorSet(const QtProperty* property) const
* @param property :: Property to set error for
* @param error :: Error value to set
*/
void ParameterPropertyManager::setError(QtProperty* property, double error)
void ParameterPropertyManager::setError(QtProperty* property, const double& error)
{
m_errors[property] = error;
emit propertyChanged(property);
// TODO: update tooltip
}

/**
* @param property :: Parameter property to set error for
* @param description :: Description of the parameter
*/
void ParameterPropertyManager::setDescription(QtProperty* property, const std::string& description)
{
m_descriptions[property] = description;
updateTooltip(property);
}

/**
Expand All @@ -56,6 +82,7 @@ void ParameterPropertyManager::clearError(QtProperty* property)
{
m_errors.remove(property);
emit propertyChanged(property);
// TODO: update tooltip
}

/**
Expand All @@ -69,6 +96,7 @@ void ParameterPropertyManager::setErrorsEnabled(bool enabled)
foreach(QtProperty* prop, m_errors.keys())
{
emit propertyChanged(prop);
// TODO: update tooltip
}
}

Expand Down Expand Up @@ -99,3 +127,12 @@ QString ParameterPropertyManager::valueText(const QtProperty* property) const
return originalValueText;
}
}

/**
* @param property :: Property to update tooltip for
*/
void ParameterPropertyManager::updateTooltip(QtProperty* property) const
{
property->setToolTip(QString::fromStdString(description(property)));
// TODO: append description for error if enabled and set
}
19 changes: 16 additions & 3 deletions Code/Mantid/QtPropertyBrowser/src/ParameterPropertyManager.h
Expand Up @@ -36,9 +36,12 @@ class QT_QTPROPERTYBROWSER_EXPORT ParameterPropertyManager : public QtDoubleProp
public:
ParameterPropertyManager(QObject *parent = 0);

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

/// Get parameter description
std::string description(const QtProperty* property) const;

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

Expand All @@ -47,7 +50,10 @@ class QT_QTPROPERTYBROWSER_EXPORT ParameterPropertyManager : public QtDoubleProp

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

/// Set parameter description
void setDescription(QtProperty* property, const std::string& description);

/// Clears error of the property, if one was set
void clearError(QtProperty* property);
Expand All @@ -59,10 +65,17 @@ public Q_SLOTS:
/// Text representation of the property
virtual QString valueText(const QtProperty* property) const;

private Q_SLOTS:
/// Updates the tooltip of the property
void updateTooltip(QtProperty* property) const;

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

/// Parameter descriptions
QMap<QtProperty*, std::string> m_descriptions;

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

0 comments on commit 8da86b3

Please sign in to comment.