diff --git a/Code/Mantid/API/src/CompositeFunction.cpp b/Code/Mantid/API/src/CompositeFunction.cpp index a49122c1b2aeed450072e216149e340e2432b0df..3a06d489212bd369622b435786bebbcb9a6126af 100644 --- a/Code/Mantid/API/src/CompositeFunction.cpp +++ b/Code/Mantid/API/src/CompositeFunction.cpp @@ -260,11 +260,11 @@ int CompositeFunction::parameterIndex(const std::string& name)const return getFunction(index)->parameterIndex(pname) + m_paramOffsets[index]; } -/** - * Checks that a pointer points to a parameter of this function and returns its index. - * @param p A pointer to a double variable. - * @return The index of the parameter or -1 if p is not a pointer to any of the function's parameters. - */ +///** +// * Checks that a pointer points to a parameter of this function and returns its index. +// * @param p A pointer to a double variable. +// * @return The index of the parameter or -1 if p is not a pointer to any of the function's parameters. +// */ //int CompositeFunction::parameterIndex(const double* p)const //{ // for(int iFun=0;iFun<nFunctions();iFun++) diff --git a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp index c922338a46d0f23016ce0b5b9d98fdec749673f7..2db2df366fcf0bd89603dca8c386ca5726128dd0 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/FitPropertyBrowser.cpp @@ -12,8 +12,8 @@ #include "MantidAPI/ParameterTie.h" #include "MantidAPI/IConstraint.h" #include "MantidAPI/ConstraintFactory.h" -#include "MantidKernel/ConfigService.h" -#include "MantidKernel/LibraryManager.h" +#include "MantidKernel/ConfigService.h" +#include "MantidKernel/LibraryManager.h" #include "FilenameEditorFactory.h" @@ -61,19 +61,19 @@ m_logValue(NULL) else { // Make sure plugins are loaded - std::string libpath = Mantid::Kernel::ConfigService::Instance().getString("plugins.directory"); - if( !libpath.empty() ) - { - Mantid::Kernel::LibraryManager::Instance().OpenAllLibraries(libpath); - } + std::string libpath = Mantid::Kernel::ConfigService::Instance().getString("plugins.directory"); + if( !libpath.empty() ) + { + Mantid::Kernel::LibraryManager::Instance().OpenAllLibraries(libpath); + } setAutoBackgroundName(m_autoBgName); } - setObjectName("FitFunction"); // this is needed for QMainWindow::restoreState() - setMinimumHeight(150); - setMinimumWidth(200); - m_appWindow->addDockWidget( Qt::LeftDockWidgetArea, this ); - + setObjectName("FitFunction"); // this is needed for QMainWindow::restoreState() + setMinimumHeight(150); + setMinimumWidth(200); + m_appWindow->addDockWidget( Qt::LeftDockWidgetArea, this ); + QWidget* w = new QWidget(parent); /* Create property managers: they create, own properties, get and set values */ @@ -177,9 +177,9 @@ m_logValue(NULL) setWidget(w); - m_browser->setContextMenuPolicy(Qt::CustomContextMenu); - connect(m_browser, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(popupMenu(const QPoint &))); - connect(m_browser, SIGNAL(currentItemChanged(QtBrowserItem*)), this, SLOT(currentItemChanged(QtBrowserItem*))); + m_browser->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_browser, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(popupMenu(const QPoint &))); + connect(m_browser, SIGNAL(currentItemChanged(QtBrowserItem*)), this, SLOT(currentItemChanged(QtBrowserItem*))); createCompositeFunction(); @@ -291,96 +291,96 @@ void FitPropertyBrowser::popupMenu(const QPoint &) if (isFunctionsGroup) { - action = new QAction("Add function",this); - connect(action,SIGNAL(triggered()),this,SLOT(addFunction())); - menu->addAction(action); - - if (m_peakToolOn) - { - if (h && h->hasPlot()) - { - action = new QAction("Remove plot",this); - connect(action,SIGNAL(triggered()),this,SLOT(removeGuessAll())); - menu->addAction(action); - } - else - { - action = new QAction("Plot",this); - connect(action,SIGNAL(triggered()),this,SLOT(plotGuessAll())); - menu->addAction(action); - } - } - + action = new QAction("Add function",this); + connect(action,SIGNAL(triggered()),this,SLOT(addFunction())); + menu->addAction(action); + + if (m_peakToolOn) + { + if (h && h->hasPlot()) + { + action = new QAction("Remove plot",this); + connect(action,SIGNAL(triggered()),this,SLOT(removeGuessAll())); + menu->addAction(action); + } + else + { + action = new QAction("Plot",this); + connect(action,SIGNAL(triggered()),this,SLOT(plotGuessAll())); + menu->addAction(action); + } + } + menu->addSeparator(); - - action = new QAction("Save",this); - connect(action,SIGNAL(triggered()),this,SLOT(saveFunction())); - menu->addAction(action); - - action = new QAction("Load",this); - connect(action,SIGNAL(triggered()),this,SLOT(loadFunction())); - menu->addAction(action); - - action = new QAction("Copy",this); - connect(action,SIGNAL(triggered()),this,SLOT(copy())); - menu->addAction(action); - - //action = new QAction("Paste",this); - //connect(action,SIGNAL(triggered()),this,SLOT(paste())); - //menu->addAction(action); - + + action = new QAction("Save",this); + connect(action,SIGNAL(triggered()),this,SLOT(saveFunction())); + menu->addAction(action); + + action = new QAction("Load",this); + connect(action,SIGNAL(triggered()),this,SLOT(loadFunction())); + menu->addAction(action); + + action = new QAction("Copy",this); + connect(action,SIGNAL(triggered()),this,SLOT(copy())); + menu->addAction(action); + + //action = new QAction("Paste",this); + //connect(action,SIGNAL(triggered()),this,SLOT(paste())); + //menu->addAction(action); + menu->addSeparator(); } else if (isFunctionsGroup || isSettingsGroup || isASetting) { if (isFitEnabled()) { - action = new QAction("Fit",this); - connect(action,SIGNAL(triggered()),this,SLOT(fit())); - menu->addAction(action); - } - - if (isUndoEnabled()) - { - action = new QAction("Undo Fit",this); - connect(action,SIGNAL(triggered()),this,SLOT(undoFit())); - menu->addAction(action); - } - - action = new QAction("Clear all",this); - connect(action,SIGNAL(triggered()),this,SLOT(clear())); - menu->addAction(action); - + action = new QAction("Fit",this); + connect(action,SIGNAL(triggered()),this,SLOT(fit())); + menu->addAction(action); + } + + if (isUndoEnabled()) + { + action = new QAction("Undo Fit",this); + connect(action,SIGNAL(triggered()),this,SLOT(undoFit())); + menu->addAction(action); + } + + action = new QAction("Clear all",this); + connect(action,SIGNAL(triggered()),this,SLOT(clear())); + menu->addAction(action); + } else if (isFunction) { if (isCompositeFunction) { - action = new QAction("Add function",this); - connect(action,SIGNAL(triggered()),this,SLOT(addFunction())); - menu->addAction(action); + action = new QAction("Add function",this); + connect(action,SIGNAL(triggered()),this,SLOT(addFunction())); + menu->addAction(action); + } + + action = new QAction("Remove",this); + connect(action,SIGNAL(triggered()),this,SLOT(deleteFunction())); + menu->addAction(action); + + if (m_peakToolOn) + { + if (h && h->hasPlot()) + { + action = new QAction("Remove plot",this); + connect(action,SIGNAL(triggered()),this,SLOT(removeGuessCurrent())); + menu->addAction(action); + } + else + { + action = new QAction("Plot",this); + connect(action,SIGNAL(triggered()),this,SLOT(plotGuessCurrent())); + menu->addAction(action); + } } - action = new QAction("Remove",this); - connect(action,SIGNAL(triggered()),this,SLOT(deleteFunction())); - menu->addAction(action); - - if (m_peakToolOn) - { - if (h && h->hasPlot()) - { - action = new QAction("Remove plot",this); - connect(action,SIGNAL(triggered()),this,SLOT(removeGuessCurrent())); - menu->addAction(action); - } - else - { - action = new QAction("Plot",this); - connect(action,SIGNAL(triggered()),this,SLOT(plotGuessCurrent())); - menu->addAction(action); - } - } - menu->addSeparator(); } else if (h) @@ -395,114 +395,114 @@ void FitPropertyBrowser::popupMenu(const QPoint &) isParameter = false; } - if (isTie) - { - //menu->addSeparator(); - action = new QAction("Remove",this); - connect(action,SIGNAL(triggered()),this,SLOT(deleteTie())); - menu->addAction(action); - } - else if (isLowerBound || isUpperBound) - { - action = new QAction("Remove",this); - connect(action,SIGNAL(triggered()),this,SLOT(removeBounds())); - menu->addAction(action); - } - else if (count() > 0 && isParameter) - { - bool hasTies; - bool hasBounds; - hasConstraints(ci->property(),hasTies,hasBounds); - - if (!hasTies && !hasBounds) - { - action = new QAction("Fix",this); - connect(action,SIGNAL(triggered()),this,SLOT(addFixTie())); - menu->addAction(action); - } - - if (!hasTies) - { - QMenu *constraintMenu = menu->addMenu("Constraint"); - - QMenu* detailMenu = constraintMenu->addMenu("Lower Bound"); - - action = new QAction("10%",this); - connect(action,SIGNAL(triggered()),this,SLOT(addLowerBound10())); - detailMenu->addAction(action); - - action = new QAction("50%",this); - connect(action,SIGNAL(triggered()),this,SLOT(addLowerBound50())); - detailMenu->addAction(action); - - action = new QAction("Custom",this); - connect(action,SIGNAL(triggered()),this,SLOT(addLowerBound())); - detailMenu->addAction(action); - detailMenu = constraintMenu->addMenu("Upper Bound"); - - action = new QAction("10%",this); - connect(action,SIGNAL(triggered()),this,SLOT(addUpperBound10())); - detailMenu->addAction(action); - - action = new QAction("50%",this); - connect(action,SIGNAL(triggered()),this,SLOT(addUpperBound50())); - detailMenu->addAction(action); - - action = new QAction("Custom",this); - connect(action,SIGNAL(triggered()),this,SLOT(addUpperBound())); - detailMenu->addAction(action); - detailMenu = constraintMenu->addMenu("Both Bounds"); - - action = new QAction("10%",this); - connect(action,SIGNAL(triggered()),this,SLOT(addBothBounds10())); - detailMenu->addAction(action); - - action = new QAction("50%",this); - connect(action,SIGNAL(triggered()),this,SLOT(addBothBounds50())); - detailMenu->addAction(action); - - action = new QAction("Custom",this); - connect(action,SIGNAL(triggered()),this,SLOT(addBothBounds())); - detailMenu->addAction(action); - } - - if (hasBounds) - { - action = new QAction("Remove constraints",this); - connect(action,SIGNAL(triggered()),this,SLOT(removeBounds())); - menu->addAction(action); - } - - if (!hasTies && !hasBounds) - { - if (count() == 1) - { - action = new QAction("Tie",this); - connect(action,SIGNAL(triggered()),this,SLOT(addTie())); - menu->addAction(action); - } - else - { - QMenu* detail = menu->addMenu("Tie"); - - action = new QAction("To function",this); - connect(action,SIGNAL(triggered()),this,SLOT(addTieToFunction())); - detail->addAction(action); - - action = new QAction("Custom Tie",this); - connect(action,SIGNAL(triggered()),this,SLOT(addTie())); - detail->addAction(action); - } - } - else if (hasTies) - { - action = new QAction("Remove tie",this); - connect(action,SIGNAL(triggered()),this,SLOT(deleteTie())); - menu->addAction(action); - } - } - } - + if (isTie) + { + //menu->addSeparator(); + action = new QAction("Remove",this); + connect(action,SIGNAL(triggered()),this,SLOT(deleteTie())); + menu->addAction(action); + } + else if (isLowerBound || isUpperBound) + { + action = new QAction("Remove",this); + connect(action,SIGNAL(triggered()),this,SLOT(removeBounds())); + menu->addAction(action); + } + else if (count() > 0 && isParameter) + { + bool hasTies; + bool hasBounds; + hasConstraints(ci->property(),hasTies,hasBounds); + + if (!hasTies && !hasBounds) + { + action = new QAction("Fix",this); + connect(action,SIGNAL(triggered()),this,SLOT(addFixTie())); + menu->addAction(action); + } + + if (!hasTies) + { + QMenu *constraintMenu = menu->addMenu("Constraint"); + + QMenu* detailMenu = constraintMenu->addMenu("Lower Bound"); + + action = new QAction("10%",this); + connect(action,SIGNAL(triggered()),this,SLOT(addLowerBound10())); + detailMenu->addAction(action); + + action = new QAction("50%",this); + connect(action,SIGNAL(triggered()),this,SLOT(addLowerBound50())); + detailMenu->addAction(action); + + action = new QAction("Custom",this); + connect(action,SIGNAL(triggered()),this,SLOT(addLowerBound())); + detailMenu->addAction(action); + detailMenu = constraintMenu->addMenu("Upper Bound"); + + action = new QAction("10%",this); + connect(action,SIGNAL(triggered()),this,SLOT(addUpperBound10())); + detailMenu->addAction(action); + + action = new QAction("50%",this); + connect(action,SIGNAL(triggered()),this,SLOT(addUpperBound50())); + detailMenu->addAction(action); + + action = new QAction("Custom",this); + connect(action,SIGNAL(triggered()),this,SLOT(addUpperBound())); + detailMenu->addAction(action); + detailMenu = constraintMenu->addMenu("Both Bounds"); + + action = new QAction("10%",this); + connect(action,SIGNAL(triggered()),this,SLOT(addBothBounds10())); + detailMenu->addAction(action); + + action = new QAction("50%",this); + connect(action,SIGNAL(triggered()),this,SLOT(addBothBounds50())); + detailMenu->addAction(action); + + action = new QAction("Custom",this); + connect(action,SIGNAL(triggered()),this,SLOT(addBothBounds())); + detailMenu->addAction(action); + } + + if (hasBounds) + { + action = new QAction("Remove constraints",this); + connect(action,SIGNAL(triggered()),this,SLOT(removeBounds())); + menu->addAction(action); + } + + if (!hasTies && !hasBounds) + { + if (count() == 1) + { + action = new QAction("Tie",this); + connect(action,SIGNAL(triggered()),this,SLOT(addTie())); + menu->addAction(action); + } + else + { + QMenu* detail = menu->addMenu("Tie"); + + action = new QAction("To function",this); + connect(action,SIGNAL(triggered()),this,SLOT(addTieToFunction())); + detail->addAction(action); + + action = new QAction("Custom Tie",this); + connect(action,SIGNAL(triggered()),this,SLOT(addTie())); + detail->addAction(action); + } + } + else if (hasTies) + { + action = new QAction("Remove tie",this); + connect(action,SIGNAL(triggered()),this,SLOT(deleteTie())); + menu->addAction(action); + } + } + } + menu->popup(QCursor::pos()); } @@ -878,7 +878,7 @@ void FitPropertyBrowser::populateFunctionNames() std::string fnName = names[i]; QString qfnName = QString::fromStdString(fnName); m_registeredFunctions << qfnName; - boost::shared_ptr<Mantid::API::IFunction> f = Mantid::API::FunctionFactory::Instance().create(fnName); + boost::shared_ptr<Mantid::API::IFunction> f = Mantid::API::FunctionFactory::Instance().create(fnName); f->initialize(); Mantid::API::IPeakFunction* pf = dynamic_cast<Mantid::API::IPeakFunction*>(f.get()); //Mantid::API::CompositeFunction* cf = dynamic_cast<Mantid::API::CompositeFunction*>(f.get()); @@ -1028,15 +1028,15 @@ void FitPropertyBrowser::populateWorkspaceNames() void FitPropertyBrowser::workspace_added(const QString &wsName, Mantid::API::Workspace_sptr ws) { if ( !isWorkspaceValid(ws) ) return; - QString oldName = QString::fromStdString(workspaceName()); - int i = m_workspaceNames.indexOf(wsName); + QString oldName = QString::fromStdString(workspaceName()); + int i = m_workspaceNames.indexOf(wsName); if (i < 0) { m_workspaceNames.append(wsName); m_workspaceNames.sort(); } m_enumManager->setEnumNames(m_workspace, m_workspaceNames); - i = m_workspaceNames.indexOf(oldName); + i = m_workspaceNames.indexOf(oldName); if (i >= 0) { m_enumManager->setValue(m_workspace,i); @@ -1045,14 +1045,14 @@ void FitPropertyBrowser::workspace_added(const QString &wsName, Mantid::API::Wor void FitPropertyBrowser::workspace_removed(const QString &wsName) { - QString oldName = QString::fromStdString(workspaceName()); - int i = m_workspaceNames.indexOf(wsName); + QString oldName = QString::fromStdString(workspaceName()); + int i = m_workspaceNames.indexOf(wsName); if (i >= 0) { m_workspaceNames.removeAt(i); } m_enumManager->setEnumNames(m_workspace, m_workspaceNames); - i = m_workspaceNames.indexOf(oldName); + i = m_workspaceNames.indexOf(oldName); if (i >= 0) { m_enumManager->setValue(m_workspace,i); @@ -1060,18 +1060,18 @@ void FitPropertyBrowser::workspace_removed(const QString &wsName) } void FitPropertyBrowser::init() -{ - populateFunctionNames(); - populateWorkspaceNames(); +{ + populateFunctionNames(); + populateWorkspaceNames(); connect(m_appWindow->mantidUI,SIGNAL(workspace_added(const QString &, Mantid::API::Workspace_sptr)), this,SLOT(workspace_added(const QString &, Mantid::API::Workspace_sptr))); connect(m_appWindow->mantidUI,SIGNAL(workspace_removed(const QString &)), this,SLOT(workspace_removed(const QString &))); -} - +} + /** Check if the workspace can be used in the fit. The accepted types are - * MatrixWorkspaces same size - * @param ws The workspace + * MatrixWorkspaces same size + * @param ws The workspace */ bool FitPropertyBrowser::isWorkspaceValid(Mantid::API::Workspace_sptr ws)const { @@ -1079,16 +1079,16 @@ bool FitPropertyBrowser::isWorkspaceValid(Mantid::API::Workspace_sptr ws)const { return true; } - else - { - return false; - } -} + else + { + return false; + } +} bool FitPropertyBrowser::isWorkspaceAGroup()const { - // MG: Disabled as there is an issue with replacing workspace groups and the browser - return false; + // MG: Disabled as there is an issue with replacing workspace groups and the browser + return false; } /// Is the current function a peak? @@ -1186,102 +1186,102 @@ void FitPropertyBrowser::clearBrowser() } } -/// Set the parameters to the fit outcome -void FitPropertyBrowser::getFitResults() -{ - if (isWorkspaceAGroup()) - { - std::string wsName = outputName(); - Mantid::API::ITableWorkspace_sptr ws = boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( - Mantid::API::AnalysisDataService::Instance().retrieve(wsName) ); - if (ws) - { - if ((ws->columnCount() - 1)/2 != compositeFunction()->nParams()) return; - Mantid::API::WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>( - Mantid::API::AnalysisDataService::Instance().retrieve(workspaceName()) ); - std::vector<std::string> names = wsg->getNames(); - std::vector<std::string>::iterator it = - std::find(names.begin(),names.end(),m_groupMember); - if (it == names.end()) return; - int row = int(it - names.begin()) - 1;// take into account the group name - if (row >= ws->rowCount()) return; - for(int i=0;i<compositeFunction()->nParams();++i) - { - compositeFunction()->setParameter(i,ws->Double(row,2*i+1)); - } - updateParameters(); - plotGuessAll(); - } - } - else - { - std::string wsName = outputName() + "_Parameters"; - Mantid::API::ITableWorkspace_sptr ws = boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( - Mantid::API::AnalysisDataService::Instance().retrieve(wsName) ); - - if (ws) - { - try - { - Mantid::API::TableRow row = ws->getFirstRow(); - do - { - std::string name; - double value; - row >> name >> value; - // In case of a single function Fit doesn't create a CompositeFunction - if (count() == 1) - { - name.insert(0,"f0."); - } - compositeFunction()->setParameter(name,value); - } - while(row.next()); +/// Set the parameters to the fit outcome +void FitPropertyBrowser::getFitResults() +{ + if (isWorkspaceAGroup()) + { + std::string wsName = outputName(); + Mantid::API::ITableWorkspace_sptr ws = boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( + Mantid::API::AnalysisDataService::Instance().retrieve(wsName) ); + if (ws) + { + if ((ws->columnCount() - 1)/2 != compositeFunction()->nParams()) return; + Mantid::API::WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>( + Mantid::API::AnalysisDataService::Instance().retrieve(workspaceName()) ); + std::vector<std::string> names = wsg->getNames(); + std::vector<std::string>::iterator it = + std::find(names.begin(),names.end(),m_groupMember); + if (it == names.end()) return; + int row = int(it - names.begin()) - 1;// take into account the group name + if (row >= ws->rowCount()) return; + for(int i=0;i<compositeFunction()->nParams();++i) + { + compositeFunction()->setParameter(i,ws->Double(row,2*i+1)); + } + updateParameters(); + plotGuessAll(); + } + } + else + { + std::string wsName = outputName() + "_Parameters"; + Mantid::API::ITableWorkspace_sptr ws = boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>( + Mantid::API::AnalysisDataService::Instance().retrieve(wsName) ); + + if (ws) + { + try + { + Mantid::API::TableRow row = ws->getFirstRow(); + do + { + std::string name; + double value; + row >> name >> value; + // In case of a single function Fit doesn't create a CompositeFunction + if (count() == 1) + { + name.insert(0,"f0."); + } + compositeFunction()->setParameter(name,value); + } + while(row.next()); updateParameters(); - } - catch(...) - { - // do nothing - } - } - } -} - -/** - * Slot. Undoes the fit: restores the parameters to their initial values. - */ -void FitPropertyBrowser::undoFit() -{ - if (m_initialParameters.size() == compositeFunction()->nParams()) - { + } + catch(...) + { + // do nothing + } + } + } +} + +/** + * Slot. Undoes the fit: restores the parameters to their initial values. + */ +void FitPropertyBrowser::undoFit() +{ + if (m_initialParameters.size() == compositeFunction()->nParams()) + { for(int i=0;i<compositeFunction()->nParams();i++) { compositeFunction()->setParameter(i,m_initialParameters[i]); } updateParameters(); - } + } disableUndo(); -} - -/// disable undo when the function changes -void FitPropertyBrowser::disableUndo() -{ - m_initialParameters.clear(); - m_btnUnFit->setEnabled(false); -} - +} + +/// disable undo when the function changes +void FitPropertyBrowser::disableUndo() +{ + m_initialParameters.clear(); + m_btnUnFit->setEnabled(false); +} + /// Tells if undo can be done bool FitPropertyBrowser::isUndoEnabled()const { return m_initialParameters.size() && compositeFunction()->nParams() == m_initialParameters.size(); } -/// Enable/disable the Fit button; -void FitPropertyBrowser::setFitEnabled(bool yes) -{ - m_btnFit->setEnabled(yes); -} - +/// Enable/disable the Fit button; +void FitPropertyBrowser::setFitEnabled(bool yes) +{ + m_btnFit->setEnabled(yes); +} + /// Returns true if the function is ready for a fit bool FitPropertyBrowser::isFitEnabled()const { @@ -1327,7 +1327,6 @@ void FitPropertyBrowser::addTieToFunction() if (!h) return; if (!h->isParameter(paramProp)) return; std::string parName = paramProp->propertyName().toStdString(); - bool ok; QStringList fnNames; int iPar = -1; @@ -1335,14 +1334,17 @@ void FitPropertyBrowser::addTieToFunction() { Mantid::API::ParameterReference ref(m_compositeFunction,i); Mantid::API::IFunction* fun = ref.getFunction(); - if (fun == h->function()) - { - iPar = i; - continue; - } - if (fun->parameterName(ref.getIndex()) == parName) + // Pick out parameters with the same name as the one we're tying from + if ( fun->parameterName(ref.getIndex()) == parName ) { - fnNames << QString::fromStdString(m_compositeFunction->parameterName(i)); + if ( fun == h->function() ) // If this is the 'tied from' parameter, remember it + { + iPar = i; + } + else // Otherwise add it to the list of potential 'tyees' + { + fnNames << QString::fromStdString(m_compositeFunction->parameterName(i)); + } } } if (fnNames.empty() || iPar < 0) @@ -1351,7 +1353,8 @@ void FitPropertyBrowser::addTieToFunction() return; } - QString tieName = + bool ok; + QString tieName = QInputDialog::getItem(this, "MantidPlot - Fit", "Select function", fnNames,0,false,&ok); if (!ok) return; @@ -1822,36 +1825,36 @@ void FitPropertyBrowser::removeLogValue() void FitPropertyBrowser::validateGroupMember() { std::string wsName = workspaceName(); - Mantid::API::WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>( - Mantid::API::AnalysisDataService::Instance().retrieve(wsName) ); - if (!wsg) - { - m_groupMember = workspaceName(); - return; - } - std::vector<std::string> names = wsg->getNames(); - if (names.empty()) - { - m_groupMember = ""; - return; - } - if (std::find(names.begin(),names.end(),m_groupMember) != names.end()) - { - return; - } - if (names[0] == wsName) - { - if (names.size() > 1) - { - m_groupMember = names[1]; - } - else - { - m_groupMember = ""; - } - } - else - { - m_groupMember = names[0]; - } + Mantid::API::WorkspaceGroup_sptr wsg = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>( + Mantid::API::AnalysisDataService::Instance().retrieve(wsName) ); + if (!wsg) + { + m_groupMember = workspaceName(); + return; + } + std::vector<std::string> names = wsg->getNames(); + if (names.empty()) + { + m_groupMember = ""; + return; + } + if (std::find(names.begin(),names.end(),m_groupMember) != names.end()) + { + return; + } + if (names[0] == wsName) + { + if (names.size() > 1) + { + m_groupMember = names[1]; + } + else + { + m_groupMember = ""; + } + } + else + { + m_groupMember = names[0]; + } }