Skip to content

Commit

Permalink
Refs #4509: Dialog seems to work well when calling the plot MD menu.
Browse files Browse the repository at this point in the history
Drag/drop does not pop it up?
  • Loading branch information
Janik Zikovsky committed Feb 2, 2012
1 parent b1b36cf commit 672624b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 28 deletions.
9 changes: 7 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMDCurveDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ MantidMDCurveDialog::MantidMDCurveDialog(QWidget *parent, QString wsName)
{
ui.setupUi(this);
m_lineOptions = new LinePlotOptions(this);
ui.mainLayout->insertWidget(0, m_lineOptions);

// To set the right dimension labels
IMDWorkspace_sptr ws = boost::dynamic_pointer_cast<IMDWorkspace>(
AnalysisDataService::Instance().retrieve( m_wsName.toStdString()) );
if (ws)
m_lineOptions->setOriginalWorkspace(ws);

// Connect the button slots
QMetaObject::connectSlotsByName(this);
}

/// @return true if error bars are selected
Expand All @@ -32,12 +35,14 @@ MantidMDCurveDialog::~MantidMDCurveDialog()
{

}
void MantidMDCurveDialog::on_btnOK_toggled()
void MantidMDCurveDialog::on_btnOK_clicked()
{
this->accept();
this->close();
}

void MantidMDCurveDialog::on_btnCancel_toggled()
void MantidMDCurveDialog::on_btnCancel_clicked()
{
this->reject();
this->close();
}
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMDCurveDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class MantidMDCurveDialog : public QDialog
bool showErrorBars();

public slots:
void on_btnOK_toggled();
void on_btnCancel_toggled();
void on_btnOK_clicked();
void on_btnCancel_clicked();

private:
Ui::MantidMDCurveDialogClass ui;
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMDCurveDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>377</width>
<height>165</height>
<width>410</width>
<height>139</height>
</rect>
</property>
<property name="windowTitle">
<string>MD Plot Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="mainLayout">
<property name="spacing">
<number>4</number>
</property>
Expand Down
38 changes: 20 additions & 18 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ having only one non-integrated dimension. Should exit gracefully otherwise.
void MantidUI::showMDPlot()
{
QString wsName = getSelectedWorkspaceName();

// Create a dialog to ask for options
MantidMDCurveDialog * dlg = new MantidMDCurveDialog(appWindow(), wsName);
int result = dlg->exec();
if (result == QDialog::Rejected)
return;

MultiLayer* ml = appWindow()->multilayerPlot(appWindow()->generateUniqueName(wsName));
ml->setCloseOnEmpty(true);
Graph *g = ml->activeGraph();
Expand All @@ -519,29 +526,24 @@ void MantidUI::showMDPlot()
appWindow()->setPreferences(g);
g->newLegend("");

// Create a dialog to ask for options
MantidMDCurveDialog * dlg = new MantidMDCurveDialog(appWindow(), wsName);
dlg->exec();

// Extract the errors
// 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);
// TODO: normalization
curve->mantidData()->setPlotAxisChoice(opts->getPlotAxis());

// Now pop up the dialog to choose some options. Leave the plot open.


IMDWorkspace_sptr mdews = boost::dynamic_pointer_cast<IMDWorkspace>(
AnalysisDataService::Instance().retrieve( wsName.toStdString()) );

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);
g->setYAxisTitle(tr("Normalised Signal"));
Mantid::Geometry::IMDDimension_const_sptr nonIntegratedDim = mdews->getNonIntegratedDimensions()[0];
std::string xAxisLabel = nonIntegratedDim->getName() + " / " + nonIntegratedDim->getUnits();
g->setXAxisTitle(xAxisLabel.c_str());
g->setXAxisTitle(QString::fromStdString(data->getXAxisLabel()));
g->setYAxisTitle(QString::fromStdString(data->getYAxisLabel()));
g->setAntialiasing(false);
g->setAutoScale();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class MantidQwtIMDWorkspaceData: public QObject, public MantidQwtWorkspaceData

