Skip to content
Snippets Groups Projects
Commit 25cd99ee authored by Nick Draper's avatar Nick Draper
Browse files

allowed aliases into the alg search box eg "Subtract [Minus]"

re #8120
parent 5da64086
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ namespace API { ...@@ -18,6 +18,7 @@ namespace API {
/// version. /// version.
struct Algorithm_descriptor { struct Algorithm_descriptor {
std::string name; ///< name std::string name; ///< name
std::string alias; ///< alias
std::string category; ///< category std::string category; ///< category
int version; ///< version int version; ///< version
}; };
......
...@@ -350,6 +350,7 @@ AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const { ...@@ -350,6 +350,7 @@ AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const {
boost::shared_ptr<IAlgorithm> alg = create(desc.name, desc.version); boost::shared_ptr<IAlgorithm> alg = create(desc.name, desc.version);
std::vector<std::string> categories = alg->categories(); std::vector<std::string> categories = alg->categories();
desc.alias = alg->alias();
// For each category // For each category
auto itCategoriesEnd = categories.end(); auto itCategoriesEnd = categories.end();
......
...@@ -25,7 +25,7 @@ public: ...@@ -25,7 +25,7 @@ public:
{ {
Mantid::Kernel::Instantiator<ToyAlgorithmTwo, Algorithm>* newTwo = new Mantid::Kernel::Instantiator<ToyAlgorithmTwo, Algorithm>; Mantid::Kernel::Instantiator<ToyAlgorithmTwo, Algorithm>* newTwo = new Mantid::Kernel::Instantiator<ToyAlgorithmTwo, Algorithm>;
//get the nubmer of algorithms it already has //get the number of algorithms it already has
std::vector<std::string> keys = AlgorithmFactory::Instance().getKeys(); std::vector<std::string> keys = AlgorithmFactory::Instance().getKeys();
size_t noOfAlgs = keys.size(); size_t noOfAlgs = keys.size();
...@@ -34,7 +34,7 @@ public: ...@@ -34,7 +34,7 @@ public:
TS_ASSERT_THROWS_ANYTHING(AlgorithmFactory::Instance().subscribe<ToyAlgorithm>()); TS_ASSERT_THROWS_ANYTHING(AlgorithmFactory::Instance().subscribe<ToyAlgorithm>());
//get the nubmer of algorithms it has now //get the number of algorithms it has now
keys = AlgorithmFactory::Instance().getKeys(); keys = AlgorithmFactory::Instance().getKeys();
size_t noOfAlgsAfter = keys.size(); size_t noOfAlgsAfter = keys.size();
TS_ASSERT_EQUALS(noOfAlgsAfter, noOfAlgs + 2); TS_ASSERT_EQUALS(noOfAlgsAfter, noOfAlgs + 2);
...@@ -160,7 +160,10 @@ public: ...@@ -160,7 +160,10 @@ public:
bool foundAlg = false; bool foundAlg = false;
while (descItr != descriptors.end() && !foundAlg) while (descItr != descriptors.end() && !foundAlg)
{ {
foundAlg = ("Cat" == descItr->category)&&("ToyAlgorithm" == descItr->name)&&(1 == descItr->version); foundAlg = ("Cat" == descItr->category) &&
("ToyAlgorithm" == descItr->name) &&
("Dog" == descItr->alias) &&
(1 == descItr->version);
descItr++; descItr++;
} }
TS_ASSERT(foundAlg); TS_ASSERT(foundAlg);
...@@ -170,7 +173,7 @@ public: ...@@ -170,7 +173,7 @@ public:
TS_ASSERT_THROWS_NOTHING(descriptors = AlgorithmFactory::Instance().getDescriptors(true)); TS_ASSERT_THROWS_NOTHING(descriptors = AlgorithmFactory::Instance().getDescriptors(true));
TS_ASSERT_EQUALS(noOfAlgs - 1, descriptors.size()); TS_ASSERT_EQUALS(noOfAlgs - 1, descriptors.size());
} }
void testGetCategories() void testGetCategories()
{ {
......
...@@ -5,13 +5,20 @@ ...@@ -5,13 +5,20 @@
#include "MantidAPI/AlgorithmFactory.h" #include "MantidAPI/AlgorithmFactory.h"
#include "WidgetDllOption.h" #include "WidgetDllOption.h"
#include <vector>
#include <Poco/NObserver.h> #include <Poco/NObserver.h>
#include <QtGui> #include <QtGui>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Forward declaration // Forward declaration
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Mantid
{
namespace API
{
struct Algorithm_descriptor;
}
}
namespace MantidQt namespace MantidQt
{ {
namespace MantidWidgets namespace MantidWidgets
...@@ -113,6 +120,10 @@ signals: ...@@ -113,6 +120,10 @@ signals:
protected: protected:
void keyPressEvent(QKeyEvent *e); void keyPressEvent(QKeyEvent *e);
private:
typedef std::vector<Mantid::API::Algorithm_descriptor> AlgNamesType;
void addAliases(AlgNamesType& algNamesList);
QString stripAlias(const QString& text) const;
}; };
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include "MantidKernel/System.h" #include "MantidKernel/System.h"
#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AlgorithmManager.h"
#include "boost/algorithm/string.hpp"
using namespace Mantid::Kernel; using namespace Mantid::Kernel;
using namespace Mantid::API; using namespace Mantid::API;
...@@ -55,7 +57,7 @@ namespace MantidWidgets ...@@ -55,7 +57,7 @@ namespace MantidWidgets
layout->addLayout(buttonLayout); layout->addLayout(buttonLayout);
layout->addWidget(m_tree); layout->addWidget(m_tree);
// The poco notification will be dispacted from the callers thread but we need to // The poco notification will be dispatched from the callers thread but we need to
// make sure the updates to the widgets happen on the GUI thread. Dispatching // make sure the updates to the widgets happen on the GUI thread. Dispatching
// through a Qt signal will make sure it is in the correct thread. // through a Qt signal will make sure it is in the correct thread.
AlgorithmFactory::Instance().notificationCenter.addObserver(m_updateObserver); AlgorithmFactory::Instance().notificationCenter.addObserver(m_updateObserver);
...@@ -322,7 +324,7 @@ namespace MantidWidgets ...@@ -322,7 +324,7 @@ namespace MantidWidgets
else else
{ {
QString cn = subCats[0]; QString cn = subCats[0];
QTreeWidgetItem *catItem = 0; QTreeWidgetItem *catItem = NULL;
int n = subCats.size(); int n = subCats.size();
for(int j=0;j<n;j++) for(int j=0;j<n;j++)
{ {
...@@ -377,13 +379,13 @@ namespace MantidWidgets ...@@ -377,13 +379,13 @@ namespace MantidWidgets
QComboBox::keyPressEvent(e); QComboBox::keyPressEvent(e);
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
/** Update the list of algos in the combo box */ /** Update the list of algos in the combo box */
void FindAlgComboBox::update() void FindAlgComboBox::update()
{ {
typedef std::vector<Algorithm_descriptor> AlgNamesType;
//include hidden categories in the combo list box //include hidden categories in the combo list box
AlgNamesType names = AlgorithmFactory::Instance().getDescriptors(true); AlgNamesType names = AlgorithmFactory::Instance().getDescriptors(true);
addAliases(names);
// sort by algorithm names only to fill this combobox // sort by algorithm names only to fill this combobox
sort(names.begin(),names.end(),Algorithm_descriptor_name_less); sort(names.begin(),names.end(),Algorithm_descriptor_name_less);
...@@ -399,6 +401,38 @@ namespace MantidWidgets ...@@ -399,6 +401,38 @@ namespace MantidWidgets
this->setCurrentIndex(-1); this->setCurrentIndex(-1);
} }
/** Adds alias entries to the list of algorithms */
void FindAlgComboBox::addAliases(AlgNamesType& algNamesList)
{
AlgNamesType aliasList;
for(AlgNamesType::const_iterator i=algNamesList.begin();i!=algNamesList.end();++i)
{
//the alias is not empty and is not just different by case from the name
if ((!i->alias.empty()) && (!boost::iequals(i->alias,i->name)))
{
Algorithm_descriptor newAlias(*i);
newAlias.name = i->alias + " [" + i->name + "]";
aliasList.push_back(newAlias);
}
}
//add them to the list - unsorted
algNamesList.reserve( algNamesList.size() + aliasList.size() );
algNamesList.insert( algNamesList.end(), aliasList.begin(), aliasList.end() );
}
/** if a string is for an alias convert it to the algorithm name */
QString FindAlgComboBox::stripAlias(const QString& text) const
{
QString retVal = text;
int foundOpen = text.indexOf("[");
if (foundOpen!=-1){
int foundClose=text.lastIndexOf("]");
if (foundClose!=-1)
retVal = text.mid(foundOpen+1, foundClose-foundOpen-1);
}
return retVal;
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
/** Return the selected algorithm */ /** Return the selected algorithm */
...@@ -413,6 +447,7 @@ namespace MantidWidgets ...@@ -413,6 +447,7 @@ namespace MantidWidgets
if (matchedIndex > -1) if (matchedIndex > -1)
{ {
typedText = this->itemText(matchedIndex); //text in the combobox at the matched index typedText = this->itemText(matchedIndex); //text in the combobox at the matched index
typedText = stripAlias(typedText);
} }
} }
//set return values //set return values
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment