diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FunctionBrowser.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FunctionBrowser.h index 87c698152d416147984d697f1388586bcfcbb8c6..c9ed1e70dcc5161d9133979b1a95a8ff6dcd466e 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FunctionBrowser.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/FunctionBrowser.h @@ -296,6 +296,8 @@ protected slots: void parameterChanged(QtProperty*); void parameterButtonClicked(QtProperty*); void globalChanged(QtProperty*, const QString&, bool); + /// Set value of an attribute (as a property) to a function + void setAttributeToFunction(Mantid::API::IFunction& fun, QtProperty* prop); protected: /// Manager for function group properties diff --git a/MantidQt/MantidWidgets/src/FunctionBrowser.cpp b/MantidQt/MantidWidgets/src/FunctionBrowser.cpp index edd8806fe5a7c6193b98df76b252a8d114346712..4184cc459586d37d77b198d246ceac180de1eab4 100644 --- a/MantidQt/MantidWidgets/src/FunctionBrowser.cpp +++ b/MantidQt/MantidWidgets/src/FunctionBrowser.cpp @@ -1348,6 +1348,28 @@ void FunctionBrowser::addFunction() emit functionStructureChanged(); } +/** + * Set value of an attribute (as a property) to a function. + * @param fun :: Function to which attribute is set. + * @param prop :: A property with the name and value of the attribute. + */ +void FunctionBrowser::setAttributeToFunction(Mantid::API::IFunction& fun, QtProperty* prop) +{ + std::string attName = prop->propertyName().toStdString(); + SetAttributeFromProperty setter(this,prop); + Mantid::API::IFunction::Attribute attr = fun.getAttribute(attName); + attr.apply(setter); + try + { + fun.setAttribute(attName,attr); + } + catch(std::exception& expt) + { + QMessageBox::critical(this,"MantidPlot - Error", "Cannot set attribute " + QString::fromStdString(attName) + + " of function " + prop->propertyName() + ":\n\n" + QString::fromStdString(expt.what())); + } +} + /** * Return the function * @param prop :: Function property @@ -1380,6 +1402,10 @@ Mantid::API::IFunction_sptr FunctionBrowser::getFunction(QtProperty* prop, bool cf->addFunction(f); } } + else if (isAttribute(child)) + { + setAttributeToFunction(*fun, child); + } } } else @@ -1390,19 +1416,7 @@ Mantid::API::IFunction_sptr FunctionBrowser::getFunction(QtProperty* prop, bool { if (isAttribute(child)) { - std::string attName = child->propertyName().toStdString(); - SetAttributeFromProperty setter(this,child); - Mantid::API::IFunction::Attribute attr = fun->getAttribute(attName); - attr.apply(setter); - try - { - fun->setAttribute(attName,attr); - } - catch(std::exception& expt) - { - QMessageBox::critical(this,"MantidPlot - Error", "Cannot set attribute " + QString::fromStdString(attName) + - " of function " + prop->propertyName() + ":\n\n" + QString::fromStdString(expt.what())); - } + setAttributeToFunction(*fun, child); } else if (!attributesOnly && isParameter(child)) {