24#include <QSignalMapper>
38 for (
size_t i = 0; i < numHist; ++i) {
39 if (ws.
y(i).size() > 1) {
52 m_plotBin(new QAction(
"Bin", this)), m_overplotSpectrum(new QAction(
"Overplot spectrum...", this)),
53 m_plotSpectrumWithErrs(new QAction(
"Spectrum with errors...", this)),
54 m_overplotSpectrumWithErrs(new QAction(
"Overplot spectrum with errors...", this)),
55 m_plotColorfill(new QAction(
"Colorfill", this)), m_sampleLogs(new QAction(
"Show Sample Logs", this)),
56 m_sliceViewer(new QAction(
"Show Slice Viewer", this)), m_showInstrument(new QAction(
"Show Instrument", this)),
57 m_showData(new QAction(
"Show Data", this)), m_showAlgorithmHistory(new QAction(
"Show History", this)),
58 m_showDetectors(new QAction(
"Show Detectors", this)), m_plotAdvanced(new QAction(
"Advanced...", this)),
59 m_plotSurface(new QAction(
"Surface", this)), m_plotWireframe(new QAction(
"Wireframe", this)),
60 m_plotContour(new QAction(
"Contour", this)), m_plotMDHisto1D(new QAction(
"Plot 1D MDHistogram...", this)),
61 m_overplotMDHisto1D(new QAction(
"Overplot 1D MDHistogram...", this)),
62 m_plotMDHisto1DWithErrs(new QAction(
"Plot 1D MDHistogram with errors...", this)),
63 m_overplotMDHisto1DWithErrs(new QAction(
"Overplot 1D MDHistogram with errors...", this)),
64 m_sampleMaterial(new QAction(
"Show Sample Material", this)),
65 m_sampleShape(new QAction(
"Show Sample Shape", this)), m_superplot(new QAction(
"Superplot...", this)),
66 m_superplotWithErrs(new QAction(
"Superplot with errors...", this)),
67 m_superplotBins(new QAction(
"Superplot bins...", this)),
68 m_superplotBinsWithErrs(new QAction(
"Superplot bins with errors...", this)),
69 m_showNewInstrumentView(new QAction(
"(Experimental) Show Instrument", this)), m_separator(new QAction()) {
121 m_tree->selectionModel()->clear();
123 QMenu *menu(
nullptr);
132 menu->popup(QCursor::pos());
233 auto menu =
new QMenu(
this);
234 menu->setAttribute(Qt::WA_DeleteOnClose,
true);
235 menu->setObjectName(
"WorkspaceContextMenu");
237 std::vector<Workspace_sptr> workspaces;
238 std::vector<MenuActions> actionVecs;
239 std::vector<MenuActions> plotMenuActionVecs;
240 std::vector<MenuActions> plotMenu3DActionVecs;
241 for (
const auto &workspaceName : selectedWorkspaces) {
244 workspace = AnalysisDataService::Instance().retrieve(workspaceName.toStdString());
249 if (
auto matrixWS = std::dynamic_pointer_cast<MatrixWorkspace>(
workspace)) {
251 actionVecs.push_back(actions);
252 plotMenuActionVecs.push_back(plotActions.plotActions);
253 plotMenu3DActionVecs.push_back(plotActions.plot3DActions);
254 }
else if (
auto tableWS = std::dynamic_pointer_cast<ITableWorkspace>(
workspace)) {
258 }
else if (
auto mdWS = std::dynamic_pointer_cast<IMDWorkspace>(
workspace)) {
260 actionVecs.push_back(actions);
261 plotMenuActionVecs.push_back(plotActions.plotActions);
262 plotMenu3DActionVecs.push_back(plotActions.plot3DActions);
263 }
else if (
auto wsGroup = std::dynamic_pointer_cast<WorkspaceGroup>(
workspace)) {
265 actionVecs.push_back(actions);
266 plotMenuActionVecs.push_back(plotActions.plotActions);
267 plotMenu3DActionVecs.push_back(plotActions.plot3DActions);
275 const auto it = std::find(combinedActions.cbegin(), combinedActions.cend(),
m_showInstrument);
276 if (it != combinedActions.cend()) {
278 return workspace->getInstrument() && !
workspace->getInstrument()->getName().empty() &&
282 std::all_of(workspaces.cbegin(), workspaces.cend(), [&showInstrumentViewCheck](
const Workspace_sptr &ws) {
283 if (const auto matrixWS = std::dynamic_pointer_cast<MatrixWorkspace>(ws)) {
284 return showInstrumentViewCheck(matrixWS);
292 if (!combinedPlotMenuActions.empty()) {
293 auto *plotSubMenu =
new QMenu(
"Plot", menu);
294 for (
const auto &action : combinedPlotMenuActions) {
295 plotSubMenu->addAction(action);
297 if (!combined3DPlotMenuActions.empty()) {
298 auto *plot3DMenu =
new QMenu(
"3D", menu);
299 for (
const auto &action : combined3DPlotMenuActions) {
300 plot3DMenu->addAction(action);
302 plotSubMenu->addMenu(plot3DMenu);
304 menu->addMenu(plotSubMenu);
307 for (
const auto &action : combinedActions) {
308 menu->addAction(action);
312 addGeneralWorkspaceActions(menu);
317MenuActions WorkspaceTreeWidgetSimple::intersectionOfActions(std::vector<MenuActions> actionVecs) {
318 if (actionVecs.empty()) {
321 std::sort(actionVecs.begin(), actionVecs.end(), [](
const auto &a,
const auto &b) { return a.size() > b.size(); });
324 std::erase_if(combinedActions, [&actionVecs](QAction *action) {
325 return (!std::all_of(actionVecs.cbegin() + 1, actionVecs.cend(), [&action](
const MenuActions &actionVec) {
326 const auto it = std::find(actionVec.cbegin(), actionVec.cend(), action);
327 return it != actionVec.cend();
331 return combinedActions;
334std::tuple<MenuActions, PlotMenuActions>
339 actions.push_back(m_showData);
343 auto plotActions = createMatrixWorkspacePlotMenu(hasMultipleBins(
workspace));
344 actions.push_back(m_separator);
345 actions.push_back(m_showData);
346 actions.push_back(m_showAlgorithmHistory);
347 actions.push_back(m_showInstrument);
348 actions.push_back(m_sampleLogs);
349 actions.push_back(m_sliceViewer);
350 actions.push_back(m_showDetectors);
351 if (m_tree->selectedItems().size() == 1) {
352 actions.push_back(m_sampleMaterial);
353 actions.push_back(m_sampleShape);
355 actions.push_back(m_showNewInstrumentView);
356 return std::make_tuple(actions, plotActions);
361 actions.push_back(m_showData);
362 actions.push_back(m_showAlgorithmHistory);
364 actions.push_back(m_showDetectors);
369std::tuple<MenuActions, PlotMenuActions>
373 actions.push_back(m_showAlgorithmHistory);
374 actions.push_back(m_sampleLogs);
377 bool addSliceViewer =
false;
378 bool add1DPlot =
false;
383 auto num_dims =
workspace.getNumNonIntegratedDims();
388 }
else if (num_dims > 1) {
391 addSliceViewer =
true;
394 addSliceViewer =
true;
397 if (addSliceViewer) {
398 actions.push_back(m_sliceViewer);
399 }
else if (add1DPlot) {
400 plotMenu.
plotActions = {m_plotMDHisto1D, m_overplotMDHisto1D, m_plotMDHisto1DWithErrs, m_overplotMDHisto1DWithErrs};
402 return std::make_tuple(actions, plotMenu);
405std::tuple<MenuActions, PlotMenuActions>
409 auto workspaces =
workspace.getAllItems();
410 bool containsMatrixWorkspace{
false};
411 bool containsPeaksWorkspace{
false};
412 for (
const auto &ws : workspaces) {
413 if (std::dynamic_pointer_cast<MatrixWorkspace>(ws)) {
414 containsMatrixWorkspace =
true;
416 }
else if (std::dynamic_pointer_cast<IPeaksWorkspace>(ws)) {
417 containsPeaksWorkspace =
true;
423 if (containsMatrixWorkspace) {
424 plotMenu = createMatrixWorkspacePlotMenu(
true);
425 actions.push_back(m_separator);
426 actions.push_back(m_showDetectors);
429 if (containsPeaksWorkspace) {
430 actions.push_back(m_showData);
431 actions.push_back(m_showDetectors);
433 return std::make_tuple(actions, plotMenu);
436void WorkspaceTreeWidgetSimple::addGeneralWorkspaceActions(QMenu *menu)
const {
437 menu->addSeparator();
438 menu->addAction(m_rename);
439 menu->addAction(m_saveNexus);
440 menu->addSeparator();
441 menu->addAction(m_delete);
444PlotMenuActions WorkspaceTreeWidgetSimple::createMatrixWorkspacePlotMenu(
bool hasMultipleBins) {
446 if (hasMultipleBins) {
447 plotMenu.
plotActions = {m_plotSpectrum, m_overplotSpectrum, m_plotSpectrumWithErrs, m_overplotSpectrumWithErrs,
448 m_plotAdvanced, m_superplot, m_superplotWithErrs, m_separator,
451 plotMenu.
plot3DActions = {m_plotSurface, m_plotWireframe, m_plotContour};
453 plotMenu.
plotActions = {m_superplotBins, m_superplotBinsWithErrs, m_separator, m_plotColorfill};
IPeaksWorkspace_sptr workspace
Basic MD Workspace Abstract Class.
Interface to the class Mantid::DataObjects::PeaksWorkspace.
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
Base MatrixWorkspace Abstract Class.
virtual std::size_t blocksize() const =0
Returns the size of each block of data returned by the dataY accessors.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
size_t getNumDims() const override
const HistogramData::HistogramY & y(const size_t index) const
Class to hold a set of workspaces.
Exception for when an item is not found in a collection.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)