47 setWindowModality(Qt::WindowModal);
48 setWindowIcon(QIcon(
":/images/MantidIcon.ico"));
50 m_form->errorMessage->hide();
52 auto &factory = Mantid::API::FunctionFactory::Instance();
53 auto registeredFunctions = factory.getFunctionNamesGUI();
58 std::map<std::string, std::vector<std::string>> categories;
59 for (
const auto ®isteredFunction : registeredFunctions) {
60 auto f = factory.createFunction(registeredFunction);
61 std::vector<std::string> tempCategories = f->categories();
62 for (
size_t j = 0; j < tempCategories.size(); ++j) {
63 categories[tempCategories[boost::lexical_cast<int>(j)]].emplace_back(registeredFunction);
68 m_form->searchBox->completer()->setCompletionMode(QCompleter::PopupCompletion);
69 m_form->searchBox->completer()->setFilterMode(Qt::MatchContains);
75 connect(
m_form->searchBox, SIGNAL(editTextChanged(
const QString &)),
this, SLOT(
searchBoxChanged(
const QString &)));
82 connect(
m_form->fitTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *,
int)),
this,
84 m_form->fitTree->setToolTip(
"Select a function type and press OK.");
89 m_form->searchBox->setCurrentIndex(-1);
112 const std::map<std::string, std::vector<std::string>> &categoryFunctionsMap,
113 const std::vector<std::string> &restrictions) {
115 auto showCategory = [&restrictions](
const std::string &
name) {
116 if (restrictions.empty()) {
119 return (std::find(restrictions.begin(), restrictions.end(),
name) != restrictions.end());
124 QMap<QString, QTreeWidgetItem *> categories;
126 for (
const auto &entry : categoryFunctionsMap) {
128 QString categoryName = QString::fromStdString(entry.first);
129 QStringList subCategories = categoryName.split(
'\\');
130 if (!categories.contains(categoryName)) {
131 if (subCategories.size() == 1) {
132 if (showCategory(entry.first)) {
133 QTreeWidgetItem *catItem =
new QTreeWidgetItem(QStringList(categoryName));
134 categories.insert(categoryName, catItem);
135 m_form->fitTree->addTopLevelItem(catItem);
136 for (
const auto &function : entry.second) {
137 QTreeWidgetItem *fit =
new QTreeWidgetItem(catItem);
138 fit->setText(0, QString::fromStdString(function));
143 QString currentPath = subCategories[0];
144 QTreeWidgetItem *catItem =
nullptr;
145 int subCategoryNo = subCategories.size();
147 for (
int j = 0; j < subCategoryNo; ++j) {
148 if (showCategory(subCategories[j].toStdString())) {
153 for (
int j = 0; j < subCategoryNo; ++j) {
154 if (categories.contains(currentPath)) {
155 catItem = categories[currentPath];
157 QTreeWidgetItem *newCatItem =
new QTreeWidgetItem(QStringList(subCategories[j]));
158 categories.insert(currentPath, newCatItem);
160 m_form->fitTree->addTopLevelItem(newCatItem);
162 catItem->addChild(newCatItem);
164 catItem = newCatItem;
166 if (j != subCategoryNo - 1)
167 currentPath +=
"\\" + subCategories[j + 1];
170 for (
const auto &function : entry.second) {
171 QTreeWidgetItem *fit =
new QTreeWidgetItem(catItem);
172 fit->setText(0, QString::fromStdString(function));