11#include "boost/algorithm/string.hpp"
13#include <QApplication>
30 : QWidget(parent), m_tree(nullptr), m_findAlg(nullptr), m_execButton(nullptr),
32 auto *buttonLayout =
new QHBoxLayout();
35 m_tree->setHeaderLabel(
"Algorithms");
41 m_findAlg->completer()->setCompletionMode(QCompleter::PopupCompletion);
44 QSizePolicy expandHoriz;
45 expandHoriz.setHorizontalPolicy(QSizePolicy::Expanding);
58 QVBoxLayout *layout =
new QVBoxLayout(
this);
60 layout->addLayout(buttonLayout);
98 if (!alg.name.isEmpty()) {
106 int i =
m_findAlg->findText(text, Qt::MatchFixedString);
110 m_tree->blockSignals(
true);
111 m_tree->setCurrentIndex(QModelIndex());
112 m_tree->blockSignals(
false);
137 if (alg.
name.isEmpty())
153 m_tree->blockSignals(
true);
154 m_tree->setCurrentIndex(QModelIndex());
155 m_tree->blockSignals(
false);
198 auto isCategoryName = [](
const QTreeWidgetItem *item) {
199 return (item->childCount() != 0 && !item->text(0).contains(
" v."));
203 if (items.size() > 0 && !isCategoryName(items[0])) {
204 QString str = items[0]->text(0);
205 QStringList lst = str.split(
" v.");
215 if (e->button() == Qt::LeftButton) {
216 if (!itemAt(e->pos()))
217 selectionModel()->clear();
221 QTreeWidget::mousePressEvent(e);
227 if (!(e->buttons() & Qt::LeftButton))
229 if ((e->pos() -
m_dragStartPosition).manhattanLength() < QApplication::startDragDistance())
233 QDrag *drag =
new QDrag(
this);
234 auto *mimeData =
new QMimeData;
236 mimeData->setText(
"Algorithm");
237 drag->setMimeData(mimeData);
239 Qt::DropAction dropAction = drag->exec(Qt::CopyAction | Qt::MoveAction);
247 if (!alg.name.isEmpty()) {
252 QTreeWidget::mouseDoubleClickEvent(e);
260 using AlgNamesType = std::vector<AlgorithmDescriptor>;
264 sort(names.begin(), names.end(), AlgorithmDescriptorLess);
266 QMap<QString, QTreeWidgetItem *> categories;
267 QMap<QString, QTreeWidgetItem *> algorithms;
272 for (AlgNamesType::const_iterator i = names.begin(); i != names.end(); ++i) {
273 QString algName = QString::fromStdString(i->name);
274 QString catName = QString::fromStdString(i->category);
275 QStringList subCats = catName.split(
'\\');
276 if (!categories.contains(catName)) {
277 if (subCats.size() == 1) {
278 QTreeWidgetItem *catItem =
new QTreeWidgetItem(QStringList(catName));
279 categories.insert(catName, catItem);
280 this->addTopLevelItem(catItem);
282 QString cn = subCats[0];
283 QTreeWidgetItem *catItem =
nullptr;
284 int n = subCats.size();
285 for (
int j = 0; j <
n; j++) {
286 if (categories.contains(cn)) {
287 catItem = categories[cn];
289 QTreeWidgetItem *newCatItem =
new QTreeWidgetItem(QStringList(subCats[j]));
290 categories.insert(cn, newCatItem);
292 this->addTopLevelItem(newCatItem);
294 catItem->addChild(newCatItem);
296 catItem = newCatItem;
299 cn +=
"\\" + subCats[j + 1];
304 QTreeWidgetItem *algItem =
new QTreeWidgetItem(QStringList(algName +
" v." + QString::number(i->version)));
305 QString cat_algName = catName + algName;
306 if (!algorithms.contains(cat_algName)) {
307 algorithms.insert(cat_algName, algItem);
308 categories[catName]->addChild(algItem);
310 algorithms[cat_algName]->addChild(algItem);
320 if (e->key() == Qt::Key_Return) {
324 QComboBox::keyPressEvent(e);
335 sort(names.begin(), names.end(), AlgorithmDescriptorNameLess);
338 std::string prevName =
"";
339 for (AlgNamesType::const_iterator i = names.begin(); i != names.end(); ++i) {
340 if (i->name != prevName)
341 this->
addItem(QString::fromStdString(i->name));
344 this->setCurrentIndex(-1);
350 for (AlgNamesType::const_iterator i = algNamesList.begin(); i != algNamesList.end(); ++i) {
352 if ((!i->alias.empty()) && (!boost::iequals(i->alias, i->name))) {
354 newAlias.
name = i->alias +
" [" + i->name +
"]";
355 aliasList.emplace_back(newAlias);
359 algNamesList.reserve(algNamesList.size() + aliasList.size());
360 algNamesList.insert(algNamesList.end(), aliasList.begin(), aliasList.end());
365 QString retVal = text;
366 int foundOpen = text.indexOf(
"[");
367 if (foundOpen != -1) {
368 int foundClose = text.lastIndexOf(
"]");
369 if (foundClose != -1)
370 retVal = text.mid(foundOpen + 1, foundClose - foundOpen - 1);
379 QString typedText = this->currentText().trimmed();
380 if (!typedText.isEmpty())
383 int matchedIndex = this->findText(typedText, Qt::MatchStartsWith);
384 if (matchedIndex > -1) {
385 typedText = this->itemText(matchedIndex);
void addItem(WorkspaceGroup &self, const std::string &name)
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
const Poco::AutoPtr< Mantid::Kernel::DynamicFactory< Algorithm >::UpdateNotification > & AlgorithmFactoryUpdateNotification_ptr
Structure uniquely describing an algorithm with its name, category and version.
std::string category
category
std::string name
Algorithm Name.