From 84abf8159f2e6086a9bd2f7dd5b8eb0cb615d8ca Mon Sep 17 00:00:00 2001 From: Martyn Gigg Date: Thu, 16 Apr 2015 11:50:37 +0100 Subject: [PATCH] Allow waterfall plots to be created more easily from UI Refs #11559 --- .../MantidPlot/src/Mantid/MantidDock.cpp | 35 ++++++++++++------- .../Mantid/MantidPlot/src/Mantid/MantidDock.h | 4 ++- .../Mantid/MantidPlot/src/Mantid/MantidUI.cpp | 20 ++++++----- Code/Mantid/MantidPlot/src/Mantid/MantidUI.h | 8 ++--- .../src/Mantid/MantidWSIndexDialog.cpp | 29 ++++++++++++++- .../src/Mantid/MantidWSIndexDialog.h | 30 +++++++++++++--- Code/Mantid/MantidPlot/src/MultiLayer.cpp | 7 ++-- 7 files changed, 101 insertions(+), 32 deletions(-) diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp index 25d0de248961..febf05110073 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp @@ -1344,21 +1344,27 @@ void MantidDockWidget::groupingButtonClick() /// Plots a single spectrum from each selected workspace void MantidDockWidget::plotSpectra() { - const QMultiMap > toPlot = m_tree->chooseSpectrumFromSelected(); + const auto userInput = m_tree->chooseSpectrumFromSelected(); // An empty map will be returned if the user clicks cancel in the spectrum selection - if (toPlot.empty()) return; + if (userInput.plots.empty()) return; - m_mantidUI->plot1D(toPlot, true, MantidQt::DistributionDefault, false); + bool spectrumPlot(true), errs(false), clearWindow(false); + MultiLayer *window(NULL); + m_mantidUI->plot1D(userInput.plots, spectrumPlot, MantidQt::DistributionDefault, errs, + window, clearWindow, userInput.waterfall); } /// Plots a single spectrum from each selected workspace with errors void MantidDockWidget::plotSpectraErr() { - const QMultiMap > toPlot = m_tree->chooseSpectrumFromSelected(); + const auto userInput = m_tree->chooseSpectrumFromSelected(); // An empty map will be returned if the user clicks cancel in the spectrum selection - if (toPlot.empty()) return; + if (userInput.plots.empty()) return; - m_mantidUI->plot1D(toPlot, true, MantidQt::DistributionDefault, true); + bool spectrumPlot(true), errs(true), clearWindow(false); + MultiLayer *window(NULL); + m_mantidUI->plot1D(userInput.plots, spectrumPlot, MantidQt::DistributionDefault, errs, + window, clearWindow, userInput.waterfall); } /** @@ -1671,9 +1677,10 @@ QStringList MantidTreeWidget::getSelectedWorkspaceNames() const * TableWorkspaces (which are implicitly excluded). We only want workspaces we * can actually plot! * -* @return :: A map of workspace name to spectrum numbers to plot. +* @param showWaterfallOpt If true, show the waterfall option on the dialog +* @return :: A MantidWSIndexDialog::UserInput structure listing the selected options */ -QMultiMap > MantidTreeWidget::chooseSpectrumFromSelected() const +MantidWSIndexDialog::UserInput MantidTreeWidget::chooseSpectrumFromSelected(bool showWaterfallOpt) const { // Check for any selected WorkspaceGroup names and replace with the names of // their children. @@ -1731,13 +1738,17 @@ QMultiMap > MantidTreeWidget::chooseSpectrumFromSelected() SINGLE_SPECTRUM ); } - return spectrumToPlot; + MantidWSIndexDialog::UserInput selections; + selections.plots = spectrumToPlot; + selections.waterfall = false; + return selections; } - // Else, one or more workspaces - MantidWSIndexDialog *dio = new MantidWSIndexDialog(m_mantidUI, 0, selectedMatrixWsNameList); + // Else, one or more workspaces + MantidWSIndexDialog *dio = new MantidWSIndexDialog(m_mantidUI, 0, selectedMatrixWsNameList, + showWaterfallOpt); dio->exec(); - return dio->getPlots(); + return dio->getSelections(); } void MantidTreeWidget::setSortScheme(MantidItemSortScheme sortScheme) diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidDock.h b/Code/Mantid/MantidPlot/src/Mantid/MantidDock.h index af2b1087c93c..07eb2e9f8a2b 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidDock.h +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidDock.h @@ -11,6 +11,8 @@ #include "MantidQtMantidWidgets/AlgorithmSelectorWidget.h" +#include "Mantid/MantidWSIndexDialog.h" + #include #include #include @@ -165,7 +167,7 @@ class MantidTreeWidget:public QTreeWidget void mouseDoubleClickEvent(QMouseEvent *e); QStringList getSelectedWorkspaceNames() const; - QMultiMap > chooseSpectrumFromSelected() const; + MantidWSIndexDialog::UserInput chooseSpectrumFromSelected(bool showWaterfallOpt = true) const; void setSortScheme(MantidItemSortScheme); void setSortOrder(Qt::SortOrder); MantidItemSortScheme getSortScheme() const; diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp index 80adf7e541d2..d6b53455f4fc 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp @@ -2987,7 +2987,7 @@ Plots the spectra from the given workspaces @param clearWindow :: Whether to clear specified plotWindow before plotting. Ignored if plotWindow == NULL */ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList& indexList, bool spectrumPlot, bool errs, - Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow) + Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow, bool waterfallPlot) { // Convert the list into a map (with the same workspace as key in each case) QMultiMap pairs; @@ -3009,7 +3009,8 @@ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList& inde } // Pass over to the overloaded method - return plot1D(pairs,spectrumPlot,MantidQt::DistributionDefault, errs,style,plotWindow, clearWindow); + return plot1D(pairs,spectrumPlot,MantidQt::DistributionDefault, errs,style,plotWindow, clearWindow, + waterfallPlot); } /** Create a 1D graph from the specified list of workspaces/spectra. @param toPlot :: Map of form ws -> [spectra_list] @@ -3022,7 +3023,7 @@ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList& inde */ MultiLayer* MantidUI::plot1D(const QMultiMap >& toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr, bool errs, - MultiLayer* plotWindow, bool clearWindow) + MultiLayer* plotWindow, bool clearWindow, bool waterfallPlot) { // Convert the list into a map (with the same workspace as key in each case) QMultiMap pairs; @@ -3038,7 +3039,7 @@ MultiLayer* MantidUI::plot1D(const QMultiMap >& toPlot, bool s } // Pass over to the overloaded method - return plot1D(pairs,spectrumPlot,distr,errs,Graph::Unspecified,plotWindow, clearWindow); + return plot1D(pairs,spectrumPlot,distr,errs,Graph::Unspecified,plotWindow, clearWindow, waterfallPlot); } /** Create a 1d graph from the specified spectra in a MatrixWorkspace @@ -3052,7 +3053,7 @@ MultiLayer* MantidUI::plot1D(const QMultiMap >& toPlot, bool s @return NULL if failure. Otherwise, if plotWindow == NULL - created window, if not NULL - plotWindow */ MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set& indexList, bool spectrumPlot, - MantidQt::DistributionFlag distr, bool errs, MultiLayer* plotWindow, bool clearWindow) + MantidQt::DistributionFlag distr, bool errs, MultiLayer* plotWindow, bool clearWindow, bool waterfallPlot) { // Convert the list into a map (with the same workspace as key in each case) QMultiMap pairs; @@ -3064,7 +3065,7 @@ MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set& indexLi } // Pass over to the overloaded method - return plot1D(pairs,spectrumPlot,distr,errs,Graph::Unspecified,plotWindow, clearWindow); + return plot1D(pairs,spectrumPlot,distr,errs,Graph::Unspecified,plotWindow, clearWindow, waterfallPlot); } /** Create a 1d graph form a set of workspace-spectrum pairs @@ -3079,7 +3080,8 @@ MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set& indexLi */ MultiLayer* MantidUI::plot1D(const QMultiMap& toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr, bool errs, - Graph::CurveType style, MultiLayer* plotWindow, bool clearWindow) + Graph::CurveType style, MultiLayer* plotWindow, + bool clearWindow, bool waterfallPlot) { if(toPlot.size() == 0) return NULL; @@ -3094,6 +3096,8 @@ MultiLayer* MantidUI::plot1D(const QMultiMap& toPlot, bool spectrum ask.exec(); if (ask.clickedButton() != confirmButton) return NULL; } + // Force waterfall option to false if only 1 curve + if(toPlot.size() == 1) waterfallPlot = false; QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); @@ -3206,7 +3210,7 @@ MultiLayer* MantidUI::plot1D(const QMultiMap& toPlot, bool spectrum // happen, but it does apparently with some muon analyses. g->checkValuesInAxisRange(firstCurve); } - + ml->toggleWaterfall(waterfallPlot); // Check if window does not contain any curves and should be closed ml->maybeNeedToClose(); diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h index f1c52ce45f68..cd29eb20f675 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h @@ -212,23 +212,23 @@ class MantidUI:public QObject // Create a 1d graph form specified MatrixWorkspace and index MultiLayer* plot1D(const QStringList& wsnames, const QList& indexList, bool spectrumPlot, bool errs=true, Graph::CurveType style = Graph::Unspecified, - MultiLayer* plotWindow = NULL, bool clearWindow = false); + MultiLayer* plotWindow = NULL, bool clearWindow = false, bool waterfallPlot = false); MultiLayer* plot1D(const QString& wsName, const std::set& indexList, bool spectrumPlot, MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, bool errs=false, - MultiLayer* plotWindow = NULL, bool clearWindow = false); + MultiLayer* plotWindow = NULL, bool clearWindow = false, bool waterfallPlot = false); MultiLayer* plot1D(const QMultiMap& toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, bool errs=false, Graph::CurveType style = Graph::Unspecified, - MultiLayer* plotWindow = NULL, bool clearWindow = false); + MultiLayer* plotWindow = NULL, bool clearWindow = false, bool waterfallPlot = false); MultiLayer* plot1D(const QMultiMap >& toPlot, bool spectrumPlot, MantidQt::DistributionFlag distr = MantidQt::DistributionDefault, bool errs=false, - MultiLayer* plotWindow = NULL, bool clearWindow = false); + MultiLayer* plotWindow = NULL, bool clearWindow = false, bool waterfallPlot = false); /// Draw a color fill plot for each of the listed workspaces void drawColorFillPlots(const QStringList & wsNames, Graph::CurveType curveType = Graph::ColorMap); diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.cpp index b077f4fed0de..869db7be6e55 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.cpp @@ -22,10 +22,11 @@ * @param flags :: Window flags that are passed the the QDialog constructor * @param wsNames :: the names of the workspaces to be plotted */ -MantidWSIndexDialog::MantidWSIndexDialog(MantidUI* mui, Qt::WFlags flags, QList wsNames) +MantidWSIndexDialog::MantidWSIndexDialog(MantidUI* mui, Qt::WFlags flags, QList wsNames, const bool showWaterfallOption) : QDialog(mui->appWindow(), flags), m_mantidUI(mui), m_spectra(false), + m_waterfall(showWaterfallOption), m_wsNames(wsNames), m_wsIndexIntervals(), m_spectraIdIntervals(), @@ -44,6 +45,14 @@ MantidWSIndexDialog::MantidWSIndexDialog(MantidUI* mui, Qt::WFlags flags, QList< init(); } +MantidWSIndexDialog::UserInput MantidWSIndexDialog::getSelections() const +{ + UserInput options; + options.plots = getPlots(); + options.waterfall = waterfallPlotRequested(); + return options; +} + QMultiMap > MantidWSIndexDialog::getPlots() const { // Map of workspace names to set of indices to be plotted. @@ -88,6 +97,11 @@ QMultiMap > MantidWSIndexDialog::getPlots() const return plots; } +bool MantidWSIndexDialog::waterfallPlotRequested() const +{ + return m_waterfallOpt->isChecked(); +} + //---------------------------------- // MantidWSIndexDialog private slots //---------------------------------- @@ -149,6 +163,7 @@ void MantidWSIndexDialog::init() setWindowTitle(tr("MantidPlot")); initSpectraBox(); initWorkspaceBox(); + initOptionsBoxes(); initButtons(); setLayout(m_outer); } @@ -185,6 +200,18 @@ void MantidWSIndexDialog::initSpectraBox() connect(m_spectraField->lineEdit(), SIGNAL(textEdited(const QString &)), this, SLOT(editedSpectraField())); } +void MantidWSIndexDialog::initOptionsBoxes() +{ + m_optionsBox = new QHBoxLayout; + m_waterfallOpt = new QCheckBox("Waterfall Plot"); + if(m_waterfall) + m_optionsBox->add(m_waterfallOpt); + else + m_waterfallOpt->setChecked(true); + + m_outer->addItem(m_optionsBox); +} + void MantidWSIndexDialog::initButtons() { m_buttonBox = new QHBoxLayout; diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.h b/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.h index b4638c6e9c47..9ab943480a4c 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.h +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.h @@ -4,6 +4,7 @@ //---------------------------------- // Includes //---------------------------------- +#include #include #include #include @@ -188,7 +189,8 @@ class IntervalListValidator : public QValidator class MantidWSIndexDialog : public QDialog { Q_OBJECT -/** Auxiliar class to wrap the QLine allowing to have a warn to the user for + + /** Auxiliar class to wrap the QLine allowing to have a warn to the user for * invalid inputs. */ class QLineEditWithErrorMark : public QWidget{ @@ -207,13 +209,26 @@ class QLineEditWithErrorMark : public QWidget{ }; public: - /// Constructor - same parameters as one of the parent constructors, along with a + /** + * POD structure to hold all user-selected input + */ + struct UserInput { + QMultiMap > plots; + bool waterfall; + }; + +/// Constructor - same parameters as one of the parent constructors, along with a /// list of the names of workspaces to be plotted. - MantidWSIndexDialog(MantidUI* parent, Qt::WFlags flags, QList wsNames); + MantidWSIndexDialog(MantidUI* parent, Qt::WFlags flags, QList wsNames, + const bool showWaterfallOption = false); + /// Returns a structure holding all of the selected options + UserInput getSelections() const; /// Returns the QMultiMap that contains all the workspaces that are to be plotted, /// mapped to the set of workspace indices. QMultiMap > getPlots() const; + /// Returns whether the waterfall option has been selected + bool waterfallPlotRequested() const; private slots: /// Called when the OK button is pressed. @@ -232,6 +247,8 @@ private slots: void initWorkspaceBox(); /// Initializes the layout of the spectra ID section of the dialog void initSpectraBox(); + /// Initialize the layout of the options check boxes + void initOptionsBoxes(); /// Initializes the layout of the buttons void initButtons(); @@ -253,13 +270,18 @@ private slots: /// Do we allow the user to ask for a range of spectra IDs or not? bool m_spectra; + /// Do we allow the display of the waterfall option + bool m_waterfall; + /// Pointers to the obligatory Qt objects: QLabel *m_wsMessage, *m_spectraMessage, *m_orMessage; QLineEditWithErrorMark *m_wsField, *m_spectraField; QVBoxLayout *m_outer, *m_wsBox, *m_spectraBox; - QHBoxLayout *m_buttonBox; + QHBoxLayout *m_optionsBox, *m_buttonBox; + QCheckBox *m_waterfallOpt; QPushButton *m_okButton, *m_cancelButton, *m_plotAllButton; + /// A list of names of workspaces which are to be plotted. QList m_wsNames; /// IntervalLists for the range of indices/IDs AVAILABLE to the user. diff --git a/Code/Mantid/MantidPlot/src/MultiLayer.cpp b/Code/Mantid/MantidPlot/src/MultiLayer.cpp index ed13eb23b771..36bf692670f4 100644 --- a/Code/Mantid/MantidPlot/src/MultiLayer.cpp +++ b/Code/Mantid/MantidPlot/src/MultiLayer.cpp @@ -67,6 +67,7 @@ #include #include "Mantid/MantidMDCurveDialog.h" +#include "Mantid/MantidWSIndexDialog.h" #include "MantidQtSliceViewer/LinePlotOptions.h" #include "TSVSerialiser.h" @@ -1385,8 +1386,10 @@ void MultiLayer::dropOntoMatrixCurve(Graph *g, MantidMatrixCurve* originalCurve, } if ( tree == NULL ) return; // (shouldn't happen) - QMultiMap > toPlot = tree->chooseSpectrumFromSelected(); - + bool waterfallOpt = false; + const auto userInput = tree->chooseSpectrumFromSelected(waterfallOpt); + const auto toPlot = userInput.plots; + // Iterate through the selected workspaces adding a set of curves from each for(QMultiMap >::const_iterator it=toPlot.begin();it!=toPlot.end();++it) {