Skip to content

Commit

Permalink
Refs #4509 drag/dropping a MDWorkspace onto a MDPlot also works
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Feb 2, 2012
1 parent 672624b commit 9488d7e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMDCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void MantidMDCurve::init(Graph* g, bool distr, Graph::CurveType style)
MultiLayer* ml = dynamic_cast<MultiLayer*>(g->parent()->parent()->parent());
if (style == Graph::Unspecified || (ml && ml->applicationWindow()->applyCurveStyleToMantid) )
{
//FIXME: Style HorizontalSteps does NOT seem to be applied
applyStyleChoice(style, ml, lineWidth);
}
else
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidMDCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MantidMDCurve : public MantidCurve

/// More complex constructor setting some defaults for the curve
MantidMDCurve(const QString& wsName,Graph* g,
bool err=false,bool distr = false, Graph::CurveType style = Graph::Unspecified);
bool err=false,bool distr = false, Graph::CurveType style = Graph::HorizontalSteps);

/// Copy constructor
MantidMDCurve(const MantidMDCurve& c);
Expand Down
17 changes: 7 additions & 10 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,10 @@ void MantidUI::importBoxDataTable()
}
}

/*
Plots a Curve showing intensities for a MDWorkspace only if the workspace meets certain criteria, such as
having only one non-integrated dimension. Should exit gracefully otherwise.
*/
/** Plots a Curve showing intensities for a MDWorkspace.
* But only if the workspace meets certain criteria, such as
* having only one non-integrated dimension. Should exit gracefully otherwise.
*/
void MantidUI::showMDPlot()
{
QString wsName = getSelectedWorkspaceName();
Expand All @@ -512,6 +512,9 @@ void MantidUI::showMDPlot()
int result = dlg->exec();
if (result == QDialog::Rejected)
return;
// Extract the settings from the dialog opened earlier
bool showErrors = dlg->showErrorBars();
LinePlotOptions * opts = dlg->getLineOptionsWidget();

MultiLayer* ml = appWindow()->multilayerPlot(appWindow()->generateUniqueName(wsName));
ml->setCloseOnEmpty(true);
Expand All @@ -526,19 +529,13 @@ void MantidUI::showMDPlot()
appWindow()->setPreferences(g);
g->newLegend("");

// Extract the settings from the dialog opened earlier
bool showErrors = dlg->showErrorBars();
LinePlotOptions * opts = dlg->getLineOptionsWidget();

// Create the curve with defaults
MantidMDCurve* curve = new MantidMDCurve(wsName,g,showErrors);
MantidQwtIMDWorkspaceData * data = curve->mantidData();
// Apply the settings
data->setPreviewMode(false);
data->setPlotAxisChoice(opts->getPlotAxis());
data->setNormalization(opts->getNormalization());
// // Force a refresh
// curve->setData(*data);

// Set some of the labels on the plot
g->setTitle(tr("Workspace ")+wsName);
Expand Down
23 changes: 20 additions & 3 deletions Code/Mantid/MantidPlot/src/MultiLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
#include "Mantid/MantidMDCurve.h"

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

LayerButton::LayerButton(const QString& text, QWidget* parent)
: QPushButton(text, parent)
Expand Down Expand Up @@ -1309,8 +1311,7 @@ void MultiLayer::dropEvent( QDropEvent * event )
}
}

/*
Drop a workspace onto an exisiting md curve
/** Drop a workspace onto an exisiting MantidMDCurve (plot of a MDWorkspace)
@param g : Graph object
@param originalCurve : the original MantidMDCurve onto which the new workspace(s) are to be dropped
@param tree : Mantid Tree widget
Expand All @@ -1321,6 +1322,16 @@ void MultiLayer::dropOntoMDCurve(Graph *g, MantidMDCurve* originalCurve, MantidT
using namespace Mantid::API;
QList<QString> allWsNames = tree->getSelectedWorkspaceNames();

if (allWsNames.size() <= 0) return;
// Create a dialog to ask for options. Use the first workspace to choose the dimensions
MantidMDCurveDialog * dlg = new MantidMDCurveDialog(g, allWsNames[0]);
int result = dlg->exec();
if (result == QDialog::Rejected)
return;
// Extract the settings from the dialog opened earlier
bool showErrors = dlg->showErrorBars();
LinePlotOptions * opts = dlg->getLineOptionsWidget();

// Loop through all selected workspaces create curves and put them onto the graph
for (int i=0; i<allWsNames.size(); i++)
{
Expand All @@ -1333,7 +1344,13 @@ void MultiLayer::dropOntoMDCurve(Graph *g, MantidMDCurve* originalCurve, MantidT
QString currentName(imdWS->name().c_str());
try
{
new MantidMDCurve(currentName,g,true);
MantidMDCurve* curve = new MantidMDCurve(currentName, g, showErrors);
MantidQwtIMDWorkspaceData * data = curve->mantidData();
// Apply the settings
data->setPreviewMode(false);
data->setPlotAxisChoice(opts->getPlotAxis());
data->setNormalization(opts->getNormalization());

}
catch(std::invalid_argument& ex)
{
Expand Down

0 comments on commit 9488d7e

Please sign in to comment.