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
23#include "MantidAPI/Axis.h"
30
31#include <Poco/Path.h>
32
33#include <memory>
34
35#include <QFileDialog>
36#include <QKeyEvent>
37#include <QMainWindow>
38#include <QMenu>
39#include <QMessageBox>
40#include <QPushButton>
41#include <QSignalMapper>
42
43using namespace MantidQt::API;
44using namespace Mantid::API;
45using namespace Mantid::Kernel;
46
47namespace {
49Mantid::Kernel::Logger docklog("MantidDockWidget");
50
51WorkspaceIcons WORKSPACE_ICONS = WorkspaceIcons();
52} // namespace
53
55
57 : QWidget(parent), m_mantidDisplayModel(mdb), m_viewOnly(viewOnly), m_updateCount(0), m_treeUpdating(false),
58 m_promptDelete(false), m_saveFileType(SaveFileType::Nexus), m_sortCriteria(SortCriteria::ByName),
59 m_sortDirection(SortDirection::Ascending), m_mutex(QMutex::Recursive) {
60 setObjectName("exploreMantid"); // this is needed for QMainWindow::restoreState()
61 m_saveMenu = new QMenu(this);
62
64
66
67 // Dialog box used for user to specify folder to save multiple workspaces into
68 m_saveFolderDialog = new QFileDialog;
69 m_saveFolderDialog->setFileMode(QFileDialog::Directory);
70 m_saveFolderDialog->setOption(QFileDialog::ShowDirsOnly);
71
72 // To be able to use them in queued signals they need to be registered
73 static bool registered_addtional_types = false;
74 if (!registered_addtional_types) {
75 registered_addtional_types = true;
76 qRegisterMetaType<TopLevelItems>();
77 }
78
79 // SET UP SORT
82
84
85 m_tree->setDragEnabled(true);
86
87 auto presenter = std::make_shared<WorkspacePresenter>(this);
88 m_presenter = std::dynamic_pointer_cast<ViewNotifiable>(presenter);
89 presenter->init();
90
91 if (m_viewOnly)
93}
94
96
101void WorkspaceTreeWidget::dropEvent(QDropEvent *de) { m_tree->dropEvent(de); }
102
105 m_tree->setHeaderLabel("Workspaces");
106
107 auto *buttonLayout = new FlowLayout();
108 m_loadButton = new QPushButton("Load");
109 m_loadButton->setToolTip("Load a file or live data");
110 m_saveButton = new QPushButton("Save");
111 m_saveButton->setToolTip("Save the selected workspaces");
112 m_deleteButton = new QPushButton("Delete");
113 m_deleteButton->setToolTip("Delete the selected workspaces");
114 m_clearButton = new QPushButton("Clear");
115 m_clearButton->setToolTip("Delete all workspaces");
116 m_groupButton = new QPushButton("Group");
117 m_groupButton->setToolTip("Group together two or more selected workspaces");
118 m_sortButton = new QPushButton("Sort");
119 m_sortButton->setToolTip("Sort all workspaces by name, size, or the last time they were modified");
120
121 if (m_groupButton)
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 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 (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 (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 (auto &ws : wsNames)
303 names.append(QString::fromStdString(ws));
305}
306
308
312}
313
317}
318
322}
323
327}
328
332}
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
371}
372
374 QAction *sendingAction = dynamic_cast<QAction *>(sender());
375
376 if (sendingAction) {
377 QString actionName = sendingAction->text();
378
379 if (actionName.compare("Nexus") == 0)
381 else if (actionName.compare("ASCII") == 0)
383 }
384
386}
387
389
390void WorkspaceTreeWidget::saveWorkspace(const std::string &wsName, SaveFileType type) {
392 if (!wsName.empty()) {
393 presets["InputWorkspace"] = QString::fromStdString(wsName);
394 }
395 int version = -1;
396 std::string algorithmName;
397
398 switch (type) {
400 algorithmName = "SaveNexus";
401 break;
403 algorithmName = "SaveAscii";
404 break;
405 }
406
407 m_mantidDisplayModel->showAlgorithmDialog(QString::fromStdString(algorithmName), presets, nullptr, version);
408}
409
411 QList<QTreeWidgetItem *> items = m_tree->selectedItems();
412 if (items.size() < 2)
413 return;
414
415 m_saveFolderDialog->setWindowTitle("Select save folder");
416 m_saveFolderDialog->setLabelText(QFileDialog::Accept, "Select");
417 auto res = m_saveFolderDialog->exec();
418 auto folder = m_saveFolderDialog->selectedFiles()[0].toStdString();
419
420 IAlgorithm_sptr saveAlg = AlgorithmManager::Instance().create("SaveNexus");
421 saveAlg->initialize();
422
423 if (res == QFileDialog::Accepted) {
424 for (auto &wsName : wsNames) {
425 std::string filename = folder + "/" + wsName + ".nxs";
426 try {
427 saveAlg->setProperty("InputWorkspace", wsName);
428 saveAlg->setProperty("Filename", filename);
429 saveAlg->execute();
430 } catch (std::exception &ex) {
431 docklog.error() << "Error saving workspace " << wsName << ": " << ex.what() << '\n';
432 }
433 }
434 }
435}
436
437std::string WorkspaceTreeWidget::getFilterText() const { return m_workspaceFilter->text().toStdString(); }
438
439void WorkspaceTreeWidget::filterWorkspaces(const std::string &filterText) {
440 const QString text = QString::fromStdString(filterText).trimmed();
441 QRegExp filterRegEx(text, Qt::CaseInsensitive);
442
443 // show all items
444 QTreeWidgetItemIterator unhideIter(m_tree);
445 while (*unhideIter) {
446 (*unhideIter)->setHidden(false);
447 ++unhideIter;
448 }
449
450 int hiddenCount = 0;
451 QList<QTreeWidgetItem *> visibleGroups;
452 if (!text.isEmpty()) {
453 // Loop over everything (currently loaded) and top level
454 // find out what is already expanded
455 QStringList expanded;
456 int n = m_tree->topLevelItemCount();
457 for (int i = 0; i < n; ++i) {
458 auto item = m_tree->topLevelItem(i);
459 if (item->isExpanded()) {
460 expanded << item->text(0);
461 } else {
462 // expand everything that is at the top level (as we lazy load this is
463 // required)
464 item->setExpanded(true);
465 }
466 }
467
468 // filter based on the string
469 QTreeWidgetItemIterator it(m_tree, QTreeWidgetItemIterator::All);
470 while (*it) {
471 QTreeWidgetItem *item = (*it);
472 QVariant userData = item->data(0, Qt::UserRole);
473
474 if (!userData.isNull()) {
475 Workspace_sptr workspace = userData.value<Workspace_sptr>();
476 if (workspace) {
477 // I am a workspace
478 if (item->text(0).contains(filterRegEx)) {
479 // my name does match the filter
480 if (workspace->isGroup()) {
481 // I am a group, I will want my children to be visible
482 // but I cannot do that until this iterator has finished
483 // store this pointer in a list for processing later
484 visibleGroups.append(item);
485 item->setHidden(false);
486 }
487
488 if (item->parent() == nullptr) {
489 // No parent, I am a top level workspace - show me
490 item->setHidden(false);
491 } else {
492 // I am a child workspace of a group
493 // I match, so I want my parent to remain visible as well.
494 item->setHidden(false);
495 if (item->parent()->isHidden()) {
496 // I was previously hidden, show me and set to be expanded
497 --hiddenCount;
498 item->parent()->setHidden(false);
499 expanded << item->parent()->text(0);
500 }
501 }
502 } else {
503 // my name does not match the filter - hide me
504 item->setHidden(true);
505 ++hiddenCount;
506 }
507 }
508 }
509 ++it;
510 }
511
512 // make children of visible groups visible
513 for (auto group : visibleGroups) {
514 for (int i = 0; i < group->childCount(); i++) {
515 QTreeWidgetItem *child = group->child(i);
516 if (child->isHidden()) {
517 // I was previously hidden, show me
518 --hiddenCount;
519 child->setHidden(false);
520 }
521 }
522 }
523
524 // set the expanded state
525 for (int i = 0; i < n; ++i) {
526 auto item = m_tree->topLevelItem(i);
527 item->setExpanded(expanded.contains(item->text(0)));
528 }
529 }
530
531 // display a message if items are hidden
532 if (hiddenCount > 0) {
533 QString headerString = QString("Workspaces (%1 filtered)").arg(QString::number(hiddenCount));
534 m_tree->headerItem()->setText(0, headerString);
535 } else {
536 m_tree->headerItem()->setText(0, "Workspaces");
537 }
538}
539
545void WorkspaceTreeWidget::setItemIcon(QTreeWidgetItem *item, const std::string &wsID) {
546 try {
547 item->setIcon(0, QIcon(WORKSPACE_ICONS.getIcon(wsID)));
548 } catch (std::runtime_error &) {
549 docklog.warning() << "Cannot find icon for workspace ID '" << wsID << "'\n";
550 }
551}
552
557 m_showData = new QAction(tr("Show Data"), this);
558 connect(m_showData, SIGNAL(triggered()), this, SLOT(onClickShowData()));
559
560 m_showInst = new QAction(tr("Show Instrument"), this);
561 connect(m_showInst, SIGNAL(triggered()), this, SLOT(onClickShowInstrument()));
562
563 m_plotSpec = new QAction(tr("Plot Spectrum..."), this);
564 connect(m_plotSpec, SIGNAL(triggered()), this, SLOT(onClickPlotSpectra()));
565
566 m_plotSpecErr = new QAction(tr("Plot Spectrum with Errors..."), this);
567 connect(m_plotSpecErr, SIGNAL(triggered()), this, SLOT(onClickPlotSpectraErr()));
568
569 m_plotAdvanced = new QAction(tr("Plot Advanced..."), this);
570 connect(m_plotAdvanced, SIGNAL(triggered()), this, SLOT(onClickPlotAdvanced()));
571
572 m_colorFill = new QAction(tr("Color Fill Plot"), this);
573 connect(m_colorFill, SIGNAL(triggered()), this, SLOT(onClickDrawColorFillPlot()));
574
575 m_showDetectors = new QAction(tr("Show Detectors"), this);
576 connect(m_showDetectors, SIGNAL(triggered()), this, SLOT(onClickShowDetectorTable()));
577
578 m_showBoxData = new QAction(tr("Show Box Data Table"), this);
579 connect(m_showBoxData, SIGNAL(triggered()), this, SLOT(onClickShowBoxData()));
580
581 m_showMDPlot = new QAction(tr("Plot MD"), this);
582 connect(m_showMDPlot, SIGNAL(triggered()), this, SLOT(onClickShowMDPlot()));
583
584 m_showListData = new QAction(tr("List Data"), this);
585 connect(m_showListData, SIGNAL(triggered()), this, SLOT(onClickShowListData()));
586
587 m_showSpectrumViewer = new QAction(tr("Show Spectrum Viewer"), this);
588 connect(m_showSpectrumViewer, SIGNAL(triggered()), this, SLOT(onClickShowSpectrumViewer()));
589
590 m_showSliceViewer = new QAction(tr("Show Slice Viewer"), this);
591 {
592 QIcon icon;
593 icon.addFile(QString::fromUtf8(":/SliceViewer/icons/SliceViewerWindow_icon.png"), QSize(), QIcon::Normal,
594 QIcon::Off);
595 m_showSliceViewer->setIcon(icon);
596 }
597 connect(m_showSliceViewer, SIGNAL(triggered()), this, SLOT(onClickShowSliceViewer()));
598
599 m_showLogs = new QAction(tr("Sample Logs..."), this);
600 connect(m_showLogs, SIGNAL(triggered()), this, SLOT(onClickShowFileLog()));
601
602 m_showSampleMaterial = new QAction(tr("Sample Material..."), this);
603 connect(m_showSampleMaterial, SIGNAL(triggered()), this, SLOT(onClickShowSampleMaterial()));
604
605 m_showHist = new QAction(tr("Show History"), this);
606 connect(m_showHist, SIGNAL(triggered()), this, SLOT(onClickShowAlgHistory()));
607
608 m_saveNexus = new QAction(tr("Save NeXus"), this);
609 connect(m_saveNexus, SIGNAL(triggered()), this, SLOT(onClickSaveNexusWorkspace()));
610
611 m_rename = new QAction(tr("Rename"), this);
612 connect(m_rename, SIGNAL(triggered()), this, SLOT(renameWorkspace()));
613
614 m_delete = new QAction(tr("Delete"), this);
615 connect(m_delete, SIGNAL(triggered()), this, SLOT(onClickDeleteWorkspaces()));
616
617 m_showTransposed = new QAction(tr("Show Transposed"), this);
618 connect(m_showTransposed, SIGNAL(triggered()), this, SLOT(onClickShowTransposed()));
619
620 m_convertToMatrixWorkspace = new QAction(tr("Convert to MatrixWorkspace"), this);
621 m_convertToMatrixWorkspace->setIcon(QIcon(getQPixmap("mantid_matrix_xpm")));
622 connect(m_convertToMatrixWorkspace, SIGNAL(triggered()), this, SLOT(onClickConvertToMatrixWorkspace()));
623
624 m_convertMDHistoToMatrixWorkspace = new QAction(tr("Convert to MatrixWorkspace"), this);
625 m_convertMDHistoToMatrixWorkspace->setIcon(QIcon(getQPixmap("mantid_matrix_xpm")));
626 connect(m_convertMDHistoToMatrixWorkspace, SIGNAL(triggered()), this, SLOT(onClickConvertMDHistoToMatrixWorkspace()));
627
628 m_clearUB = new QAction(tr("Clear UB Matrix"), this);
629 connect(m_clearUB, SIGNAL(triggered()), this, SLOT(onClickClearUB()));
630}
631
637 m_sortMenu = new QMenu(this);
638
639 QAction *m_ascendingSortAction = new QAction("Ascending", this);
640 QAction *m_descendingSortAction = new QAction("Descending", this);
641 QAction *m_byNameChoice = new QAction("Name", this);
642 QAction *m_byLastModifiedChoice = new QAction("Last Modified", this);
643 QAction *m_byMemorySize = new QAction("Size", this);
644
645 m_ascendingSortAction->setCheckable(true);
646 m_ascendingSortAction->setEnabled(true);
647
648 m_descendingSortAction->setCheckable(true);
649 m_descendingSortAction->setEnabled(true);
650
651 QActionGroup *sortDirectionGroup = new QActionGroup(m_sortMenu);
652 sortDirectionGroup->addAction(m_ascendingSortAction);
653 sortDirectionGroup->addAction(m_descendingSortAction);
654 sortDirectionGroup->setExclusive(true);
655 m_ascendingSortAction->setChecked(true);
656
657 m_byNameChoice->setCheckable(true);
658 m_byNameChoice->setEnabled(true);
659
660 m_byLastModifiedChoice->setCheckable(true);
661 m_byLastModifiedChoice->setEnabled(true);
662
663 m_byMemorySize->setCheckable(true);
664 m_byMemorySize->setEnabled(true);
665
666 m_sortChoiceGroup = new QActionGroup(m_sortMenu);
669 m_sortChoiceGroup->addAction(m_byMemorySize);
670 m_sortChoiceGroup->setExclusive(true);
671 m_byNameChoice->setChecked(true);
672
673 connect(m_ascendingSortAction, SIGNAL(triggered()), this, SLOT(sortAscending()));
674 connect(m_descendingSortAction, SIGNAL(triggered()), this, SLOT(sortDescending()));
675 connect(m_byNameChoice, SIGNAL(triggered()), this, SLOT(chooseByName()));
676 connect(m_byLastModifiedChoice, SIGNAL(triggered()), this, SLOT(chooseByLastModified()));
677 connect(m_byMemorySize, SIGNAL(triggered()), this, SLOT(chooseByMemorySize()));
678
679 m_sortMenu->addActions(sortDirectionGroup->actions());
680 m_sortMenu->addSeparator();
681 m_sortMenu->addActions(m_sortChoiceGroup->actions());
682 m_sortButton->setMenu(m_sortMenu);
683}
684
689void WorkspaceTreeWidget::populateChildData(QTreeWidgetItem *item) {
690 QVariant userData = item->data(0, Qt::UserRole);
691 if (userData.isNull())
692 return;
693
694 // Clear it first
695 while (item->childCount() > 0) {
696 auto *widgetItem = item->takeChild(0);
697 delete widgetItem;
698 }
699
700 Workspace_sptr workspace = userData.value<Workspace_sptr>();
701
702 if (auto group = std::dynamic_pointer_cast<WorkspaceGroup>(workspace)) {
703 auto members = group->getAllItems();
704 for (const auto &ws : members) {
705 auto *node = addTreeEntry(std::make_pair(ws->getName(), ws), item);
707 if (shouldBeSelected(node->text(0)))
708 node->setSelected(true);
709 }
710 } else {
711 QString details;
712 try {
713 details = workspace->toString().c_str();
714 } catch (std::runtime_error &e) {
715 details = QString("Error: %1").arg(e.what());
716 }
717 QStringList rows = details.split(QLatin1Char('\n'), Qt::SkipEmptyParts);
718 rows.append(QString("Memory used: ") + workspace->getMemorySizeAsStr().c_str());
719
720 auto iend = rows.constEnd();
721 for (auto itr = rows.constBegin(); itr != iend; ++itr) {
722 MantidTreeWidgetItem *data = new MantidTreeWidgetItem(QStringList(*itr), m_tree);
723 data->setFlags(Qt::NoItemFlags);
725 item->addChild(data);
726 }
727 }
728}
729
737 emit signalUpdateTree(items);
738}
739
745void WorkspaceTreeWidget::populateTopLevel(const TopLevelItems &topLevelItems, const QStringList &expanded) {
746 {
747 QMutexLocker lock(&m_mutex);
748 // collect names of selected workspaces
749 QList<QTreeWidgetItem *> selected = m_tree->selectedItems();
750 m_selectedNames.clear(); // just in case
751 foreach (QTreeWidgetItem *item, selected) { m_selectedNames << item->text(0); }
752
753 // populate the tree from scratch
754 m_tree->clear();
755 auto iend = topLevelItems.end();
756 for (auto it = topLevelItems.begin(); it != iend; ++it) {
757 auto *node = addTreeEntry(*it);
758 QString name = node->text(0);
759 if (expanded.contains(name))
760 node->setExpanded(true);
761 // see if item must be selected
762 if (shouldBeSelected(name))
763 node->setSelected(true);
764 }
765
766 m_selectedNames.clear();
767 m_renameMap.clear();
768 }
769 // apply any filtering
771}
772
780MantidTreeWidgetItem *WorkspaceTreeWidget::addTreeEntry(const std::pair<std::string, Mantid::API::Workspace_sptr> &item,
781 QTreeWidgetItem *parent) {
782 MantidTreeWidgetItem *node = new MantidTreeWidgetItem(QStringList(item.first.c_str()), m_tree);
783 node->setData(0, Qt::UserRole, QVariant::fromValue(item.second));
784
785 // A a child ID item so that it becomes expandable. Using the correct ID is
786 // needed when plotting from non-expanded groups.
787 const std::string wsID = item.second->id();
788 auto *idNode = new MantidTreeWidgetItem(QStringList(wsID.c_str()), m_tree);
789 idNode->setFlags(Qt::NoItemFlags);
790 node->addChild(idNode);
791 setItemIcon(node, wsID);
792
793 if (parent) {
794 parent->addChild(node);
795 } else {
796 m_tree->addTopLevelItem(node);
797 }
798 return node;
799}
800
805bool WorkspaceTreeWidget::shouldBeSelected(const QString &name) const {
806 QMutexLocker lock(&m_mutex);
807 QStringList renamed = m_renameMap.keys(name);
808 if (!renamed.isEmpty()) {
809 foreach (QString oldName, renamed) {
810 if (m_selectedNames.contains(oldName)) {
811 return true;
812 }
813 }
814 } else if (m_selectedNames.contains(name)) {
815 return true;
816 }
817 return false;
818}
819
821 // get selected workspaces
822 auto items = m_tree->selectedItems();
823
824 if (m_groupButton) {
825 if (items.size() == 1) {
826 // check it's group
827 auto wsSptr = items.first()->data(0, Qt::UserRole).value<Workspace_sptr>();
828 auto grpSptr = std::dynamic_pointer_cast<WorkspaceGroup>(wsSptr);
829 if (grpSptr) {
830 m_groupButton->setText("Ungroup");
831 m_groupButton->setToolTip("Ungroup selected workspace");
832 m_groupButton->setEnabled(true);
833 } else
834 m_groupButton->setEnabled(false);
835
836 } else if (items.size() >= 2) {
837 m_groupButton->setText("Group");
838 m_groupButton->setEnabled(true);
839 m_groupButton->setToolTip("Group together two or more selected workspaces");
840 } else if (items.size() == 0) {
841 m_groupButton->setText("Group");
842 m_groupButton->setEnabled(false);
843 m_groupButton->setToolTip("Group together two or more selected workspaces");
844 }
845 }
846
847 if (m_deleteButton)
848 m_deleteButton->setEnabled(items.size() > 0);
849
850 if (m_saveButton)
851 m_saveButton->setEnabled(items.size() > 0);
852
853 if (items.size() > 0) {
854 auto item = *(items.begin());
856 } else {
858 }
859}
860
867 const Mantid::API::MatrixWorkspace_const_sptr &matrixWS) const {
868 // Add all options except plot of we only have 1 value
869 menu->addAction(m_showData);
870 menu->addAction(m_showInst);
871 // Disable the 'show instrument' option if a workspace doesn't have an
872 // instrument attached or if it does not have a spectra axis
873 m_showInst->setEnabled(matrixWS->getInstrument() && !matrixWS->getInstrument()->getName().empty() &&
874 matrixWS->getAxis(1)->isSpectra());
875 menu->addSeparator();
876 menu->addAction(m_plotSpec);
877 menu->addAction(m_plotSpecErr);
878 menu->addAction(m_plotAdvanced);
879
880 // Don't plot a spectrum if only one X value
881 bool multipleBins = false;
882 try {
883 multipleBins = (matrixWS->blocksize() > 1);
884 } catch (...) {
885 const size_t numHist = matrixWS->getNumberHistograms();
886 for (size_t i = 0; i < numHist; ++i) {
887 if (matrixWS->y(i).size() > 1) {
888 multipleBins = true;
889 break;
890 }
891 }
892 }
893 m_plotSpec->setEnabled(multipleBins);
894 m_plotSpecErr->setEnabled(multipleBins);
895 m_plotAdvanced->setEnabled(multipleBins);
896
897 menu->addAction(m_showSpectrumViewer); // The 2D spectrum viewer
898
899 menu->addAction(m_colorFill);
900 // Show the color fill plot if you have more than one histogram
901 m_colorFill->setEnabled((matrixWS->axes() > 1 && matrixWS->getNumberHistograms() > 1));
902 menu->addAction(m_showSliceViewer); // The 2D slice viewer
903 menu->addSeparator();
904 menu->addAction(m_showDetectors);
905 menu->addAction(m_showLogs);
906 menu->addAction(m_showSampleMaterial);
907 menu->addAction(m_showHist);
908 menu->addAction(m_saveNexus);
909}
910
918 Q_UNUSED(WS);
919
920 // menu->addAction(m_showBoxData); // Show MD Box data (for debugging only)
921 menu->addAction(m_showSliceViewer); // The 2D slice viewer
922 menu->addAction(m_showHist); // Algorithm history
923 menu->addAction(m_showListData); // Show data in table
924 menu->addAction(m_showLogs);
925}
926
928 const Mantid::API::IMDWorkspace_const_sptr &WS) const {
929 Q_UNUSED(WS);
930 menu->addAction(m_showHist); // Algorithm history
931 menu->addAction(m_showSliceViewer); // The 2D slice viewer
932 menu->addAction(m_showMDPlot); // A plot of intensity vs bins
933 menu->addAction(m_showListData); // Show data in table
934 menu->addAction(m_convertMDHistoToMatrixWorkspace);
935 menu->addAction(m_showLogs);
936}
937
944 Q_UNUSED(WS);
945 menu->addAction(m_showData);
946 menu->addSeparator();
947 menu->addAction(m_showDetectors);
948 menu->addAction(m_showHist);
949}
950
956 m_plotSpec->setEnabled(true);
957 menu->addAction(m_plotSpec);
958 m_plotSpecErr->setEnabled(true);
959 menu->addAction(m_plotSpecErr);
960 m_plotAdvanced->setEnabled(true);
961 menu->addAction(m_plotAdvanced);
962 menu->addAction(m_colorFill);
963 m_colorFill->setEnabled(true);
964
965 menu->addSeparator();
966 menu->addAction(m_saveNexus);
967}
968
974 menu->addAction(m_showData);
975 menu->addAction(m_showTransposed);
976 menu->addAction(m_showHist);
977 menu->addAction(m_saveNexus);
978 menu->addAction(m_convertToMatrixWorkspace);
979}
980
986void WorkspaceTreeWidget::addClearMenuItems(QMenu *menu, const QString &wsName) {
987 QMenu *clearMenu = new QMenu(tr("Clear Options"), this);
988
989 m_clearUB->setEnabled(hasUBMatrix(wsName.toStdString()));
990
991 clearMenu->addAction(m_clearUB);
992 menu->addMenu(clearMenu);
993}
994
995bool WorkspaceTreeWidget::hasUBMatrix(const std::string &wsName) {
996 bool hasUB = false;
997 Workspace_sptr ws = AnalysisDataService::Instance().retrieve(wsName);
998 IMDWorkspace_sptr wsIMD = std::dynamic_pointer_cast<IMDWorkspace>(ws);
999 if (ws && wsIMD) {
1000 hasUB = wsIMD->hasOrientedLattice();
1001 }
1002 return hasUB;
1003}
1004
1012void WorkspaceTreeWidget::addSaveMenuOption(const QString &algorithmString, QString menuEntryName) {
1013 // Default to algo string if no entry name given
1014 if (menuEntryName.isEmpty())
1015 menuEntryName = algorithmString;
1016
1017 // Create the action and add data
1018 QAction *saveAction = new QAction(menuEntryName, this);
1019 saveAction->setData(QVariant(algorithmString));
1020
1021 // Connect the trigger slot to show algorithm dialog
1022 connect(saveAction, SIGNAL(triggered()), this, SLOT(handleShowSaveAlgorithm()));
1023
1024 // Add it to the menu
1025 m_saveMenu->addAction(saveAction);
1026}
1027
1033 m_filteredText = text.toStdString();
1035}
1036
1040}
1041
1047 return askUserYesNo("Clear Workspaces", "This will delete all the workspaces, are you sure?");
1048}
1049
1054void WorkspaceTreeWidget::enableClearButton(bool enable) { m_clearButton->setEnabled(enable); }
1055
1059}
1060
1061void WorkspaceTreeWidget::clickedWorkspace(QTreeWidgetItem *item, int /*unused*/) { Q_UNUSED(item); }
1062
1064 auto selectedNames = getSelectedWorkspaceNames();
1065 if (selectedNames.empty())
1066 return;
1067
1068 // If there are multiple workspaces selected group and save as Nexus
1069 if (selectedNames.size() > 1) {
1070 connect(m_saveButton, SIGNAL(clicked()), this, SLOT(saveWorkspaceCollection()));
1071
1072 // Don't display as a group
1073 m_saveButton->setMenu(nullptr);
1074 } else {
1075 // Don't run the save group function when clicked
1076 disconnect(m_saveButton, SIGNAL(clicked()), this, SLOT(saveWorkspaceCollection()));
1077
1078 // Remove all existing save algorithms from list
1079 m_saveMenu->clear();
1080
1081 // Add some save algorithms
1082 addSaveMenuOption("SaveNexus", "Nexus");
1083 addSaveMenuOption("SaveAscii", "ASCII");
1084
1085 // Set the button to show the menu
1086 m_saveButton->setMenu(m_saveMenu);
1087 }
1088
1089 auto wsName = selectedNames[0];
1090 // TODO: Wire signal correctly in applicationwindow
1091 m_mantidDisplayModel->enableSaveNexus(QString::fromStdString(wsName));
1092}
1093
1096 if (m_groupButton) {
1097 QString qButtonName = m_groupButton->text();
1098 if (qButtonName == "Group") {
1100 } else if (qButtonName == "Ungroup") {
1102 }
1103 }
1104}
1105
1108
1112}
1113
1114// Asynchronous signal handlers
1118 // do not update until the counter is zero
1119 if (m_updateCount.deref())
1120 return;
1121
1122 // find all expanded top-level entries
1123 QStringList expanded;
1124 int n = m_tree->topLevelItemCount();
1125 for (int i = 0; i < n; ++i) {
1126 auto item = m_tree->topLevelItem(i);
1127 if (item->isExpanded()) {
1128 expanded << item->text(0);
1129 }
1130 }
1131
1132 // create a new tree
1133 setTreeUpdating(true);
1134 populateTopLevel(items, expanded);
1135 setTreeUpdating(false);
1136
1137 // enable clear button here if any items in tree
1138 enableClearButton(!items.empty());
1139
1140 // Re-sort
1141 m_tree->sort();
1142}
1143
1146 m_tree->clear();
1147}
1148
1149// Context Menu Methods
1150
1152void WorkspaceTreeWidget::popupMenu(const QPoint &pos) {
1153 if (!m_viewOnly) {
1154 m_menuPosition = pos;
1156 }
1157}
1158
1160 QTreeWidgetItem *treeItem = m_tree->itemAt(m_menuPosition);
1161 selectedWsName = "";
1162 if (treeItem)
1163 selectedWsName = treeItem->text(0);
1164 else
1165 m_tree->selectionModel()->clear();
1166
1167 QMenu *menu(nullptr);
1168
1169 // If no workspace is here then have load raw and dae
1170 if (selectedWsName.isEmpty())
1171 menu = m_loadMenu;
1172 else { // else show instrument, sample logs and delete
1173 // Fresh menu
1174 menu = new QMenu(this);
1175 menu->setObjectName("WorkspaceContextMenu");
1176 auto mantidTreeItem = dynamic_cast<MantidTreeWidgetItem *>(treeItem);
1177 auto ws = mantidTreeItem->data(0, Qt::UserRole).value<Mantid::API::Workspace_sptr>();
1178
1179 // Add the items that are appropriate for the type
1180 if (auto matrixWS = std::dynamic_pointer_cast<const Mantid::API::MatrixWorkspace>(ws)) {
1181 addMatrixWorkspaceMenuItems(menu, matrixWS);
1182 } else if (auto mdeventWS = std::dynamic_pointer_cast<const IMDEventWorkspace>(ws)) {
1183 addMDEventWorkspaceMenuItems(menu, mdeventWS);
1184 } else if (auto mdWS = std::dynamic_pointer_cast<const IMDWorkspace>(ws)) {
1185 addMDHistoWorkspaceMenuItems(menu, mdWS);
1186 } else if (auto peaksWS = std::dynamic_pointer_cast<const IPeaksWorkspace>(ws)) {
1187 addPeaksWorkspaceMenuItems(menu, peaksWS);
1188 } else if (auto groupWS = std::dynamic_pointer_cast<const WorkspaceGroup>(ws)) {
1190 } else if (std::dynamic_pointer_cast<const Mantid::API::ITableWorkspace>(ws)) {
1192 } else {
1193 // None of the above? -> not a workspace
1194 return;
1195 }
1197
1198 // Get the names of the programs for the send to option
1199 std::vector<std::string> programNames =
1200 (Mantid::Kernel::ConfigService::Instance().getKeys("workspace.sendto.name"));
1201 bool firstPass(true);
1202 // Check to see if any options aren't visible
1203 for (auto &programName : programNames) {
1204 std::string visible =
1205 Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programName + ".visible");
1206 std::string target =
1207 Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programName + ".target");
1208 if (Mantid::Kernel::ConfigService::Instance().isExecutable(target) && visible == "Yes") {
1209 bool compatible(true);
1210 std::string saveUsing(
1211 Mantid::Kernel::ConfigService::Instance().getString("workspace.sendto." + programName + ".saveusing"));
1212 try {
1214 alg->setPropertyValue("InputWorkspace", selectedWsName.toStdString());
1215 } catch (std::exception &) {
1216 compatible = false;
1217 }
1218 if (compatible) {
1219 if (firstPass) {
1220 m_saveToProgram = new QMenu(tr("Send to"), this);
1221 menu->addMenu(m_saveToProgram);
1222
1223 // Sub-menu for program list
1224 m_programMapper = new QSignalMapper(this);
1225 }
1226 QString name = QString::fromStdString(programName);
1227 // Setup new menu option for the program
1228 m_program = new QAction(name, this);
1229 connect(m_program, SIGNAL(triggered()), m_programMapper, SLOT(map()));
1230 // Send name of program when clicked
1231 m_programMapper->setMapping(m_program, name);
1232 m_saveToProgram->addAction(m_program);
1233
1234 // Set first pass to false so that it doesn't set up another menu
1235 // entry for all programs.
1236 firstPass = false;
1237 }
1238 }
1239 }
1240
1241 // Tell the button what to listen for and what to do once clicked (if there
1242 // is anything to connect it will be set to false)
1243 if (!firstPass)
1244 connect(m_programMapper, SIGNAL(mapped(const QString &)), this, SLOT(onClickSaveToProgram(const QString &)));
1245
1246 // Rename is valid for all workspace types
1247 menu->addAction(m_rename);
1248 // separate delete
1249 menu->addSeparator();
1250 menu->addAction(m_delete);
1251 }
1252
1253 // Show the menu at the cursor's current position
1254 menu->popup(QCursor::pos());
1255}
1256
1258
1260
1263}
1264
1266
1268 m_programName = name;
1270}
1271
1276 // Create a map for the keys and details to go into
1277 std::map<std::string, std::string> programKeysAndDetails;
1278 programKeysAndDetails["name"] = m_programName.toStdString();
1279
1280 // Get a list of the program detail keys (mandatory - target, saveusing)
1281 // (optional - arguments, save parameters, workspace type)
1282 std::vector<std::string> programKeys = (Mantid::Kernel::ConfigService::Instance().getKeys(
1283 ("workspace.sendto." + programKeysAndDetails.find("name")->second)));
1284
1285 for (const auto &programKey : programKeys) {
1286 // Assign a key to its value using the map
1287 programKeysAndDetails[programKey] = (Mantid::Kernel::ConfigService::Instance().getString(
1288 ("workspace.sendto." + programKeysAndDetails.find("name")->second + "." + programKey)));
1289 }
1290
1291 // Check to see if mandatory information is included
1292 if ((programKeysAndDetails.count("name") != 0) && (programKeysAndDetails.count("target") != 0) &&
1293 (programKeysAndDetails.count("saveusing") != 0)) {
1294 std::string expTarget = Poco::Path::expand(programKeysAndDetails.find("target")->second);
1295
1296 QFileInfo target = QString::fromStdString(expTarget);
1297 if (target.exists()) {
1298 try {
1299 // Convert to QString and create Algorithm
1300 QString saveUsing = QString::fromStdString(programKeysAndDetails.find("saveusing")->second);
1301
1302 // Create a new save based on what files the new program can open
1303 auto alg = m_mantidDisplayModel->createAlgorithm(saveUsing);
1304
1305 // Get the file extention based on the workspace
1306 Property *prop = alg->getProperty("Filename");
1307 auto *fileProp = dynamic_cast<FileProperty *>(prop);
1308 std::string ext;
1309 if (fileProp) {
1310 ext = fileProp->getDefaultExt();
1311 }
1312
1313 // Save as.. default save + the file type i.e .nxs
1314 alg->setPropertyValue("fileName", "auto_save_" + selectedWsName.toStdString() + ext);
1315
1316 // Save the workspace
1317 alg->setPropertyValue("InputWorkspace", selectedWsName.toStdString());
1318
1319 // If there are any save parameters
1320 if (programKeysAndDetails.count("saveparameters") != 0) {
1321 QString saveParametersGrouped = QString::fromStdString(programKeysAndDetails.find("saveparameters")->second);
1322 QStringList saveParameters = saveParametersGrouped.split(',');
1323
1324 // For each one found split it up and assign the parameter
1325 for (int i = 0; i < saveParameters.size(); i++) {
1326 QStringList sPNameAndDetail = saveParameters[i].split('=');
1327 std::string saveParameterName = sPNameAndDetail[0].trimmed().toStdString();
1328 std::string saveParameterDetail = sPNameAndDetail[1].trimmed().toStdString();
1329 if (saveParameterDetail == "True")
1330 alg->setProperty(saveParameterName, true);
1331 else if (saveParameterDetail == "False")
1332 alg->setProperty(saveParameterName, false);
1333 else // if not true or false then must be a value
1334 {
1335 alg->setPropertyValue(saveParameterName, saveParameterDetail);
1336 }
1337 }
1338 }
1339
1340 // Execute the save
1341 executeAlgorithmAsync(alg, true);
1342
1343 // Get the save location of the file (should be default Mantid folder)
1344 QString savedFile = QString::fromStdString(alg->getProperty("Filename"));
1345 QStringList arguments;
1346
1347 // Arguments for the program to take. Default will be the file anyway.
1348 if (programKeysAndDetails.count("arguments") != 0) {
1349 QString temp = QString::fromStdString(programKeysAndDetails.find("arguments")->second);
1350 temp.replace(QString("[file]"), savedFile);
1351 // temp.replace(QString("[user]"), user;
1352 arguments = temp.split(",");
1353 } else
1354 arguments.insert(0, savedFile);
1355
1356 // convert the list into a standard vector for compatibility with Poco
1357 std::vector<std::string> argumentsV;
1358
1359 for (int i = 0; i < arguments.size(); i++) {
1360 argumentsV.assign(1, (arguments[i].toStdString()));
1361 }
1362
1363 // Execute the program
1364 try {
1365 Mantid::Kernel::ConfigService::Instance().launchProcess(expTarget, argumentsV);
1366 } catch (std::runtime_error &) {
1367 QMessageBox::information(this, "Error",
1368 "User tried to open program from: " + QString::fromStdString(expTarget) +
1369 " There was an error opening the program. "
1370 "Please check the target and arguments list "
1371 "to ensure that these are correct");
1372 }
1373 } catch (std::exception &) {
1374 QMessageBox::information(this, "Mantid - Send to Program",
1375 "A file property wasn't found. Please check that the correct" +
1376 QString("save algorithm was used.\n(View -> Preferences -> "
1377 "Mantid -> SendTo -> Edit -> SaveUsing)"));
1378 }
1379 } else
1380 QMessageBox::information(this, "Target Path Error",
1381 "User tried to open program from: " + QString::fromStdString(expTarget) +
1382 " The target file path for the program "
1383 "can't be found. Please check that the full "
1384 "path is correct");
1385 }
1386}
1387
1389
1392}
1393
1396}
1397
1401void WorkspaceTreeWidget::plotSpectrum(const std::string &type) {
1402 const bool isAdvanced = type == "Advanced";
1403 const auto userInput = m_tree->chooseSpectrumFromSelected(true, true, true, isAdvanced);
1404 // An empty map will be returned if the user clicks cancel in the spectrum
1405 // selection
1406 if (userInput.plots.empty()) {
1407 return;
1408 }
1409 bool showErrorBars = ((type == "Errors") || (type == "Advanced" && userInput.errors));
1410
1411 // mantidUI knows nothing about userInput, hence the long argument lists.
1412 if (userInput.tiled) {
1413 m_mantidDisplayModel->plotSubplots(userInput.plots, MantidQt::DistributionDefault, showErrorBars);
1414 } else if (userInput.simple || userInput.waterfall) {
1415 if (userInput.isAdvanced) {
1416 m_mantidDisplayModel->plot1D(userInput.plots, true, MantidQt::DistributionDefault, showErrorBars, nullptr, false,
1417 userInput.waterfall, userInput.advanced.logName, userInput.advanced.customLogValues);
1418 } else {
1419 m_mantidDisplayModel->plot1D(userInput.plots, true, MantidQt::DistributionDefault, showErrorBars, nullptr, false,
1420 userInput.waterfall);
1421 }
1422
1423 } else if (userInput.surface) {
1424 m_mantidDisplayModel->plotSurface(userInput.advanced.accepted, userInput.advanced.plotIndex,
1425 userInput.advanced.axisName, userInput.advanced.logName,
1426 userInput.advanced.customLogValues, userInput.advanced.workspaceNames);
1427 } else if (userInput.contour) {
1428 m_mantidDisplayModel->plotContour(userInput.advanced.accepted, userInput.advanced.plotIndex,
1429 userInput.advanced.axisName, userInput.advanced.logName,
1430 userInput.advanced.customLogValues, userInput.advanced.workspaceNames);
1431 }
1432}
1433
1436}
1437
1444 // Get the selected workspaces
1445 auto items = m_tree->selectedItems();
1446 if (items.empty())
1447 return;
1448
1449 // Extract child workspace names from any WorkspaceGroups selected.
1450 // Use a list to preserve workspace order.
1451 QStringList allWsNames;
1452
1453 for (auto &item : items) {
1454 auto ws = item->data(0, Qt::UserRole).value<Workspace_sptr>();
1455
1456 if (auto wsGroup = std::dynamic_pointer_cast<WorkspaceGroup>(ws)) {
1457 for (auto &name : wsGroup->getNames())
1458 allWsNames.append(QString::fromStdString(name));
1459 } else
1460 allWsNames.append(item->text(0));
1461 }
1462
1463 // remove duplicate workspace entries
1464 allWsNames.removeDuplicates();
1465
1467}
1468
1470 switch (e->key()) {
1471 case Qt::Key_Delete:
1472 case Qt::Key_Backspace:
1474 break;
1475 }
1476}
1477
1480}
1481
1483 // get selected workspace
1484 auto ws = QString::fromStdString(getSelectedWorkspaceNames()[0]);
1485 auto table = m_mantidDisplayModel->createDetectorTable(ws, std::vector<int>(), false);
1486 if (!table) {
1487 QMessageBox::information(this, "Error", QString("Cannot create detectors tables for workspace ") + ws);
1488 }
1489}
1490
1492
1494
1496
1498
1500
1502
1505}
1506
1508
1511}
1512
1514
1516
1518
1521}
1522
1524
1527}
1528
1530
1532
1534
1538}
1544}
1545
1551}
1552
1554 m_mantidDisplayModel->showAlgorithmDialog("ConvertTableToMatrixWorkspace");
1555}
1556
1558 m_mantidDisplayModel->showAlgorithmDialog("ConvertMDHistoToMatrixWorkspace");
1559}
1560
1565
1575}
1576
1578 m_loadButton->hide();
1579 m_saveButton->hide();
1580 m_deleteButton->hide();
1581 m_clearButton->hide();
1582 m_groupButton->hide();
1583 m_sortButton->hide();
1584}
1585
1586} // namespace MantidQt::MantidWidgets
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
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.
Definition: FileProperty.h:42
std::string getDefaultExt() const
Returns the main file extension that's used.
Definition: FileProperty.h:90
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
Base class for properties.
Definition: Property.h:94
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
EXPORT_OPT_MANTIDQT_COMMON QPixmap getQPixmap(const std::string &name)
Function that returns a QPixmap given a string name.
Definition: pixmaps.cpp:12823
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
Definition: Workspace_fwd.h:20
std::shared_ptr< const IMDWorkspace > IMDWorkspace_const_sptr
Shared pointer to the IMDWorkspace base class (const version)
Definition: IMDWorkspace.h:148
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.
Definition: IMDWorkspace.h:146
std::shared_ptr< const IPeaksWorkspace > IPeaksWorkspace_const_sptr
shared pointer to Mantid::API::IPeaksWorkspace (const version)