11#include "ui_SelectFunctionDialog.h"
17#include <boost/lexical_cast.hpp>
19#include <QButtonGroup>
47 setWindowModality(Qt::WindowModal);
48 setWindowIcon(QIcon(
":/images/MantidIcon.ico"));
50 m_form->errorMessage->hide();
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);
71 connect(
m_form->searchBox, SIGNAL(editTextChanged(
const QString &)),
this, SLOT(
searchBoxChanged(
const QString &)));
78 connect(
m_form->fitTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *,
int)),
this,
80 m_form->fitTree->setToolTip(
"Select a function type and press OK.");
85 m_form->searchBox->setCurrentIndex(-1);
98 const std::map<std::string, std::vector<std::string>> &categoryFunctionsMap,
99 const std::vector<std::string> &restrictions) {
101 auto showCategory = [&restrictions](
const std::string &name) {
102 if (restrictions.empty()) {
105 return (std::find(restrictions.begin(), restrictions.end(), name) != restrictions.end());
110 QMap<QString, QTreeWidgetItem *> categories;
112 for (
const auto &entry : categoryFunctionsMap) {
114 QString categoryName = QString::fromStdString(entry.first);
115 QStringList subCategories = categoryName.split(
'\\');
116 if (!categories.contains(categoryName)) {
117 if (subCategories.size() == 1) {
118 if (showCategory(entry.first)) {
119 QTreeWidgetItem *catItem =
new QTreeWidgetItem(QStringList(categoryName));
120 categories.insert(categoryName, catItem);
121 m_form->fitTree->addTopLevelItem(catItem);
122 for (
const auto &function : entry.second) {
123 QTreeWidgetItem *fit =
new QTreeWidgetItem(catItem);
124 fit->setText(0, QString::fromStdString(function));
125 m_form->searchBox->addItem(QString::fromStdString(function));
130 QString currentPath = subCategories[0];
131 QTreeWidgetItem *catItem =
nullptr;
132 int subCategoryNo = subCategories.size();
134 for (
int j = 0; j < subCategoryNo; ++j) {
135 if (showCategory(subCategories[j].toStdString())) {
140 for (
int j = 0; j < subCategoryNo; ++j) {
141 if (categories.contains(currentPath)) {
142 catItem = categories[currentPath];
144 QTreeWidgetItem *newCatItem =
new QTreeWidgetItem(QStringList(subCategories[j]));
145 categories.insert(currentPath, newCatItem);
147 m_form->fitTree->addTopLevelItem(newCatItem);
149 catItem->addChild(newCatItem);
151 catItem = newCatItem;
153 if (j != subCategoryNo - 1)
154 currentPath +=
"\\" + subCategories[j + 1];
157 for (
const auto &function : entry.second) {
158 QTreeWidgetItem *fit =
new QTreeWidgetItem(catItem);
159 fit->setText(0, QString::fromStdString(function));
160 m_form->searchBox->addItem(QString::fromStdString(function));
177 auto const numberOfTopLevelItems =
m_form->fitTree->topLevelItemCount();
178 if (numberOfTopLevelItems > 0) {
179 auto const firstItem =
m_form->fitTree->topLevelItem(0);
180 auto const itemHeight =
m_form->fitTree->visualItemRect(firstItem).height();
181 m_form->fitTree->setMinimumHeight(itemHeight * numberOfTopLevelItems);
189 const auto searchText =
m_form->searchBox->currentText();
191 if (items.size() == 1 && items[0]->childCount() == 0) {
192 return items[0]->text(0);
193 }
else if (
m_form->searchBox->findText(searchText) >= 0) {
205 if (text.isEmpty()) {
208 m_form->fitTree->setCurrentIndex(QModelIndex());
210 const auto index =
m_form->searchBox->findText(text);
216 if (item->childCount() == 0)
222 if (func.isEmpty()) {
223 m_form->errorMessage->setText(QString(
"<span style='color:red'> Function not found</span> "));
224 m_form->errorMessage->show();
226 m_form->errorMessage->hide();
232 m_form->errorMessage->hide();
238 if (!function.isEmpty()) {
std::map< DeltaEMode::Type, std::string > index
static void showFitFunction(const std::string &name=std::string())
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...