Skip to content

Commit

Permalink
Allow waterfall plots to be created more easily from UI
Browse files Browse the repository at this point in the history
Refs #11559
  • Loading branch information
martyngigg committed Apr 16, 2015
1 parent 62cb51b commit 84abf81
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 32 deletions.
35 changes: 23 additions & 12 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Expand Up @@ -1344,21 +1344,27 @@ void MantidDockWidget::groupingButtonClick()
/// Plots a single spectrum from each selected workspace
void MantidDockWidget::plotSpectra()
{
const QMultiMap<QString,std::set<int> > 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<QString,std::set<int> > 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);
}

/**
Expand Down Expand Up @@ -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<QString,std::set<int> > MantidTreeWidget::chooseSpectrumFromSelected() const
MantidWSIndexDialog::UserInput MantidTreeWidget::chooseSpectrumFromSelected(bool showWaterfallOpt) const
{
// Check for any selected WorkspaceGroup names and replace with the names of
// their children.
Expand Down Expand Up @@ -1731,13 +1738,17 @@ QMultiMap<QString,std::set<int> > 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)
Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Expand Up @@ -11,6 +11,8 @@

#include "MantidQtMantidWidgets/AlgorithmSelectorWidget.h"

#include "Mantid/MantidWSIndexDialog.h"

#include <QActionGroup>
#include <QAtomicInt>
#include <QComboBox>
Expand Down Expand Up @@ -165,7 +167,7 @@ class MantidTreeWidget:public QTreeWidget
void mouseDoubleClickEvent(QMouseEvent *e);

QStringList getSelectedWorkspaceNames() const;
QMultiMap<QString,std::set<int> > chooseSpectrumFromSelected() const;
MantidWSIndexDialog::UserInput chooseSpectrumFromSelected(bool showWaterfallOpt = true) const;
void setSortScheme(MantidItemSortScheme);
void setSortOrder(Qt::SortOrder);
MantidItemSortScheme getSortScheme() const;
Expand Down
20 changes: 12 additions & 8 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Expand Up @@ -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<int>& 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<QString,int> pairs;
Expand All @@ -3009,7 +3009,8 @@ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList<int>& 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]
Expand All @@ -3022,7 +3023,7 @@ MultiLayer* MantidUI::plot1D(const QStringList& ws_names, const QList<int>& inde
*/
MultiLayer* MantidUI::plot1D(const QMultiMap<QString, set<int> >& 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<QString,int> pairs;
Expand All @@ -3038,7 +3039,7 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString, set<int> >& 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
Expand All @@ -3052,7 +3053,7 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString, set<int> >& 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<int>& 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<QString,int> pairs;
Expand All @@ -3064,7 +3065,7 @@ MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set<int>& 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
Expand All @@ -3079,7 +3080,8 @@ MultiLayer* MantidUI::plot1D(const QString& wsName, const std::set<int>& indexLi
*/
MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& 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;

Expand All @@ -3094,6 +3096,8 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& 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));

Expand Down Expand Up @@ -3206,7 +3210,7 @@ MultiLayer* MantidUI::plot1D(const QMultiMap<QString,int>& 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();

Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.h
Expand Up @@ -212,23 +212,23 @@ class MantidUI:public QObject
// Create a 1d graph form specified MatrixWorkspace and index
MultiLayer* plot1D(const QStringList& wsnames, const QList<int>& 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<int>& 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<QString,int>& 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<QString,std::set<int> >& 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);
Expand Down
29 changes: 28 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.cpp
Expand Up @@ -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<QString> wsNames)
MantidWSIndexDialog::MantidWSIndexDialog(MantidUI* mui, Qt::WFlags flags, QList<QString> wsNames, const bool showWaterfallOption)
: QDialog(mui->appWindow(), flags),
m_mantidUI(mui),
m_spectra(false),
m_waterfall(showWaterfallOption),
m_wsNames(wsNames),
m_wsIndexIntervals(),
m_spectraIdIntervals(),
Expand All @@ -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<QString,std::set<int> > MantidWSIndexDialog::getPlots() const
{
// Map of workspace names to set of indices to be plotted.
Expand Down Expand Up @@ -88,6 +97,11 @@ QMultiMap<QString,std::set<int> > MantidWSIndexDialog::getPlots() const
return plots;
}

bool MantidWSIndexDialog::waterfallPlotRequested() const
{
return m_waterfallOpt->isChecked();
}

//----------------------------------
// MantidWSIndexDialog private slots
//----------------------------------
Expand Down Expand Up @@ -149,6 +163,7 @@ void MantidWSIndexDialog::init()
setWindowTitle(tr("MantidPlot"));
initSpectraBox();
initWorkspaceBox();
initOptionsBoxes();
initButtons();
setLayout(m_outer);
}
Expand Down Expand Up @@ -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;
Expand Down
30 changes: 26 additions & 4 deletions Code/Mantid/MantidPlot/src/Mantid/MantidWSIndexDialog.h
Expand Up @@ -4,6 +4,7 @@
//----------------------------------
// Includes
//----------------------------------
#include <QCheckBox>
#include <QDialog>
#include <QString>
#include <QList>
Expand Down Expand Up @@ -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{
Expand All @@ -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<QString,std::set<int> > 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<QString> wsNames);
MantidWSIndexDialog(MantidUI* parent, Qt::WFlags flags, QList<QString> 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<QString,std::set<int> > getPlots() const;
/// Returns whether the waterfall option has been selected
bool waterfallPlotRequested() const;

private slots:
/// Called when the OK button is pressed.
Expand All @@ -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();

Expand All @@ -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<QString> m_wsNames;
/// IntervalLists for the range of indices/IDs AVAILABLE to the user.
Expand Down
7 changes: 5 additions & 2 deletions Code/Mantid/MantidPlot/src/MultiLayer.cpp
Expand Up @@ -67,6 +67,7 @@

#include <gsl/gsl_vector.h>
#include "Mantid/MantidMDCurveDialog.h"
#include "Mantid/MantidWSIndexDialog.h"
#include "MantidQtSliceViewer/LinePlotOptions.h"

#include "TSVSerialiser.h"
Expand Down Expand Up @@ -1385,8 +1386,10 @@ void MultiLayer::dropOntoMatrixCurve(Graph *g, MantidMatrixCurve* originalCurve,
}

if ( tree == NULL ) return; // (shouldn't happen)
QMultiMap<QString,std::set<int> > 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<QString,std::set<int> >::const_iterator it=toPlot.begin();it!=toPlot.end();++it)
{
Expand Down

0 comments on commit 84abf81

Please sign in to comment.