Skip to content

Commit

Permalink
Added preview spectra select to Quasi
Browse files Browse the repository at this point in the history
Refs #10723
  • Loading branch information
DanNixon committed Jan 14, 2015
1 parent ee51e2a commit 2324bad
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 14 deletions.
Expand Up @@ -96,6 +96,8 @@ namespace CustomInterfaces
void replot(const QString& plotID);
/// Function to remove a curve from a plot
void removeCurve(const QString& curveID);
/// Function to remove all curves from plots
void removeAllCurves();

/// Function to get the range of the curve displayed on the mini plot
std::pair<double, double> getCurveRange(const QString& plotID);
Expand Down
Expand Up @@ -34,10 +34,15 @@ namespace MantidQt
void handleSampleInputReady(const QString& filename);
/// slot to handle when the user changes the program to be used
void handleProgramChange(int index);
/// Slot to handle setting a new preview spectrum
void previewSpecChanged(int value);
/// Handles updating spectra in mini plot
void updateMiniPlot();

private:

//The ui form
/// Current preview spectrum
int m_previewSpec;
/// The ui form
Ui::Quasi m_uiForm;

};
Expand Down
Expand Up @@ -266,7 +266,69 @@
<layout class="QVBoxLayout" name="treeSpace"/>
</item>
<item>
<layout class="QVBoxLayout" name="plotSpace"/>
<layout class="QVBoxLayout" name="plotPane">
<item>
<layout class="QVBoxLayout" name="plotSpace"/>
</item>
<item>
<layout class="QHBoxLayout" name="underPlotSpace">
<item>
<widget class="QLabel" name="lblPreviewSpec">
<property name="text">
<string>Preview Spectrum: </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spPreviewSpectrum">
<property name="maximum" stdset="0">
<number>0</number>
</property>
</widget>
</item>
<item>
<spacer name="legendSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lblPlotLegendData">
<property name="text">
<string>Data</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblPplotLegendFit">
<property name="text">
<string>Fit</string>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0);</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblPplotLegendDiff">
<property name="text">
<string>Diff</string>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(0, 255, 0);</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
Expand Down
16 changes: 15 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/IndirectTab.cpp
Expand Up @@ -222,11 +222,25 @@ namespace CustomInterfaces
if(m_curves[curveID] == NULL)
return;

m_curves[curveID]->attach(0);
m_curves[curveID]->attach(NULL);
delete m_curves[curveID];
m_curves[curveID] = NULL;
}

/**
* Removes all curves from their plots.
*/
void IndirectTab::removeAllCurves()
{
for(auto it = m_curves.begin(); it != m_curves.end(); ++it)
{
it->second->attach(NULL);
delete it->second;
}

m_curves.clear();
}

/**
* Plot a workspace to the miniplot given a workspace pointer and
* a specturm index.
Expand Down
69 changes: 59 additions & 10 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp
Expand Up @@ -2,12 +2,15 @@
#include "MantidQtCustomInterfaces/Quasi.h"
#include "MantidQtCustomInterfaces/UserInputValidator.h"

using namespace Mantid::API;

namespace MantidQt
{
namespace CustomInterfaces
{
Quasi::Quasi(QWidget * parent) :
IndirectBayesTab(parent)
IndirectBayesTab(parent),
m_previewSpec(0)
{
m_uiForm.setupUi(parent);

Expand Down Expand Up @@ -54,7 +57,11 @@ namespace MantidQt
//Connect the data selector for the sample to the mini plot
connect(m_uiForm.dsSample, SIGNAL(dataReady(const QString&)), this, SLOT(handleSampleInputReady(const QString&)));

// Connect the progrm selector to its handler
connect(m_uiForm.cbProgram, SIGNAL(currentIndexChanged(int)), this, SLOT(handleProgramChange(int)));

// Connect preview spectrum spinner to handler
connect(m_uiForm.spPreviewSpectrum, SIGNAL(valueChanged(int)), this, SLOT(previewSpecChanged(int)));
}

/**
Expand Down Expand Up @@ -126,8 +133,6 @@ namespace MantidQt
*/
void Quasi::run()
{
using namespace Mantid::API;

// Using 1/0 instead of True/False for compatibility with underlying Fortran code
// in some places
QString verbose("False");
Expand All @@ -147,9 +152,6 @@ namespace MantidQt
QString sampleName = m_uiForm.dsSample->getCurrentDataName();
QString resName = m_uiForm.dsResolution->getCurrentDataName();

// Should be either "red", "sqw" or "res"
QString resType = resName.right(3);

QString program = m_uiForm.cbProgram->currentText();

if(program == "Lorentzians")
Expand Down Expand Up @@ -201,6 +203,33 @@ namespace MantidQt

runPythonScript(pyInput);

updateMiniPlot();
}

/**
* Updates the data and fit curves on the mini plot.
*/
void Quasi::updateMiniPlot()
{
// Update sample plot
if(!m_uiForm.dsSample->isValid())
return;

QString sampleName = m_uiForm.dsSample->getCurrentDataName();
plotMiniPlot(sampleName, m_previewSpec, "QuasiPlot", "RawPlotCurve");

// Update fit plot
QString program = m_uiForm.cbProgram->currentText();
if(program == "Lorentzians")
program = "QL";
else
program = "QSe";

QString resName = m_uiForm.dsResolution->getCurrentDataName();

// Should be either "red", "sqw" or "res"
QString resType = resName.right(3);

// Get the correct workspace name based on the type of resolution file
if(program == "QL")
{
Expand All @@ -210,9 +239,12 @@ namespace MantidQt
program += "d";
}

// Update mini plot
QString outWsName = sampleName.left(sampleName.size() - 3) + program + "_Workspace_0";
QString outWsName = sampleName.left(sampleName.size() - 3) + program + "_Workspace_" + QString::number(m_previewSpec);
if(!AnalysisDataService::Instance().doesExist(outWsName.toStdString()))
return;

MatrixWorkspace_sptr outputWorkspace = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWsName.toStdString());

TextAxis* axis = dynamic_cast<TextAxis*>(outputWorkspace->getAxis(1));

for(size_t histIndex = 0; histIndex < outputWorkspace->getNumberHistograms(); histIndex++)
Expand All @@ -233,7 +265,7 @@ namespace MantidQt
}

replot("QuasiPlot");
}
}

/**
* Plots the loaded file to the miniplot and sets the guides
Expand All @@ -243,7 +275,12 @@ namespace MantidQt
*/
void Quasi::handleSampleInputReady(const QString& filename)
{
plotMiniPlot(filename, 0, "QuasiPlot", "RawPlotCurve");
MatrixWorkspace_sptr inWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(filename.toStdString());
int numHist = static_cast<int>(inWs->getNumberHistograms()) - 1;
m_uiForm.spPreviewSpectrum->setMaximum(numHist);
removeAllCurves();
replot("QuasiPlot");
updateMiniPlot();
std::pair<double,double> range = getCurveRange("RawPlotCurve");
setMiniPlotGuides("QuasiERange", m_properties["EMin"], m_properties["EMax"], range);
setPlotRange("QuasiERange", m_properties["EMin"], m_properties["EMax"], range);
Expand Down Expand Up @@ -306,5 +343,17 @@ namespace MantidQt
break;
}
}

/**
* Handles setting a new preview spectrum on the preview plot.
*
* @param value Spectrum index
*/
void Quasi::previewSpecChanged(int value)
{
m_previewSpec = value;
updateMiniPlot();
}

} // namespace CustomInterfaces
} // namespace MantidQt

0 comments on commit 2324bad

Please sign in to comment.