void setPreviewMode(bool preview);
void setPlotAxisChoice(int choice);
void setNormalization(Mantid::API::MDNormalization choice);

std::string getXAxisLabel() const;
std::string getYAxisLabel() const;
Expand All @@ -68,9 +69,13 @@ class MantidQwtIMDWorkspaceData: public QObject, public MantidQwtWorkspaceData

/// Indicates that the data is plotted on a log y scale
bool m_logScale;

/// lowest positive y value
mutable double m_minPositive;

/// Are we in preview mode?
bool m_preview;

/// Start point of the line in the workspace
Mantid::Kernel::VMD m_start;

Expand Down
31 changes: 28 additions & 3 deletions Code/Mantid/MantidQt/API/src/MantidQwtIMDWorkspaceData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ MantidQwtIMDWorkspaceData::MantidQwtIMDWorkspaceData(Mantid::API::IMDWorkspace_c
bool isDistribution)
: QObject(),
m_workspace(workspace),
m_logScale(logScale),
m_minPositive(0),
m_logScale(logScale), m_minPositive(0),
m_preview(false),
m_start(start),
m_end(end),
m_normalization(normalize),
Expand Down Expand Up @@ -82,6 +82,7 @@ MantidQwtIMDWorkspaceData::MantidQwtIMDWorkspaceData(const MantidQwtIMDWorkspace
: QObject(),
m_workspace(data.m_workspace),
m_logScale(data.m_logScale),
m_preview(data.m_preview),
m_start(data.m_start),
m_end(data.m_end),
m_dir(data.m_dir),
Expand Down Expand Up @@ -114,8 +115,13 @@ QwtData * MantidQwtIMDWorkspaceData::copy() const
/// Return a new data object of the same type but with a new workspace
MantidQwtIMDWorkspaceData* MantidQwtIMDWorkspaceData::copy(Mantid::API::IMDWorkspace_sptr workspace)const
{
return new MantidQwtIMDWorkspaceData(workspace, m_logScale, m_start, m_end,
MantidQwtIMDWorkspaceData * out;
out = new MantidQwtIMDWorkspaceData(workspace, m_logScale, m_start, m_end,
m_normalization, m_isDistribution);
out->m_plotAxis = this->m_plotAxis;
out->m_currentPlotAxis = this->m_currentPlotAxis;
out->setPreviewMode(m_preview);
return out;
}


Expand Down Expand Up @@ -213,12 +219,28 @@ bool MantidQwtIMDWorkspaceData::setAsDistribution(bool on)
}

//-----------------------------------------------------------------------------
/** Set which axis to plot as the X of the line plot
*
* @param choice :: int, -2 = auto, -1 = distance,
*/
void MantidQwtIMDWorkspaceData::setPlotAxisChoice(int choice)
{
m_plotAxis = choice;
this->choosePlotAxis();
}

//-----------------------------------------------------------------------------
/** Set the signal normalization to use.
* This recalculates the line plot.
*
* @param choice :: one of MDNormalization enum
*/
void MantidQwtIMDWorkspaceData::setNormalization(Mantid::API::MDNormalization choice)
{
m_normalization = choice;
this->cacheLinePlot();
}

//-----------------------------------------------------------------------------
/** Are we in Preview mode?
*
Expand All @@ -233,6 +255,7 @@ void MantidQwtIMDWorkspaceData::setPlotAxisChoice(int choice)
*/
void MantidQwtIMDWorkspaceData::setPreviewMode(bool preview)
{
m_preview = preview;
// If the workspace has no original, then we MUST be in preview mode.
if (preview || (m_workspace->numOriginalWorkspaces() == 0))
{
Expand Down Expand Up @@ -298,6 +321,8 @@ void MantidQwtIMDWorkspaceData::choosePlotAxis()
std::string MantidQwtIMDWorkspaceData::getXAxisLabel() const
{
std::string xLabel;
if (!m_originalWorkspace)
return "";
if (m_currentPlotAxis >= 0)
{
// One of the dimensions of the original
Expand Down

0 comments on commit 672624b

Please sign in to comment.