Skip to content

Commit

Permalink
refs #7541. Use candidate list.
Browse files Browse the repository at this point in the history
Construct a list of candidate workspace properties, then filter those to find a preferred one.
  • Loading branch information
OwenArnold committed Aug 28, 2013
1 parent 01c88ca commit 5de5a75
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions Code/Mantid/MantidQt/API/src/AlgorithmPropertiesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/AlgorithmProxy.h"
#include <list>
#include <algorithm>

using namespace Mantid::Kernel;
using Mantid::API::IWorkspaceProperty;
Expand Down Expand Up @@ -302,6 +304,12 @@ namespace API
this->hideOrDisableProperties();
}

bool isCalledInputWorkspace(PropertyWidget * const candidate)
{
Mantid::Kernel::Property const * const property = candidate->getProperty();
const std::string& propertyName = property->name();
return propertyName == "InputWorkspace";
}

//-------------------------------------------------------------------------------------------------
/** A slot to handle the replace workspace button click
Expand All @@ -312,6 +320,8 @@ namespace API
{
if (m_propWidgets.contains(propName))
{
typedef std::list<PropertyWidget*> CollectionOfPropertyWidget;
CollectionOfPropertyWidget candidateReplacementSources;
PropertyWidget * propWidget = m_propWidgets[propName];
if (propWidget)
{
Expand All @@ -328,19 +338,31 @@ namespace API
if (prop->direction() == Direction::Input)
{
// Input workspace property. Get the text typed in.
const std::string propName = otherWidget->getProperty()->name();
const std::string WSNAME = otherWidget->getValue().toStdString();
wsName = otherWidget->getValue();
if (!wsName.isEmpty())
{
propWidget->setValue(wsName);
break;
// Add the candidate to the list of candidates.
candidateReplacementSources.push_back(otherWidget);
}
}
}
}


// Choose from candidates, only do this if there are candidates to select from.
if(candidateReplacementSources.size() > 0)
{
CollectionOfPropertyWidget::iterator selectedIt = std::find_if(candidateReplacementSources.begin(), candidateReplacementSources.end(), isCalledInputWorkspace);
if(selectedIt != candidateReplacementSources.end())
{
// Use the InputWorkspace property called "InputWorkspace" as the source for the OutputWorkspace.
propWidget->setValue((*selectedIt)->getValue());
}
else
{
// Take the first candidate if there are none called "InputWorkspace" as the source for the OutputWorkspace.
propWidget->setValue(candidateReplacementSources.front()->getValue());
}
}
}
}

Expand Down

0 comments on commit 5de5a75

Please sign in to comment.