diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/FunctionBrowser.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/FunctionBrowser.cpp index a5091090e1853d2504aafb2b319a9723dbd797a3..81fe73bff6e7fa821093ec0642caf90cb2cd7099 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/FunctionBrowser.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/FunctionBrowser.cpp @@ -1650,6 +1650,39 @@ void FunctionBrowser::removeFunction() if (!isFunction(prop)) return; removeProperty(prop); updateFunctionIndices(); + + // After removing a function we could end up with + // a CompositeFunction with only one function + // In this case, the function should be kept but + // the composite function should be removed + auto props = m_browser->properties(); + if (!props.isEmpty()) { + // The function browser is not empty + + // Check if the current function in the browser is a + // composite function + auto topProp = props[0]; + auto fun = Mantid::API::FunctionFactory::Instance().createFunction( + topProp->propertyName().toStdString()); + auto cf = boost::dynamic_pointer_cast<Mantid::API::CompositeFunction>(fun); + if (cf) { + // If it is a composite function + // check that there are more than one function + // which means more than two subproperties + size_t nFunctions = props[0]->subProperties().size() - 1; + + if (nFunctions == 1) { + // If only one function remains, remove the composite function: + // Temporary copy the remaining function + auto func = getFunction(m_browser->properties()[0]->subProperties()[1]); + // Remove the composite function + m_browser->removeProperty(topProp); + // Add the temporary stored function + setFunction(func); + } + } + } + emit functionStructureChanged(); }