Mantid
Loading...
Searching...
No Matches
WorkspaceTreeWidget.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
22
24#include "MantidAPI/Axis.h"
31
32#include <Poco/Path.h>
33
34#include <memory>
35
36#include <QFileDialog>
37#include <QKeyEvent>
38#include <QMainWindow>
39#include <QMenu>
40#include <QMessageBox>
41#include <QPushButton>
42#include <QSignalMapper>
43
44using namespace MantidQt::API;
45using namespace Mantid::API;
46using namespace Mantid::Kernel;
47
48namespace {
50Mantid::Kernel::Logger docklog("MantidDockWidget");
51
52WorkspaceIcons WORKSPACE_ICONS = WorkspaceIcons();
53} // namespace
54
56
58 : QWidget(parent), m_mantidDisplayModel(mdb), m_viewOnly(viewOnly), m_updateCount(0), m_treeUpdating(false),
59 m_promptDelete(false), m_saveFileType(SaveFileType::Nexus), m_sortCriteria(SortCriteria::ByName),
60 m_sortDirection(SortDirection::Ascending), m_mutex(QMutex::Recursive) {
61 setObjectName("exploreMantid"); // this is needed for QMainWindow::restoreState()
62 m_saveMenu = new QMenu(this);
63
65
67
68 // Dialog box used for user to specify folder to save multiple workspaces into
69 m_saveFolderDialog = new QFileDialog(this);
70 m_saveFolderDialog->setFileMode(QFileDialog::Directory);
71 m_saveFolderDialog->setOption(QFileDialog::ShowDirsOnly);
72
73 // To be able to use them in queued signals they need to be registered
74 static bool registered_addtional_types = false;
75 if (!registered_addtional_types) {
76 registered_addtional_types = true;
77 qRegisterMetaType<TopLevelItems>();
78 }
79
80 // SET UP SORT
83
85
86 m_tree->setDragEnabled(true);
87
88 auto presenter = std::make_shared<WorkspacePresenter>(this);
89 m_presenter = std::dynamic_pointer_cast<ViewNotifiable>(presenter);
90 presenter->init();
91
92 if (m_viewOnly)
94}
95
97
102void WorkspaceTreeWidget::dropEvent(QDropEvent *de) { m_tree->dropEvent(de); }
103
106 m_tree->setHeaderLabel("Workspaces");
107
108 auto *buttonLayout = new FlowLayout();
109 m_loadButton = new QPushButton("Load");
110 m_loadButton->setToolTip("Load a file or live data");
111 m_saveButton = new QPushButton("Save");
112 m_saveButton->setToolTip("Save the selected workspaces");
113 m_deleteButton = new QPushButton("Delete");
114 m_deleteButton->setToolTip("Delete the selected workspaces");
115 m_clearButton = new QPushButton("Clear");
116 m_clearButton->setToolTip("Delete all workspaces");
117 m_groupButton = new QPushButton("Group");
118 m_groupButton->setToolTip("Group together two or more selected workspaces");
119 m_sortButton = new QPushButton("Sort");
120 m_sortButton->setToolTip("Sort all workspaces by name, size, or the last time they were modified");
121
122 m_groupButton->setEnabled(false);
123 m_deleteButton->setEnabled(false);
124 m_clearButton->setEnabled(false);
125 m_saveButton->setEnabled(false);
126
127 buttonLayout->addWidget(m_loadButton);
128 buttonLayout->addWidget(m_deleteButton);
129 buttonLayout->addWidget(m_clearButton);
130 buttonLayout->addWidget(m_groupButton);
131 buttonLayout->addWidget(m_sortButton);
132 buttonLayout->addWidget(m_saveButton);
133
135 m_workspaceFilter->setPlaceholderText("Filter Workspaces");
136 m_workspaceFilter->setToolTip("Type here to filter the workspaces");
137
138 auto *layout = new QVBoxLayout();
139 layout->setMargin(0);
140 layout->addLayout(buttonLayout);
141 layout->addWidget(m_workspaceFilter);
142 layout->addWidget(m_tree);
143 this->setLayout(layout);
144}
145
147 m_loadMenu = new QMenu(this);
148
149 QAction *loadFileAction = new QAction("File", this);
150 QAction *liveDataAction = new QAction("Live Data", this);
151 connect(loadFileAction, SIGNAL(triggered()), this, SLOT(onClickLoad()));
152 connect(liveDataAction, SIGNAL(triggered()), this, SLOT(onClickLiveData()));
153
154 m_loadMenu->addAction(loadFileAction);
155 m_loadMenu->addAction(liveDataAction);
156 m_loadButton->setMenu(m_loadMenu);
157}
158
160 connect(m_workspaceFilter, SIGNAL(textChanged(const QString &)), this, SLOT(filterWorkspaceTree(const QString &)));
161 connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(onClickDeleteWorkspaces()));
162 connect(m_clearButton, SIGNAL(clicked()), this, SLOT(onClickClearWorkspaces()));
163 connect(m_tree, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(clickedWorkspace(QTreeWidgetItem *, int)));
164 connect(m_tree, SIGNAL(itemSelectionChanged()), this, SLOT(workspaceSelected()));
165 connect(m_groupButton, SIGNAL(clicked()), this, SLOT(onClickGroupButton()));
166
167 m_tree->setContextMenuPolicy(Qt::CustomContextMenu);
168 connect(m_tree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(popupMenu(const QPoint &)));
169 connect(this, SIGNAL(signalUpdateTree(const TopLevelItems &)), this, SLOT(handleUpdateTree(const TopLevelItems &)),
170 Qt::QueuedConnection);
171
172 connect(this, SIGNAL(signalClearView()), this, SLOT(handleClearView()), Qt::QueuedConnection);
173 connect(m_tree, SIGNAL(itemSelectionChanged()), this, SLOT(onTreeSelectionChanged()));
174 connect(m_tree, SIGNAL(itemExpanded(QTreeWidgetItem *)), this, SLOT(populateChildData(QTreeWidgetItem *)));
175}
176
183void WorkspaceTreeWidget::setTreeUpdating(const bool state) { m_treeUpdating = state; }
184
186
188 return std::dynamic_pointer_cast<WorkspacePresenter>(m_presenter);
189}
190
195 auto items = m_tree->selectedItems();
196 StringList names;
197 names.reserve(static_cast<size_t>(items.size()));
198 std::transform(items.cbegin(), items.cend(), std::back_inserter(names),
199 [](auto const &item) { return item->text(0).toStdString(); });
200
201 return names;
202}
203
205 auto items = m_tree->selectedItems();
206 QStringList names;
207
208 for (auto &item : items) {
209 names.append(item->text(0));
210 }
211 return names;
212}
213
218 auto items = m_tree->selectedItems();
219 auto data = items[0]->data(0, Qt::UserRole).value<Workspace_sptr>();
220
221 return data;
222}
223
224bool WorkspaceTreeWidget::askUserYesNo(const std::string &caption, const std::string &message) const {
225 return QMessageBox::question(parentWidget(), QString::fromStdString(caption), QString::fromStdString(message),
226 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes;
227}
228
229void WorkspaceTreeWidget::showCriticalUserMessage(const std::string &caption, const std::string &message) const {
230 QMessageBox::critical(parentWidget(), QString::fromStdString(caption), QString::fromStdString(message));
231}
232
234 QObject *sender = QObject::sender();
235 const auto *dlg = reinterpret_cast<MantidQt::API::AlgorithmDialog *>(sender);
236 if (!dlg)
237 return; // should never happen
238
239 QString fn = MantidQt::API::AlgorithmInputHistory::Instance().previousInput("Load", "Filename");
240
242}
243
245 QMetaObject::invokeMethod(dynamic_cast<QObject *>(m_mantidDisplayModel), "showAlgorithmDialog", Qt::QueuedConnection,
246 Q_ARG(QString, "Load"));
247}
248
250 QMetaObject::invokeMethod(dynamic_cast<QObject *>(m_mantidDisplayModel), "showAlgorithmDialog", Qt::QueuedConnection,
251 Q_ARG(QString, "StartLiveData"));
252}
253
255
257 QStringList names;
258
259 for (const auto &ws : wsNames)
260 names.append(QString::fromStdString(ws));
261
263}
264
272void WorkspaceTreeWidget::recordWorkspaceRename(const std::string &oldName, const std::string &newName) {
273 QString qs_oldName = QString::fromStdString(oldName);
274 QString qs_newName = QString::fromStdString(newName);
275
276 QMutexLocker renameMapLock(&m_mutex);
277 // check if old_name has been recently a new name
278 QList<QString> oldNames = m_renameMap.keys(qs_oldName);
279 // non-empty list of oldNames become new_name
280 if (!oldNames.isEmpty()) {
281 for (const auto &name : oldNames)
282 m_renameMap[name] = qs_newName;
283 } else {
284 // record a new rename pair
285 m_renameMap[qs_oldName] = qs_newName;
286 }
287}
288
290
292
294
296 return askUserYesNo("Delete Workspaces", "Are you sure you want to delete the selected Workspaces?\n\nThis prompt "
297 "can be disabled from:\nFile->Settings->General");
298}
299
301 QStringList names;
302 for (const auto &ws : wsNames)
303 names.append(QString::fromStdString(ws));
305}
306
308
313
318
323
328
333
335 static int counter = 1;
336
337 item->setSortPos(counter);
338
339 counter++;
340}
341
343
345
347 if (isTreeUpdating())
348 return;
350 m_tree->setSortOrder(direction == SortDirection::Ascending ? Qt::AscendingOrder : Qt::DescendingOrder);
351 m_tree->sort();
352}
353
355 switch (criteria) {
362 default:
363 // Handle if someone adds a new Enum and it falls through by defaulting to
364 // name
366 }
367}
368
372
374 const QAction *sendingAction = dynamic_cast<QAction *>(sender());
375 if (!sendingAction)
376 return;
377
378 QString actionName = sendingAction->text();
379
380 if (actionName.compare("Nexus") == 0)
382 else if (actionName.compare("ASCII") == 0)
384
385 auto selectedNames = getSelectedWorkspaceNames();
386
387 if (selectedNames.size() > 1) {
388 // Save multiple workspaces
389 saveWorkspaces(selectedNames);
390 } else if (selectedNames.size() == 1) {
391 // Save single workspace
393 }
394}
395
397
398void WorkspaceTreeWidget::saveWorkspace(const std::string &wsName, SaveFileType type) {
400 if (!wsName.empty()) {
401 presets["InputWorkspace"] = QString::fromStdString(wsName);
402 }
403 int version = -1;
404 std::string algorithmName;
405
406 switch (type) {
408 algorithmName = "SaveNexus";
409 break;
411 algorithmName = "SaveAscii";
412 break;
413 }
414
415 m_mantidDisplayModel->showAlgorithmDialog(QString::fromStdString(algorithmName), presets, nullptr, version);
416}
417
419 QList<QTreeWidgetItem *> items = m_tree->selectedItems();
420 if (items.size() < 2)
421 return;
422
423 m_saveFolderDialog->setWindowTitle("Select save folder");
424 m_saveFolderDialog->setLabelText(QFileDialog::Accept, "Select");
425
426 auto res = m_saveFolderDialog->exec();
427 if (res != QFileDialog::Accepted)
428 return;
429
430 auto folder = m_saveFolderDialog->selectedFiles()[0].toStdString();
431
432 std::string algorithmName;
433 std::string fileExtension;
434
435 switch (m_saveFileType) {
437 algorithmName = "SaveAscii";
438 fileExtension = ".dat";
439 break;
441 default:
442 algorithmName = "SaveNexus";
443 fileExtension = ".nxs";
444 break;
445 }
446
447 IAlgorithm_sptr saveAlg = AlgorithmManager::Instance().create(algorithmName);
448 saveAlg->initialize();
449
450 for (auto &wsName : wsNames) {
451 std::string filename = folder + "/" + wsName + fileExtension;
452 try {
453 saveAlg->setProperty("InputWorkspace", wsName);
454 saveAlg->setProperty("Filename", filename);
455 saveAlg->execute();
456 } catch (std::exception &ex) {
457 docklog.error() << "Error saving workspace " << wsName << ": " << ex.what() << '\n';
458 }
459 }
460}
461
462std::string WorkspaceTreeWidget::getFilterText() const { return m_workspaceFilter->text().toStdString(); }
463
464void WorkspaceTreeWidget::filterWorkspaces(const std::string &filterText) {
465 const QString text = QString::fromStdString(filterText).trimmed();
466 QRegExp filterRegEx(text, Qt::CaseInsensitive);
467
468 // show all items
469 QTreeWidgetItemIterator unhideIter(m_tree);
470 while (*unhideIter) {
471 (*unhideIter)->setHidden(false);
472 ++unhideIter;
473 }
474
475 int hiddenCount = 0;
476 if (!text.isEmpty()) {
477 QList<QTreeWidgetItem *> visibleGroups;
478 // Loop over everything (currently loaded) and top level
479 // find out what is already expanded
480 QStringList expanded;
481 int n = m_tree->topLevelItemCount();
482 for (int i = 0; i < n; ++i) {
483 auto item = m_tree->topLevelItem(i);
484 if (item->isExpanded()) {
485 expanded << item->text(0);
486 } else {
487 // expand everything that is at the top level (as we lazy load this is
488 // required)
489 item->setExpanded(true);
490 }
491 }
492
493 // filter based on the string
494 QTreeWidgetItemIterator it(m_tree, QTreeWidgetItemIterator::All);
495 while (*it) {
496 QTreeWidgetItem *item = (*it);
497 QVariant userData = item->data(0, Qt::UserRole);
498
499 if (!userData.isNull()) {
500 Workspace_sptr workspace = userData.value<Workspace_sptr>();
501 if (workspace) {
502 // I am a workspace
503 if (item->text(0).contains(filterRegEx)) {
504 // my name does match the filter
505 if (workspace->isGroup()) {
506 // I am a group, I will want my children to be visible
507 // but I cannot do that until this iterator has finished
508 // store this pointer in a list for processing later
509 visibleGroups.append(item);
510 item->setHidden(false);
511 }
512
513 if (item->parent() == nullptr) {
514 // No parent, I am a top level workspace - show me
515 item->setHidden(false);
516 } else {
517 // I am a child workspace of a group
518 // I match, so I want my parent to remain visible as well.
519 item->setHidden(false);
520 if (item->parent()->isHidden()) {
521 // I was previously hidden, show me and set to be expanded
522 --hiddenCount;
523 item->parent()->setHidden(false);
524 expanded << item->parent()->text(0);
525 }
526 }
527 } else {
528 // my name does not match the filter - hide me
529 item->setHidden(true);
530 ++hiddenCount;
531 }
532 }
533 }
534 ++it;
535 }
536
537 // make children of visible groups visible
538 for (auto group : visibleGroups) {
539 for (int i = 0; i < group->childCount(); i++) {
540 QTreeWidgetItem *child = group->child(i);
541 if (child->isHidden()) {
542 // I was previously hidden, show me
543 --hiddenCount;
544 child->setHidden(false);
545 }
546 }
547 }
548
549 // set the expanded state
550 for (int i = 0; i < n; ++i) {
551 auto item = m_tree->topLevelItem(i);
552 item->setExpanded(expanded.contains(item->text(0)));
553 }
554 }
555
556 // display a message if items are hidden
557 if (hiddenCount > 0) {
558 QString headerString = QString("Workspaces (%1 filtered)").arg(QString::number(hiddenCount));
559 m_tree->headerItem()->setText(0, headerString);
560 } else {
561 m_tree->headerItem()->setText(0, "Workspaces");
562 }
563}
564
570void WorkspaceTreeWidget::setItemIcon(QTreeWidgetItem *item, const std::string &wsID) {
571 try {
572 item->setIcon(0, QIcon(WORKSPACE_ICONS.getIcon(wsID)));
573 } catch (std::runtime_error &) {
574 docklog.warning() << "Cannot find icon for workspace ID '" << wsID << "'\n";
575 }
576}
577
582 m_showData = new QAction(tr("Show Data"), this);
583 connect(m_showData, SIGNAL(triggered()), this, SLOT(onClickShowData()));
584
585 m_showInst = new QAction(tr("Show Instrument"), this);
586 connect(m_showInst, SIGNAL(triggered()), this, SLOT(onClickShowInstrument()));
587
588 m_plotSpec = new QAction(tr("Plot Spectrum..."), this);
589 connect(m_plotSpec, SIGNAL(triggered()), this, SLOT(onClickPlotSpectra()));
590
591 m_plotSpecErr = new QAction(tr("Plot Spectrum with Errors..."), this);
592 connect(m_plotSpecErr, SIGNAL(triggered()), this, SLOT(onClickPlotSpectraErr()));
593
594 m_plotAdvanced = new QAction(tr("Plot Advanced..."), this);
595 connect(m_plotAdvanced, SIGNAL(triggered()), this, SLOT(onClickPlotAdvanced()));
596
597 m_colorFill = new QAction(tr("Color Fill Plot"), this);
598 connect(m_colorFill, SIGNAL(triggered()), this, SLOT(onClickDrawColorFillPlot()));
599
600 m_showDetectors = new QAction(tr("Show Detectors"), this);
601 connect(m_showDetectors, SIGNAL(triggered()), this, SLOT(onClickShowDetectorTable()));
602
603 m_showBoxData = new QAction(tr("Show Box Data Table"), this);
604 connect(m_showBoxData, SIGNAL(triggered()), this, SLOT(onClickShowBoxData()));
605
606 m_showMDPlot = new QAction(tr("Plot MD"), this);
607 connect(m_showMDPlot, SIGNAL(triggered()), this, SLOT(onClickShowMDPlot()));
608
609 m_showListData = new QAction(tr("List Data"), this);
610 connect(m_showListData, SIGNAL(triggered()), this, SLOT(onClickShowListData()));
611
612 m_showSpectrumViewer = new QAction(tr("Show Spectrum Viewer"), this);
613 connect(m_showSpectrumViewer, SIGNAL(triggered()), this, SLOT(onClickShowSpectrumViewer()));
614
615 m_showSliceViewer = new QAction(tr("Show Slice Viewer"), this);
616 {
617 QIcon icon;
618 icon.addFile(QString::fromUtf8(":/SliceViewer/icons/SliceViewerWindow_icon.png"), QSize(), QIcon::Normal,
619 QIcon::Off);
620 m_showSliceViewer->setIcon(icon);
621 }
622 connect(m_showSliceViewer, SIGNAL(triggered()), this, SLOT(onClickShowSliceViewer()));
623
624 m_showLogs = new QAction(tr("Sample Logs..."), this);
625 connect(m_showLogs, SIGNAL(triggered()), this, SLOT(onClickShowFileLog()));
626
627 m_showSampleMaterial = new QAction(tr("Sample Material..."), this);
628 connect(m_showSampleMaterial, SIGNAL(triggered()), this, SLOT(onClickShowSampleMaterial()));
629
630 m_showHist = new QAction(tr("Show History"), this);
631 connect(m_showHist, SIGNAL(triggered()), this, SLOT(onClickShowAlgHistory()));
632
633 m_saveNexus = new QAction(tr("Save NeXus"), this);
634 connect(m_saveNexus, SIGNAL(triggered()), this, SLOT(onClickSaveNexusWorkspace()));
635
636 m_rename = new QAction(tr("Rename"), this);
637 connect(m_rename, SIGNAL(triggered()), this, SLOT(renameWorkspace()));
638
639 m_delete = new QAction(tr("Delete"), this);
640 connect(m_delete, SIGNAL(triggered()), this, SLOT(onClickDeleteWorkspaces()));
641
642 m_showTransposed = new QAction(tr("Show Transposed"), this);
643 connect(m_showTransposed, SIGNAL(triggered()), this, SLOT(onClickShowTransposed()));
644
645 m_convertToMatrixWorkspace = new QAction(tr("Convert to MatrixWorkspace"), this);
646 m_convertToMatrixWorkspace->setIcon(QIcon(getQPixmap("mantid_matrix_xpm")));
647 connect(m_convertToMatrixWorkspace, SIGNAL(triggered()), this, SLOT(onClickConvertToMatrixWorkspace()));
648
649 m_convertMDHistoToMatrixWorkspace = new QAction(tr("Convert to MatrixWorkspace"), this);
650 m_convertMDHistoToMatrixWorkspace->setIcon(QIcon(getQPixmap("mantid_matrix_xpm")));
651 connect(m_convertMDHistoToMatrixWorkspace, SIGNAL(triggered()), this, SLOT(onClickConvertMDHistoToMatrixWorkspace()));
652
653 m_clearUB = new QAction(tr("Clear UB Matrix"), this);
654 connect(m_clearUB, SIGNAL(triggered()), this, SLOT(onClickClearUB()));
655}
656
662 QMenu *sortMenu = new QMenu(this);
663
664 QAction *ascendingSortAction = new QAction("Ascending", this);
665 QAction *descendingSortAction = new QAction("Descending", this);
666 QAction *byNameChoice = new QAction("Name", this);
667 QAction *byLastModifiedChoice = new QAction("Last Modified", this);
668 QAction *byMemorySize = new QAction("Size", this);
669
670 ascendingSortAction->setCheckable(true);
671 ascendingSortAction->setEnabled(true);
672
673 descendingSortAction->setCheckable(true);
674 descendingSortAction->setEnabled(true);
675
676 QActionGroup *sortDirectionGroup = new QActionGroup(sortMenu);
677 sortDirectionGroup->addAction(ascendingSortAction);
678 sortDirectionGroup->addAction(descendingSortAction);
679 sortDirectionGroup->setExclusive(true);
680 ascendingSortAction->setChecked(true);
681
682 byNameChoice->setCheckable(true);
683 byNameChoice->setEnabled(true);
684
685 byLastModifiedChoice->setCheckable(true);
686 byLastModifiedChoice->setEnabled(true);
687
688 byMemorySize->setCheckable(true);
689 byMemorySize->setEnabled(true);
690
691 QActionGroup *sortChoiceGroup = new QActionGroup(sortMenu);
692 sortChoiceGroup->addAction(byNameChoice);
693 sortChoiceGroup->addAction(byLastModifiedChoice);
694 sortChoiceGroup->addAction(byMemorySize);
695 sortChoiceGroup->setExclusive(true);
696 byNameChoice->setChecked(true);
697
698 connect(ascendingSortAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
699 connect(descendingSortAction, SIGNAL(triggered()), this, SLOT(sortDescending()));
700 connect(byNameChoice, SIGNAL(triggered()), this, SLOT(chooseByName()));
701 connect(byLastModifiedChoice, SIGNAL(triggered()), this, SLOT(chooseByLastModified()));
702 connect(byMemorySize, SIGNAL(triggered()), this, SLOT(chooseByMemorySize()));
703
704 sortMenu->addActions(sortDirectionGroup->actions());
705 sortMenu->addSeparator();
706 sortMenu->addActions(sortChoiceGroup->actions());
707 m_sortButton->setMenu(sortMenu);
708}
709
714void WorkspaceTreeWidget::populateChildData(QTreeWidgetItem *item) {
715 QVariant userData = item->data(0, Qt::UserRole);
716 if (userData.isNull())
717 return;
718
719 // Clear it first
720 while (item->childCount() > 0) {
721 auto *widgetItem = item->takeChild(0);
722 delete widgetItem;
723 }
724
725 Workspace_sptr workspace = userData.value<Workspace_sptr>();
726
727 if (auto group = std::dynamic_pointer_cast<WorkspaceGroup>(workspace)) {
728 auto members = group->getAllItems();
729 auto visibleNames = AnalysisDataService::Instance().getObjectNames();
730 for (const auto &ws : members) {
731 if (std::find(visibleNames.begin(), visibleNames.end(), ws->getName()) != visibleNames.end()) {
732 auto *node = addTreeEntry(std::make_pair(ws->getName(), ws), item);
734 if (shouldBeSelected(node->text(0)))
735 node->setSelected(true);
736 }
737 }
738 } else {
739 QString details;
740 try {
741 details = workspace->toString().c_str();
742 } catch (std::runtime_error &e) {
743 details = QString("Error: %1").arg(e.what());
744 }
745 QStringList rows = details.split(QLatin1Char('\n'), Qt::SkipEmptyParts);
746 rows.append(QString("Memory used: ") + workspace->getMemorySizeAsStr().c_str());
747
748 auto iend = rows.constEnd();
749 for (auto itr = rows.constBegin(); itr != iend; ++itr) {
750 MantidTreeWidgetItem *data = new MantidTreeWidgetItem(QStringList(*itr), m_tree);
751 data->setFlags(Qt::NoItemFlags);
753 item->addChild(data);
754 }
755 }
756}
757
767
773void WorkspaceTreeWidget::populateTopLevel(const TopLevelItems &topLevelItems, const QStringList &expanded) {
774 {
775 QMutexLocker lock(&m_mutex);
776 // collect names of selected workspaces
777 QList<QTreeWidgetItem *> selected = m_tree->selectedItems();
778 m_selectedNames.clear(); // just in case
779 foreach (QTreeWidgetItem *item, selected) {
780 m_selectedNames << item->text(0);
781 }
782
783 // populate the tree from scratch
784 m_tree->clear();
785 auto iend = topLevelItems.end();
786 for (auto it = topLevelItems.begin(); it != iend; ++it) {
787 auto *node = addTreeEntry(*it);
788 QString name = node->text(0);
789 if (expanded.contains(name))
790 node->setExpanded(true);
791 // see if item must be selected
793 node->setSelected(true);
794 }
795
796 m_selectedNames.clear();
797 m_renameMap.clear();
798 }
799 // apply any filtering
801}
802
810MantidTreeWidgetItem *WorkspaceTreeWidget::addTreeEntry(const std::pair<std::string, Mantid::API::Workspace_sptr> &item,
811 QTreeWidgetItem *parent) {
812 MantidTreeWidgetItem *node = new MantidTreeWidgetItem(QStringList(item.first.c_str()), m_tree);
813 node->setData(0, Qt::UserRole, QVariant::fromValue(item.second));
814
815 // A a child ID item so that it becomes expandable. Using the correct ID is
816 // needed when plotting from non-expanded groups.
817 const std::string wsID = item.second->id();
818 auto *idNode = new MantidTreeWidgetItem(QStringList(wsID.c_str()), m_tree);
819 idNode->setFlags(Qt::NoItemFlags);
820 node->addChild(idNode);
821 setItemIcon(node, wsID);
822
823 if (parent) {
824 parent->addChild(node);
825 } else {
826 m_tree->addTopLevelItem(node);
827 }
828 return node;
829}
830
835bool WorkspaceTreeWidget::shouldBeSelected(const QString &name) const {
836 QMutexLocker lock(&m_mutex);
837 QStringList renamed = m_renameMap.keys(name);
838 if (!renamed.isEmpty()) {
839 return std::any_of(renamed.cbegin(), renamed.cend(),
840 [&](const auto &oldName) { return m_selectedNames.contains(oldName); });
841 } else if (m_selectedNames.contains(name)) {
842 return true;
843 }
844 return false;
845}
846
848 // get selected workspaces
849 auto items = m_tree->selectedItems();
850
851 if (m_groupButton) {
852 if (items.size() == 1) {
853 // check it's group
854 auto wsSptr = items.first()->data(0, Qt::UserRole).value<Workspace_sptr>();
855 auto grpSptr = std::dynamic_pointer_cast<WorkspaceGroup>(wsSptr);
856 if (grpSptr) {
857 m_groupButton->setText("Ungroup");
858 m_groupButton->setToolTip("Ungroup selected workspace");
859 m_groupButton->setEnabled(true);
860 } else
861 m_groupButton->setEnabled(false);
862
863 } else if (items.size() >= 2) {
864 m_groupButton->setText("Group");
865 m_groupButton->setEnabled(true);
866 m_groupButton->setToolTip("Group together two or more selected workspaces");
867 } else if (items.size() == 0) {
868 m_groupButton->setText("Group");
869 m_groupButton->setEnabled(false);
870 m_groupButton->setToolTip("Group together two or more selected workspaces");
871 }
872 }
873
874 if (m_deleteButton)
875 m_deleteButton->setEnabled(items.size() > 0);
876
877 if (m_saveButton)
878 m_saveButton->setEnabled(items.size() > 0);
879
880 if (items.size() > 0) {
881 auto item = *(items.begin());
883 } else {
885 }
886}
887
894 const Mantid::API::MatrixWorkspace_const_sptr &matrixWS) const {
895 // Add all options except plot of we only have 1 value
896 menu->addAction(m_showData);
897 menu->addAction(m_showInst);
898 // Disable the 'show instrument' option if a workspace doesn't have an
899 // instrument attached or if it does not have a spectra axis
900 m_showInst->setEnabled(matrixWS->getInstrument() && !matrixWS->getInstrument()->getName().empty() &&
901 matrixWS->getAxis(1)->isSpectra());
902 menu->addSeparator();
903 menu->addAction(m_plotSpec);
904 menu->addAction(m_plotSpecErr);
905 menu->addAction(m_plotAdvanced);
906
907 // Don't plot a spectrum if only one X value
908 bool multipleBins = false;
909 try {
910 multipleBins = (matrixWS->blocksize() > 1);
911 } catch (...) {
912 const size_t numHist = matrixWS->getNumberHistograms();
913 for (size_t i = 0; i < numHist; ++i) {
914 if (matrixWS->y(i).size() > 1) {
915 multipleBins = true;
916 break;
917 }
918 }
919 }
920 m_plotSpec->setEnabled(multipleBins);
921 m_plotSpecErr->setEnabled(multipleBins);
922 m_plotAdvanced->setEnabled(multipleBins);
923
924 menu->addAction(m_showSpectrumViewer); // The 2D spectrum viewer
925
926 menu->addAction(m_colorFill);
927 // Show the color fill plot if you have more than one histogram
928 m_colorFill->setEnabled((matrixWS->axes() > 1 && matrixWS->getNumberHistograms() > 1));
929 menu->addAction(m_showSliceViewer); // The 2D slice viewer
930 menu->addSeparator();
931 menu->addAction(m_showDetectors);
932 menu->addAction(m_showLogs);
933 menu->addAction(m_showSampleMaterial);
934 menu->addAction(m_showHist);
935 menu->addAction(m_saveNexus);
936}
937
945 Q_UNUSED(WS);
946
947 // menu->addAction(m_showBoxData); // Show MD Box data (for debugging only)
948 menu->addAction(m_showSliceViewer); // The 2D slice viewer
949 menu->addAction(m_showHist); // Algorithm history
950 menu->addAction(m_showListData); // Show data in table
951 menu->addAction(m_showLogs);
952}
953
955 const Mantid::API::IMDWorkspace_const_sptr &WS) const {
956 Q_UNUSED(WS);
957 menu->addAction(m_showHist); // Algorithm history
958 menu->addAction(m_showSliceViewer); // The 2D slice viewer
959 menu->addAction(m_showMDPlot); // A plot of intensity vs bins
960 menu->addAction(m_showListData); // Show data in table
961 menu->addAction(m_convertMDHistoToMatrixWorkspace);
962 menu->addAction(m_showLogs);
963}
964
971 Q_UNUSED(WS);
972 menu->addAction(m_showData);
973 menu->addSeparator();
974 menu->addAction(m_showDetectors);
975 menu->addAction(m_showHist);
976}
977
983 m_plotSpec->setEnabled(true);
984 menu->addAction(m_plotSpec);
985 m_plotSpecErr->setEnabled(true);
986 menu->addAction(m_plotSpecErr);
987 m_plotAdvanced->setEnabled(true);
988 menu->addAction(m_plotAdvanced);
989 menu->addAction(m_colorFill);
990 m_colorFill->setEnabled(true);
991
992 menu->addSeparator();
993 menu->addAction(m_saveNexus);
994}
995
1001 menu->addAction(m_showData);
1002 menu->addAction(m_showTransposed);
1003 menu->addAction(m_showHist);
1004 menu->addAction(m_saveNexus);
1005 menu->addAction(m_convertToMatrixWorkspace);
1006}
1007
1013void WorkspaceTreeWidget::addClearMenuItems(QMenu *menu, const QString &wsName) {
1014 QMenu *clearMenu = new QMenu(tr("Clear Options"), this);
1015
1016 m_clearUB->setEnabled(hasUBMatrix(wsName.toStdString()));
1017
1018 clearMenu->addAction(m_clearUB);
1019 menu->addMenu(clearMenu);
1020}
1021
1022bool WorkspaceTreeWidget::hasUBMatrix(const std::string &wsName) {
1023 bool hasUB = false;
1024 Workspace_sptr ws = AnalysisDataService::Instance().retrieve(wsName);
1025 IMDWorkspace_sptr wsIMD = std::dynamic_pointer_cast<IMDWorkspace>(ws);
1026 if (ws && wsIMD) {
1027 hasUB = wsIMD->hasOrientedLattice();
1028 }
1029 return hasUB;
1030}
1031
1039void WorkspaceTreeWidget::addSaveMenuOption(const QString &algorithmString, QString menuEntryName) {
1040 // Default to algo string if no entry name given
1041 if (menuEntryName.isEmpty())
1042 menuEntryName = algorithmString;
1043
1044 // Create the action and add data
1045 QAction *saveAction = new QAction(menuEntryName, this);
1046 saveAction->setData(QVariant(algorithmString));
1047
1048 // Connect the trigger slot to show algorithm dialog
1049 connect(saveAction, SIGNAL(triggered()), this, SLOT(handleShowSaveAlgorithm()));
1050
1051 // Add it to the menu
1052 m_saveMenu->addAction(saveAction);
1053}
1054
1060 m_filteredText = text.toStdString();
1062}
1063
1068
1074 return askUserYesNo("Clear Workspaces", "This will delete all the workspaces, are you sure?");
1075}
1076
1081void WorkspaceTreeWidget::enableClearButton(bool enable) { m_clearButton->setEnabled(enable); }
1082
1087
1088void WorkspaceTreeWidget::clickedWorkspace(QTreeWidgetItem *item, int /*unused*/) { Q_UNUSED(item); }
1089
1091 auto selectedNames = getSelectedWorkspaceNames();
1092 if (selectedNames.empty())
1093 return;
1094
1095 // Remove all existing save algorithms from list
1096 m_saveMenu->clear();
1097
1098 addSaveMenuOption("SaveNexus", "Nexus");
1099 addSaveMenuOption("SaveAscii", "ASCII");
1100
1101 m_saveButton->setMenu(m_saveMenu);
1102}
1103
1106 if (m_groupButton) {
1107 QString qButtonName = m_groupButton->text();
1108 if (qButtonName == "Group") {
1110 } else if (qButtonName == "Ungroup") {
1112 }
1113 }
1114}
1115
1118
1123
1124// Asynchronous signal handlers
1128 // do not update until the counter is zero
1129 if (m_updateCount.deref())
1130 return;
1131
1132 // find all expanded top-level entries
1133 QStringList expanded;
1134 int n = m_tree->topLevelItemCount();
1135 for (int i = 0; i < n; ++i) {
1136 auto item = m_tree->topLevelItem(i);
1137 if (item->isExpanded()) {
1138 expanded << item->text(0);
1139 }
1140 }
1141
1142 // create a new tree
1143 setTreeUpdating(true);
1144 populateTopLevel(items, expanded);
1145 setTreeUpdating(false);
1146
1147 // enable clear button here if any items in tree
1148 enableClearButton(!items.empty());
1149
1150 // Re-sort
1151 m_tree->sort();
1152}
1153
1158
1159// Context Menu Methods
1160
1162void WorkspaceTreeWidget::popupMenu(const QPoint &pos) {
1163 if (!m_viewOnly) {
1164 m_menuPosition = pos;
1166 }
1167}
1168
1170 QTreeWidgetItem *treeItem = m_tree->itemAt(m_menuPosition);
1171 selectedWsName = "";
1172 if (treeItem)
1173 selectedWsName = treeItem->text(0);
1174 else
1175 m_tree->selectionModel()->clear();
1176
1177 QMenu *menu(nullptr);
1178
1179 // If no workspace is here then have load raw and dae
1180 if (selectedWsName.isEmpty())
1181 menu = m_loadMenu;
1182 else { // else show instrument, sample logs and delete
1183 // Fresh menu
1184 menu = new QMenu(this);
1185 menu->setObjectName("WorkspaceContextMenu");
1186 auto mantidTreeItem = dynamic_cast<MantidTreeWidgetItem *>(treeItem);
1187 auto ws = mantidTreeItem->data(0, Qt::UserRole).value<Mantid::API::Workspace_sptr>();
1188
1189 // Add the items that are appropriate for the type
1190 if (auto matrixWS = std::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(ws)) {
1191 addMatrixWorkspaceMenuItems(menu, matrixWS);
1192 } else if (auto mdeventWS = std::dynamic_pointer_cast<const IMDEventWorkspace>(ws)) {
1193 addMDEventWorkspaceMenuItems(menu, mdeventWS);
1194 } else if (auto mdWS = std::dynamic_pointer_cast<const IMDWorkspace>(ws)) {
1195 addMDHistoWorkspaceMenuItems(menu, mdWS);
1196 } else if (auto peaksWS = std::dynamic_pointer_cast<const IPeaksWorkspace>(ws)) {
1197 addPeaksWorkspaceMenuItems(menu, peaksWS);
1198 } else if (auto groupWS = std::dynamic_pointer_cast<const WorkspaceGroup>(ws)) {
1200 } else if (std::dynamic_pointer_cast<const Mantid::API::ITableWorkspace>(ws)) {
1202 } else {
1203 // None of the above? -> not a workspace
1204 return;
1205 }
1207
1208 // Get the names of the programs for the send to option
1209 std::vector<std::string> programNames =
1210 (Mantid::Kernel::ConfigService::Instance().getKeys("workspace.sendto.name"));
1211 bool firstPass(true);
1212 // Check to see if any options aren't visible
1213 for (const auto &programName : programNames) {
1214 std::string visible =
1215 Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programName + ".visible");
1216 std::string target =
1217 Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programName + ".target");
1218 if (Mantid::Kernel::ConfigService::Instance().isExecutable(target) && visible == "Yes") {
1219 bool compatible(true);
1220 std::string saveUsing(
1221 Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programName + ".saveusing"));
1222 try {
1223 Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create(saveUsing);
1224 alg->setPropertyValue("InputWorkspace", selectedWsName.toStdString());
1225 } catch (std::exception &) {
1226 compatible = false;
1227 }
1228 if (compatible) {
1229 if (firstPass) {
1230 m_saveToProgram = new QMenu(tr("Send to"), this);
1231 menu->addMenu(m_saveToProgram);
1232
1233 // Sub-menu for program list
1234 m_programMapper = new QSignalMapper(this);
1235 }
1236 QString name = QString::fromStdString(programName);
1237 // Setup new menu option for the program
1238 m_program = new QAction(name, this);
1239 connect(m_program, SIGNAL(triggered()), m_programMapper, SLOT(map()));
1240 // Send name of program when clicked
1241 m_programMapper->setMapping(m_program, name);
1242 m_saveToProgram->addAction(m_program);
1243
1244 // Set first pass to false so that it doesn't set up another menu
1245 // entry for all programs.
1246 firstPass = false;
1247 }
1248 }
1249 }
1250
1251 // Tell the button what to listen for and what to do once clicked (if there
1252 // is anything to connect it will be set to false)
1253 if (!firstPass)
1254 connect(m_programMapper, SIGNAL(mapped(const QString &)), this, SLOT(onClickSaveToProgram(const QString &)));
1255
1256 // Rename is valid for all workspace types
1257 menu->addAction(m_rename);
1258 // separate delete
1259 menu->addSeparator();
1260 menu->addAction(m_delete);
1261 }
1262
1263 // Show the menu at the cursor's current position
1264 menu->popup(QCursor::pos());
1265}
1266
1268
1270
1274
1276
1281
1286 // Create a map for the keys and details to go into
1287 std::map<std::string, std::string> programKeysAndDetails;
1288 programKeysAndDetails["name"] = m_programName.toStdString();
1289
1290 // Get a list of the program detail keys (mandatory - target, saveusing)
1291 // (optional - arguments, save parameters, workspace type)
1292 std::vector<std::string> programKeys = (Mantid::Kernel::ConfigService::Instance().getKeys(
1293 ("workspace.sendto." + programKeysAndDetails.find("name")->second)));
1294
1295 for (const auto &programKey : programKeys) {
1296 // Assign a key to its value using the map
1297 programKeysAndDetails[programKey] = (Mantid::Kernel::ConfigService::Instance().getString(
1298 ("workspace.sendto." + programKeysAndDetails.find("name")->second + "." + programKey)));
1299 }
1300
1301 // Check to see if mandatory information is included
1302 if ((programKeysAndDetails.count("name") != 0) && (programKeysAndDetails.count("target") != 0) &&
1303 (programKeysAndDetails.count("saveusing") != 0)) {
1304 std::string expTarget = Poco::Path::expand(programKeysAndDetails.find("target")->second);
1305
1306 QFileInfo target = QString::fromStdString(expTarget);
1307 if (target.exists()) {
1308 try {
1309 // Convert to QString and create Algorithm
1310 QString saveUsing = QString::fromStdString(programKeysAndDetails.find("saveusing")->second);
1311
1312 // Create a new save based on what files the new program can open
1313 auto alg = m_mantidDisplayModel->createAlgorithm(saveUsing);
1314
1315 // Get the file extention based on the workspace
1316 Property *prop = alg->getProperty("Filename");
1317 auto *fileProp = dynamic_cast<FileProperty *>(prop);
1318 std::string ext;
1319 if (fileProp) {
1320 ext = fileProp->getDefaultExt();
1321 }
1322
1323 // Save as.. default save + the file type i.e .nxs
1324 alg->setPropertyValue("fileName", "auto_save_" + selectedWsName.toStdString() + ext);
1325
1326 // Save the workspace
1327 alg->setPropertyValue("InputWorkspace", selectedWsName.toStdString());
1328
1329 // If there are any save parameters
1330 if (programKeysAndDetails.count("saveparameters") != 0) {
1331 QString saveParametersGrouped = QString::fromStdString(programKeysAndDetails.find("saveparameters")->second);
1332 QStringList saveParameters = saveParametersGrouped.split(',');
1333
1334 // For each one found split it up and assign the parameter
1335 for (int i = 0; i < saveParameters.size(); i++) {
1336 QStringList sPNameAndDetail = saveParameters[i].split('=');
1337 std::string saveParameterName = sPNameAndDetail[0].trimmed().toStdString();
1338 std::string saveParameterDetail = sPNameAndDetail[1].trimmed().toStdString();
1339 if (saveParameterDetail == "True")
1340 alg->setProperty(saveParameterName, true);
1341 else if (saveParameterDetail == "False")
1342 alg->setProperty(saveParameterName, false);
1343 else // if not true or false then must be a value
1344 {
1345 alg->setPropertyValue(saveParameterName, saveParameterDetail);
1346 }
1347 }
1348 }
1349
1350 // Execute the save
1351 executeAlgorithmAsync(alg, true);
1352
1353 // Get the save location of the file (should be default Mantid folder)
1354 QString savedFile = QString::fromStdString(alg->getProperty("Filename"));
1355 QStringList arguments;
1356
1357 // Arguments for the program to take. Default will be the file anyway.
1358 if (programKeysAndDetails.count("arguments") != 0) {
1359 QString temp = QString::fromStdString(programKeysAndDetails.find("arguments")->second);
1360 temp.replace(QString("[file]"), savedFile);
1361 // temp.replace(QString("[user]"), user;
1362 arguments = temp.split(",");
1363 } else
1364 arguments.insert(0, savedFile);
1365
1366 // convert the list into a standard vector for compatibility with Poco
1367 std::vector<std::string> argumentsV;
1368
1369 for (int i = 0; i < arguments.size(); i++) {
1370 argumentsV.assign(1, (arguments[i].toStdString()));
1371 }
1372
1373 // Execute the program
1374 try {
1375 Mantid::Kernel::ConfigService::Instance().launchProcess(expTarget, argumentsV);
1376 } catch (std::runtime_error &) {
1377 QMessageBox::information(this, "Error",
1378 "User tried to open program from: " + QString::fromStdString(expTarget) +
1379 " There was an error opening the program. "
1380 "Please check the target and arguments list "
1381 "to ensure that these are correct");
1382 }
1383 } catch (std::exception &) {
1384 QMessageBox::information(this, "Mantid - Send to Program",
1385 "A file property wasn't found. Please check that the correct" +
1386 QString("save algorithm was used.\n(View -> Preferences -> "
1387 "Mantid -> SendTo -> Edit -> SaveUsing)"));
1388 }
1389 } else
1390 QMessageBox::information(this, "Target Path Error",
1391 "User tried to open program from: " + QString::fromStdString(expTarget) +
1392 " The target file path for the program "
1393 "can't be found. Please check that the full "
1394 "path is correct");
1395 }
1396}
1397
1399
1403
1407
1411void WorkspaceTreeWidget::plotSpectrum(const std::string &type) {
1412 const bool isAdvanced = type == "Advanced";
1413 const auto userInput = m_tree->chooseSpectrumFromSelected(true, true, true, isAdvanced);
1414 // An empty map will be returned if the user clicks cancel in the spectrum
1415 // selection
1416 if (userInput.plots.empty()) {
1417 return;
1418 }
1419 bool showErrorBars = ((type == "Errors") || (type == "Advanced" && userInput.errors));
1420
1421 // mantidUI knows nothing about userInput, hence the long argument lists.
1422 if (userInput.tiled) {
1423 m_mantidDisplayModel->plotSubplots(userInput.plots, MantidQt::DistributionDefault, showErrorBars);
1424 } else if (userInput.simple || userInput.waterfall) {
1425 if (userInput.isAdvanced) {
1426 const auto advancedUserInput = userInput.advanced.value();
1427 m_mantidDisplayModel->plot1D(userInput.plots, true, MantidQt::DistributionDefault, showErrorBars, nullptr, false,
1428 userInput.waterfall, advancedUserInput.logName, advancedUserInput.customLogValues);
1429 } else {
1430 m_mantidDisplayModel->plot1D(userInput.plots, true, MantidQt::DistributionDefault, showErrorBars, nullptr, false,
1431 userInput.waterfall);
1432 }
1433
1434 } else if (userInput.surface) {
1435 const auto advancedUserInput = userInput.advanced.value();
1436 m_mantidDisplayModel->plotSurface(advancedUserInput.accepted, advancedUserInput.plotIndex,
1437 advancedUserInput.axisName, advancedUserInput.logName,
1438 advancedUserInput.customLogValues, advancedUserInput.workspaceNames);
1439 } else if (userInput.contour) {
1440 const auto advancedUserInput = userInput.advanced.value();
1441 m_mantidDisplayModel->plotContour(advancedUserInput.accepted, advancedUserInput.plotIndex,
1442 advancedUserInput.axisName, advancedUserInput.logName,
1443 advancedUserInput.customLogValues, advancedUserInput.workspaceNames);
1444 }
1445}
1446
1450
1457 // Get the selected workspaces
1458 auto items = m_tree->selectedItems();
1459 if (items.empty())
1460 return;
1461
1462 // Extract child workspace names from any WorkspaceGroups selected.
1463 // Use a list to preserve workspace order.
1464 QStringList allWsNames;
1465
1466 for (auto &item : items) {
1467 auto ws = item->data(0, Qt::UserRole).value<Workspace_sptr>();
1468
1469 if (auto wsGroup = std::dynamic_pointer_cast<WorkspaceGroup>(ws)) {
1470 for (const auto &name : wsGroup->getNames())
1471 allWsNames.append(QString::fromStdString(name));
1472 } else
1473 allWsNames.append(item->text(0));
1474 }
1475
1476 // remove duplicate workspace entries
1477 allWsNames.removeDuplicates();
1478
1480}
1481
1483 switch (e->key()) {
1484 case Qt::Key_Delete:
1485 case Qt::Key_Backspace:
1487 break;
1488 }
1489}
1490
1494
1496 // get selected workspace
1497 auto ws = QString::fromStdString(getSelectedWorkspaceNames()[0]);
1498 const auto *table = m_mantidDisplayModel->createDetectorTable(ws, std::vector<int>(), false);
1499 if (!table) {
1500 QMessageBox::information(this, "Error", QString("Cannot create detectors tables for workspace ") + ws);
1501 }
1502}
1503
1505
1507
1509
1511
1513
1515
1519
1521
1525
1527
1529
1531
1535
1537
1541
1543
1545
1547
1558
1565
1569
1573
1578
1589
1591 m_loadButton->hide();
1592 m_saveButton->hide();
1593 m_deleteButton->hide();
1594 m_clearButton->hide();
1595 m_groupButton->hide();
1596 m_sortButton->hide();
1597}
1598
1599} // namespace MantidQt::MantidWidgets
std::string name
Definition Run.cpp:60
IPeaksWorkspace_sptr workspace
std::map< std::string, Mantid::API::Workspace_sptr > TopLevelItems
This class should be the basis for all customised algorithm dialogs.
Defines a mapping between a workspace ID and a pixmap to use for an icon.
virtual void deleteWorkspaces(const QStringList &wsNames=QStringList())=0
virtual bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, const bool wait=false)=0
virtual MultiLayer * plot1D(const QMultiMap< QString, std::set< int > > &toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr=MantidQt::DistributionDefault, bool errs=false, MultiLayer *plotWindow=nullptr, bool clearWindow=false, bool waterfallPlot=false, const QString &log="", const std::set< double > &customLogValues=std::set< double >())=0
virtual void plotSurface(bool accepted, int plotIndex, const QString &axisName, const QString &logName, const std::set< double > &customLogValues, const QList< QString > &workspaceNames)=0
virtual void drawColorFillPlots(const QStringList &wsNames, GraphOptions::CurveType curveType=GraphOptions::ColorMap)=0
virtual MultiLayer * plotSubplots(const QMultiMap< QString, std::set< int > > &toPlot, MantidQt::DistributionFlag distr=MantidQt::DistributionDefault, bool errs=false, MultiLayer *plotWindow=nullptr)=0
virtual void updateRecentFilesList(const QString &fname)=0
virtual Mantid::API::IAlgorithm_sptr createAlgorithm(const QString &algName, int version=-1)=0
virtual void showAlgorithmDialog(const QString &algName, int version=-1)=0
virtual void renameWorkspace(QStringList=QStringList())=0
virtual void enableSaveNexus(const QString &wsName)=0
virtual Table * createDetectorTable(const QString &wsName, const std::vector< int > &indices, bool include_data=false)=0
virtual void plotContour(bool accepted, int plotIndex, const QString &axisName, const QString &logName, const std::set< double > &customLogValues, const QList< QString > &workspaceNames)=0
A class derived from QTreeWidgetItem, to accomodate sorting on the items in a MantidTreeWidget.
MantidWSIndexWidget::UserInput chooseSpectrumFromSelected(bool showWaterfallOpt=true, bool showPlotAll=true, bool showTiledOpt=true, bool isAdvanced=false) const
Allows users to choose spectra from the selected workspaces by presenting them with a dialog box.
void dropEvent(QDropEvent *de) override
Accept a drag drop event and process the data appropriately.
void sort()
Sort the items according to the current sort scheme and order.
void onClickLiveData()
handles Live Data menu trigger
void onClickGroupButton()
Handles group button clicks.
bool shouldBeSelected(const QString &name) const
Check if a workspace should be selected after dock update.
QMutex m_mutex
A mutex to lock m_renameMap and m_selectedNames for reading/writing.
void createWorkspaceMenuActions()
Create the action items associated with the dock.
void addWorkspaceGroupMenuItems(QMenu *menu) const
Add the actions that are appropriate for a WorkspaceGroup.
bool clearWorkspacesConfirmation() const override
Gets confirmation from user that they meant to press clear workspaces button.
void enableClearButton(bool enable) override
Enables and disables the Clear Workspaces Button.
void popupMenu(const QPoint &pos)
Handles display of the workspace context menu.
void saveWorkspaces(const MantidQt::MantidWidgets::StringList &wsNames) override
void addPeaksWorkspaceMenuItems(QMenu *menu, const Mantid::API::IPeaksWorkspace_const_sptr &WS) const
Add the actions that are appropriate for a PeaksWorkspace.
void populateTopLevel(const TopLevelItems &topLevelItems, const QStringList &expanded)
Clears the tree and re-populates it with the given top level items.
void addMDHistoWorkspaceMenuItems(QMenu *menu, const Mantid::API::IMDWorkspace_const_sptr &WS) const
void deleteWorkspaces(const MantidQt::MantidWidgets::StringList &wsNames) override
MantidQt::MantidWidgets::WorkspacePresenterVN_sptr m_presenter
void addClearMenuItems(QMenu *menu, const QString &wsName)
Add menu for clearing workspace items.
void signalUpdateTree(const TopLevelItems &)
void createSortMenuActions()
Create actions for sorting.
void filterWorkspaces(const std::string &filterText) override
void onClickClearWorkspaces()
Handles clear button trigger.
void onClickClearUB()
Handler for the clear the UB matrix event.
void setTreeUpdating(const bool state)
Flips the flag indicating whether a tree update is in progress.
void onClickLoad()
Handles Load File menu trigger.
bool askUserYesNo(const std::string &caption, const std::string &message) const override
MantidQt::MantidWidgets::StringList getSelectedWorkspaceNames() const override
Returns the names of the selected workspaces in the dock.
MantidQt::MantidWidgets::MantidItemSortScheme whichCriteria(SortCriteria criteria)
void onClickConvertMDHistoToMatrixWorkspace()
Convert selected MDHistoWorkspace to a MatrixWorkspace.
QHash< QString, QString > m_renameMap
Keep a map of renamed workspaces between updates.
void handleUpdateTree(const TopLevelItems &)
Handle asynchronous tree update.
void saveToProgram() override
Saves a workspace based on the program the user chooses to save to.
void populateChildData(QTreeWidgetItem *item)
When an item is expanded, populate the child data for this item.
void setItemIcon(QTreeWidgetItem *item, const std::string &wsID)
Set tree item's icon based on the ID of the workspace.
void saveWorkspace(const std::string &wsName, SaveFileType type) override
void addMDEventWorkspaceMenuItems(QMenu *menu, const Mantid::API::IMDEventWorkspace_const_sptr &mdeventWS) const
Add the actions that are appropriate for a MDEventWorkspace.
WorkspaceTreeWidget(MantidQt::MantidWidgets::MantidDisplayBase *mdb, bool viewOnly=false, QWidget *parent=nullptr)
void plotSpectrum(const std::string &type) override
Plots one or more spectra from each selected workspace.
void filterWorkspaceTree(const QString &text)
Filter workspaces based on the string provided.
void excludeItemFromSort(MantidTreeWidgetItem *item)
void addTableWorkspaceMenuItems(QMenu *menu) const
Add the actions that are appropriate for a MatrixWorkspace.
void showRenameDialog(const MantidQt::MantidWidgets::StringList &wsNames) override
void recordWorkspaceRename(const std::string &oldName, const std::string &newName) override
Save the old and the new name in m_renameMap.
void addSaveMenuOption(const QString &algorithmString, QString menuEntryName="")
Adds an algorithm to the save menu.
MantidTreeWidgetItem * addTreeEntry(const std::pair< std::string, Mantid::API::Workspace_sptr > &item, QTreeWidgetItem *parent=nullptr)
Adds a node for the given named item, including a single child ID item to make each node have a expan...
MantidQt::MantidWidgets::WorkspacePresenterWN_wptr getPresenterWeakPtr() override
void onClickConvertToMatrixWorkspace()
Convert selected TableWorkspace to a MatrixWorkspace.
void onClickDeleteWorkspaces()
Handles delete button/menu item triggers.
Mantid::API::Workspace_sptr getSelectedWorkspace() const override
Returns a pointer to the selected workspace (the first if multiple workspaces selected)
bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, const bool wait=true) override
Allows asynchronous execution of algorithms.
void sortWorkspaces(SortCriteria criteria, SortDirection direction) override
void dropEvent(QDropEvent *de) override
Accept a drag drop event and process the data appropriately.
void showCriticalUserMessage(const std::string &caption, const std::string &message) const override
void updateTree(const TopLevelItems &items) override
Update the workspace tree to match the current state of the ADS.
QStringList m_selectedNames
Temporarily keeps names of selected workspaces during tree update in order to restore selection after...
void showColourFillPlot() override
Draw a color fill plot of the workspaces that are currently selected.
void addMatrixWorkspaceMenuItems(QMenu *menu, const Mantid::API::MatrixWorkspace_const_sptr &matrixWS) const
Add the actions that are appropriate for a MatrixWorkspace.
A specialized class for dealing with file properties.
const std::string & getDefaultExt() const
Returns the main file extension that's used.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
Base class for properties.
Definition Property.h:94
EXPORT_OPT_MANTIDQT_COMMON QPixmap getQPixmap(const std::string &name)
Function that returns a QPixmap given a string name.
std::vector< std::string > StringList
std::weak_ptr< WorkspaceProviderNotifiable > WorkspacePresenterWN_wptr
std::shared_ptr< const IMDEventWorkspace > IMDEventWorkspace_const_sptr
Shared pointer to Mantid::API::IMDEventWorkspace (const version)
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const IMDWorkspace > IMDWorkspace_const_sptr
Shared pointer to the IMDWorkspace base class (const version)
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
std::shared_ptr< const IPeaksWorkspace > IPeaksWorkspace_const_sptr
shared pointer to Mantid::API::IPeaksWorkspace (const version)