Mantid
Loading...
Searching...
No Matches
WorkspaceTreeWidget.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2016 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 +
7#pragma once
8
11
20
22#include <QDockWidget>
23#include <QHash>
24#include <QMap>
25#include <QMetaType>
26#include <QMutex>
27#include <map>
28#include <memory>
29
30class QMainWindow;
31class QLabel;
32class QFileDialog;
33class QLineEdit;
34class QActionGroup;
35class QMenu;
36class QPushButton;
37class QTreeWidget;
38class QTreeWidgetItem;
39class QProgressBar;
40class QVBoxLayout;
41class QHBoxLayout;
42class QSignalMapper;
43class QSortFilterProxyModel;
44
45using TopLevelItems = std::map<std::string, Mantid::API::Workspace_sptr>;
46Q_DECLARE_METATYPE(TopLevelItems)
47
48namespace MantidQt {
49namespace MantidWidgets {
50class MantidDisplayBase;
51class MantidTreeWidgetItem;
52class MantidTreeWidget;
53
61 Q_OBJECT
62public:
64 QWidget *parent = nullptr);
66 void dropEvent(QDropEvent *de) override;
67
68 MantidQt::MantidWidgets::WorkspacePresenterWN_wptr getPresenterWeakPtr() override;
69
70 SortDirection getSortDirection() const override;
71 SortCriteria getSortCriteria() const override;
72 void sortWorkspaces(SortCriteria criteria, SortDirection direction) override;
73
74 MantidQt::MantidWidgets::StringList getSelectedWorkspaceNames() const override;
75 // Horrible second function to get a return value as QStringList directly
76 QStringList getSelectedWorkspaceNamesAsQList() const;
77 Mantid::API::Workspace_sptr getSelectedWorkspace() const override;
78
79 bool askUserYesNo(const std::string &caption, const std::string &message) const override;
80 void showCriticalUserMessage(const std::string &caption, const std::string &message) const override;
81
82 void showLoadDialog() override;
83 void showLiveDataDialog() override;
84 void showRenameDialog(const MantidQt::MantidWidgets::StringList &wsNames) override;
85 void enableDeletePrompt(bool enable) override;
86 bool isPromptDelete() const override;
87 bool deleteConfirmation() const override;
88 void deleteWorkspaces(const MantidQt::MantidWidgets::StringList &wsNames) override;
89 bool clearWorkspacesConfirmation() const override;
90 void enableClearButton(bool enable) override;
91 void clearView() override;
92 std::string getFilterText() const override;
93 SaveFileType getSaveFileType() const override;
94 void saveWorkspace(const std::string &wsName, SaveFileType type) override;
95 void saveWorkspaces(const MantidQt::MantidWidgets::StringList &wsNames) override;
96 void filterWorkspaces(const std::string &filterText) override;
97 void recordWorkspaceRename(const std::string &oldName, const std::string &newName) override;
98 void refreshWorkspaces() override;
99
100 // Context Menu Handlers
101 void popupContextMenu() override;
102 void showWorkspaceData() override;
103 void saveToProgram() override;
104 void showInstrumentView() override;
105 void plotSpectrum(const std::string &type) override;
106 void showColourFillPlot() override;
107 void showDetectorsTable() override;
108 void showBoxDataTable() override;
109 void showMDPlot() override;
110 void showListData() override;
111 void showSpectrumViewer() override;
112 void showSliceViewer() override;
113 void showLogs() override;
114 void showSampleMaterialWindow() override;
115 void showAlgorithmHistory() override;
116 void showTransposed() override;
117 void convertToMatrixWorkspace() override;
118 void convertMDHistoToMatrixWorkspace() override;
119
120 bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, const bool wait = true) override;
121
122private:
123 bool hasUBMatrix(const std::string &wsName);
124 void addSaveMenuOption(const QString &algorithmString, QString menuEntryName = "");
125 void setTreeUpdating(const bool state);
126 inline bool isTreeUpdating() const { return m_treeUpdating; }
127 void updateTree(const TopLevelItems &items) override;
128 void populateTopLevel(const TopLevelItems &topLevelItems, const QStringList &expanded);
129 MantidTreeWidgetItem *addTreeEntry(const std::pair<std::string, Mantid::API::Workspace_sptr> &item,
130 QTreeWidgetItem *parent = nullptr);
131 bool shouldBeSelected(const QString &name) const;
132 void createWorkspaceMenuActions();
133 void createSortMenuActions();
134 void setItemIcon(QTreeWidgetItem *item, const std::string &wsID);
135
136 void addMatrixWorkspaceMenuItems(QMenu *menu, const Mantid::API::MatrixWorkspace_const_sptr &matrixWS) const;
137 void addMDEventWorkspaceMenuItems(QMenu *menu, const Mantid::API::IMDEventWorkspace_const_sptr &mdeventWS) const;
138 void addMDHistoWorkspaceMenuItems(QMenu *menu, const Mantid::API::IMDWorkspace_const_sptr &WS) const;
139 void addPeaksWorkspaceMenuItems(QMenu *menu, const Mantid::API::IPeaksWorkspace_const_sptr &WS) const;
140 void addWorkspaceGroupMenuItems(QMenu *menu) const;
141 void addTableWorkspaceMenuItems(QMenu *menu) const;
142 void addClearMenuItems(QMenu *menu, const QString &wsName);
143
144 void excludeItemFromSort(MantidTreeWidgetItem *item);
145
146 void setupWidgetLayout();
147 void setupLoadButtonMenu();
148 void setupConnections();
149 void hideButtonToolbar();
150
151 MantidQt::MantidWidgets::MantidItemSortScheme whichCriteria(SortCriteria criteria);
152
153public slots:
154 void clickedWorkspace(QTreeWidgetItem * /*item*/, int /*unused*/);
155 void saveWorkspaceCollection();
156 void onClickDeleteWorkspaces();
157 void onClickClearWorkspaces();
158 void renameWorkspace();
159 void populateChildData(QTreeWidgetItem *item);
160 void onClickSaveToProgram(const QString &name);
161 void sortAscending();
162 void sortDescending();
163 void chooseByName();
164 void chooseByLastModified();
165 void chooseByMemorySize();
166 void keyPressEvent(QKeyEvent * /*unused*/) override;
167
168protected slots:
169 void popupMenu(const QPoint &pos);
170 void workspaceSelected();
171
172private slots:
173 void handleShowSaveAlgorithm();
174 void onTreeSelectionChanged();
175 void onClickGroupButton();
176 void onClickLoad();
177 void onLoadAccept();
178 void onClickLiveData();
179 void onClickShowData();
180 void onClickShowInstrument();
181 void onClickShowBoxData();
182 void onClickShowMDPlot();
183 void onClickShowListData();
184 void onClickShowSpectrumViewer();
185 void onClickShowSliceViewer();
186 void onClickShowFileLog();
187 void onClickSaveNexusWorkspace();
188 void onClickShowTransposed();
189 void onClickPlotSpectra();
190 void onClickPlotSpectraErr();
191 void onClickPlotAdvanced();
192 void onClickDrawColorFillPlot();
193 void onClickShowDetectorTable();
194 void onClickConvertToMatrixWorkspace();
195 void onClickConvertMDHistoToMatrixWorkspace();
196 void onClickShowAlgHistory();
197 void onClickShowSampleMaterial();
198 void onClickClearUB();
199 void incrementUpdateCount();
200 void filterWorkspaceTree(const QString &text);
201
202private:
204
205protected:
209 QMenu *m_loadMenu, *m_saveToProgram;
210 QSignalMapper *m_programMapper;
211 QAction *m_program, *m_saveNexus, *m_rename, *m_delete;
212
213private:
216
217 std::string m_filteredText;
218 QPushButton *m_loadButton;
219 QPushButton *m_saveButton;
220 QPushButton *m_deleteButton;
221 QPushButton *m_clearButton;
222 QPushButton *m_groupButton;
223 QPushButton *m_sortButton;
225 QActionGroup *m_sortChoiceGroup;
226 QFileDialog *m_saveFolderDialog;
228
229 QMenu *m_sortMenu, *m_saveMenu;
230 // Context-menu actions
231 QAction *m_showData, *m_showInst, *m_plotSpec, *m_plotSpecErr, *m_plotAdvanced, *m_showDetectors, *m_showBoxData,
232 *m_showSpectrumViewer, *m_showSliceViewer, *m_colorFill, *m_showLogs, *m_showSampleMaterial, *m_showHist,
233 *m_showMDPlot, *m_showListData, *m_ascendingSortAction, *m_descendingSortAction, *m_byNameChoice,
234 *m_byLastModifiedChoice, *m_showTransposed, *m_convertToMatrixWorkspace, *m_convertMDHistoToMatrixWorkspace,
236
237 QAtomicInt m_updateCount;
245 QStringList m_selectedNames;
249 mutable QMutex m_mutex;
250
251private slots:
252 void handleUpdateTree(const TopLevelItems & /*items*/);
253 void handleClearView();
254signals:
256 void signalUpdateTree(const TopLevelItems & /*_t1*/);
257};
258} // namespace MantidWidgets
259} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
std::map< std::string, Mantid::API::Workspace_sptr > TopLevelItems
A class derived from QTreeWidgetItem, to accomodate sorting on the items in a MantidTreeWidget.
QMutex m_mutex
A mutex to lock m_renameMap and m_selectedNames for reading/writing.
MantidQt::MantidWidgets::WorkspacePresenterVN_sptr m_presenter
void signalUpdateTree(const TopLevelItems &)
QHash< QString, QString > m_renameMap
Keep a map of renamed workspaces between updates.
QStringList m_selectedNames
Temporarily keeps names of selected workspaces during tree update in order to restore selection after...
std::shared_ptr< ViewNotifiable > WorkspacePresenterVN_sptr
std::vector< std::string > StringList
std::weak_ptr< WorkspaceProviderNotifiable > WorkspacePresenterWN_wptr
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
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)
void renameWorkspace(const IAlgorithm_sptr &renamer, const Workspace_sptr &workspace, const std::string &newName)
std::shared_ptr< const IPeaksWorkspace > IPeaksWorkspace_const_sptr
shared pointer to Mantid::API::IPeaksWorkspace (const version)