Skip to content

Commit

Permalink
Remove unused code from IndirectTab
Browse files Browse the repository at this point in the history
Also prefer QPair over std::pair in UI stuff

Refs #11036
  • Loading branch information
DanNixon committed Feb 13, 2015
1 parent d5f53c3 commit 5b18086
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 237 deletions.
Expand Up @@ -96,9 +96,9 @@ namespace MantidQt
/// Function to run a string as python code
void runPythonScript(const QString& pyInput);
/// Function to read an instrument's resolution from the IPF using a string
bool getInstrumentResolution(const QString& filename, std::pair<double,double>& res);
bool getInstrumentResolution(const QString& filename, QPair<double, double> & res);
/// Function to read an instrument's resolution from the IPF using a workspace pointer
bool getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair<double,double>& res);
bool getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, QPair<double, double> & res);
/// Function to set the position of the lower guide on the plot
void updateLowerGuide(MantidQt::MantidWidgets::RangeSelector* rs, QtProperty* lower, QtProperty* upper, double value);
/// Function to set the position of the upper guide on the plot
Expand Down
Expand Up @@ -13,6 +13,7 @@

#include <QDoubleValidator>
#include <QMap>
#include <QPair>
#include <QtIntPropertyManager>
#include <QtTreePropertyBrowser>

Expand Down Expand Up @@ -88,28 +89,10 @@ namespace CustomInterfaces
/// Run the load algorithm with the given file name, output name and spectrum range
bool loadFile(const QString& filename, const QString& outputName, const int specMin = -1, const int specMax = -1);

/// Function to plot a workspace to the miniplot using a workspace name
void plotMiniPlot(const QString& workspace, size_t index, const QString& plotID, const QString& curveID = "");
/// Function to plot a workspace to the miniplot using a workspace pointer
void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex, const QString& plotID, const QString& curveID = "");
/// Function to replot a miniplot
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);
/// Function to set the range of an axis on a plot
void setAxisRange(const QString& plotID, QwtPlot::Axis axis, std::pair<double, double> range);
/// Function to autoscale a given axis based on the data in a curve
void setXAxisToCurve(const QString& plotID, const QString& curveID);

/// Function to set the range limits of the plot
void setPlotRange(const QString& rsID, QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds);
void setPlotPropertyRange(const QString& rsID, QtProperty* min, QtProperty* max, const QPair<double, double> & bounds);
/// Function to set the range selector on the mini plot
void setMiniPlotGuides(const QString& rsID, QtProperty* lower, QtProperty* upper, const std::pair<double, double>& bounds);
void setRangeSelector(const QString& rsID, QtProperty* lower, QtProperty* upper, const QPair<double, double> & bounds);

/// Function to run an algorithm on a seperate thread
void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm);
Expand All @@ -119,10 +102,6 @@ namespace CustomInterfaces
/// Parent QWidget (if applicable)
QWidget *m_parentWidget;

/// Plot of the input
std::map<QString, QwtPlot *> m_plots;
/// Curve on the plot
std::map<QString, QwtPlotCurve *> m_curves;
/// Range selector widget for mini plot
std::map<QString, MantidQt::MantidWidgets::RangeSelector *> m_rangeSelectors;
/// Tree of the properties
Expand Down
Expand Up @@ -48,7 +48,7 @@ namespace MantidQt
* @param workspace :: Name of the workspace to use
* @param res :: The retrieved values for the resolution parameter (if one was found)
*/
bool IndirectBayesTab::getInstrumentResolution(const QString& workspace, std::pair<double,double>& res)
bool IndirectBayesTab::getInstrumentResolution(const QString& workspace, QPair<double, double> & res)
{
auto ws = Mantid::API::AnalysisDataService::Instance().retrieveWS<const Mantid::API::MatrixWorkspace>(workspace.toStdString());
return getInstrumentResolution(ws, res);
Expand All @@ -61,7 +61,7 @@ namespace MantidQt
* @param ws :: Pointer to the workspace to use
* @param res :: The retrieved values for the resolution parameter (if one was found)
*/
bool IndirectBayesTab::getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair<double,double>& res)
bool IndirectBayesTab::getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, QPair<double, double> & res)
{
auto inst = ws->getInstrument();
auto analyser = inst->getStringParameter("analyser");
Expand All @@ -74,7 +74,7 @@ namespace MantidQt
//set the default instrument resolution
if(params.size() > 0)
{
res = std::make_pair(-params[0], params[0]);
res = qMakePair(-params[0], params[0]);
return true;
}
}
Expand Down
Expand Up @@ -315,11 +315,11 @@ namespace CustomInterfaces
// Set peak and background ranges
std::map<std::string, double> ranges = getRangesFromInstrument();

std::pair<double, double> peakRange(ranges["peak-start-tof"], ranges["peak-end-tof"]);
std::pair<double, double> backgroundRange(ranges["back-start-tof"], ranges["back-end-tof"]);
QPair<double, double> peakRange(ranges["peak-start-tof"], ranges["peak-end-tof"]);
QPair<double, double> backgroundRange(ranges["back-start-tof"], ranges["back-end-tof"]);

setMiniPlotGuides("CalPeak", m_properties["CalPeakMin"], m_properties["CalPeakMax"], peakRange);
setMiniPlotGuides("CalBackground", m_properties["CalBackMin"], m_properties["CalBackMax"], backgroundRange);
setRangeSelector("CalPeak", m_properties["CalPeakMin"], m_properties["CalPeakMax"], peakRange);
setRangeSelector("CalBackground", m_properties["CalBackMin"], m_properties["CalBackMax"], backgroundRange);
}

/**
Expand Down Expand Up @@ -360,14 +360,14 @@ namespace CustomInterfaces
Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));

const Mantid::MantidVec & dataX = input->readX(0);
std::pair<double, double> range(dataX.front(), dataX.back());
QPair<double, double> range(dataX.front(), dataX.back());

m_uiForm.ppCalibration->clear();
m_uiForm.ppCalibration->addSpectrum("Raw", input, 0);
m_uiForm.ppCalibration->resizeX();

setPlotRange("CalPeak", m_properties["CalELow"], m_properties["CalEHigh"], range);
setPlotRange("CalBackground", m_properties["CalStart"], m_properties["CalEnd"], range);
setPlotPropertyRange("CalPeak", m_properties["CalELow"], m_properties["CalEHigh"], range);
setPlotPropertyRange("CalBackground", m_properties["CalStart"], m_properties["CalEnd"], range);

m_uiForm.ppCalibration->replot();

Expand Down Expand Up @@ -424,9 +424,9 @@ namespace CustomInterfaces
}

const Mantid::MantidVec & dataX = energyWs->readX(0);
std::pair<double, double> range(dataX.front(), dataX.back());
QPair<double, double> range(dataX.front(), dataX.back());

setPlotRange("ResBackground", m_properties["ResStart"], m_properties["ResEnd"], range);
setPlotPropertyRange("ResBackground", m_properties["ResStart"], m_properties["ResEnd"], range);

m_uiForm.ppResolution->clear();
m_uiForm.ppResolution->addSpectrum("Energy", energyWs, 0);
Expand Down Expand Up @@ -462,13 +462,13 @@ namespace CustomInterfaces
{
double res = params[0];

//Set default rebinning bounds
std::pair<double, double> peakRange(-res*10, res*10);
setMiniPlotGuides("ResPeak", m_properties["ResELow"], m_properties["ResEHigh"], peakRange);
// Set default rebinning bounds
QPair<double, double> peakRange(-res*10, res*10);
setRangeSelector("ResPeak", m_properties["ResELow"], m_properties["ResEHigh"], peakRange);

//Set default background bounds
std::pair<double, double> backgroundRange(-res*9, -res*8);
setMiniPlotGuides("ResBackground", m_properties["ResStart"], m_properties["ResEnd"], backgroundRange);
// Set default background bounds
QPair<double, double> backgroundRange(-res*9, -res*8);
setRangeSelector("ResBackground", m_properties["ResStart"], m_properties["ResEnd"], backgroundRange);
}
}
}
Expand Down
Expand Up @@ -215,10 +215,10 @@ namespace CustomInterfaces
//Set peak and background ranges
if(instDetails.size() >= 8)
{
setMiniPlotGuides("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"],
std::pair<double, double>(instDetails["peak-start"].toDouble(), instDetails["peak-end"].toDouble()));
setMiniPlotGuides("SliceBackground", m_properties["BackgroundStart"], m_properties["BackgroundEnd"],
std::pair<double, double>(instDetails["back-start"].toDouble(), instDetails["back-end"].toDouble()));
setRangeSelector("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"],
qMakePair(instDetails["peak-start"].toDouble(), instDetails["peak-end"].toDouble()));
setRangeSelector("SliceBackground", m_properties["BackgroundStart"], m_properties["BackgroundEnd"],
qMakePair(instDetails["back-start"].toDouble(), instDetails["back-end"].toDouble()));
}
}

Expand Down Expand Up @@ -258,13 +258,13 @@ namespace CustomInterfaces
Mantid::API::AnalysisDataService::Instance().retrieve(wsname.toStdString()));

const Mantid::MantidVec & dataX = input->readX(0);
std::pair<double, double> range(dataX.front(), dataX.back());
QPair<double, double> range(dataX.front(), dataX.back());

m_uiForm.ppRawPlot->clear();
m_uiForm.ppRawPlot->addSpectrum("Raw", input, 0);

setPlotRange("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"], range);
setPlotRange("SliceBackground", m_properties["BackgroundStart"], m_properties["BackgroundEnd"], range);
setPlotPropertyRange("SlicePeak", m_properties["PeakStart"], m_properties["PeakEnd"], range);
setPlotPropertyRange("SliceBackground", m_properties["BackgroundStart"], m_properties["BackgroundEnd"], range);

m_uiForm.ppRawPlot->resizeX();
}
Expand Down
Expand Up @@ -113,10 +113,9 @@ namespace CustomInterfaces

m_uiForm.ppRawPlot->clear();
m_uiForm.ppRawPlot->addSpectrum("Raw", filename, 0);
QPair<double, double> curveRange = m_uiForm.ppRawPlot->getCurveRange("Raw");
std::pair<double, double> range = std::make_pair(curveRange.first, curveRange.second);
setMiniPlotGuides("MomentsRangeSelector", m_properties["EMin"], m_properties["EMax"], range);
setPlotRange("MomentsRangeSelector", m_properties["EMin"], m_properties["EMax"], range);
QPair<double, double> range = m_uiForm.ppRawPlot->getCurveRange("Raw");
setRangeSelector("MomentsRangeSelector", m_properties["EMin"], m_properties["EMax"], range);
setPlotPropertyRange("MomentsRangeSelector", m_properties["EMin"], m_properties["EMax"], range);

connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(updateProperties(QtProperty*, double)));

Expand Down
153 changes: 6 additions & 147 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IndirectTab.cpp
Expand Up @@ -22,8 +22,7 @@ namespace CustomInterfaces
/** Constructor
*/
IndirectTab::IndirectTab(QObject* parent) : QObject(parent),
m_plots(), m_curves(), m_rangeSelectors(),
m_properties(),
m_rangeSelectors(), m_properties(),
m_dblManager(new QtDoublePropertyManager()), m_blnManager(new QtBoolPropertyManager()), m_grpManager(new QtGroupPropertyManager()),
m_dblEdFac(new DoubleEditorFactory()),
m_pythonRunner(),
Expand Down Expand Up @@ -143,146 +142,6 @@ namespace CustomInterfaces
return load->isExecuted();
}

/**
* Gets the range of the curve plotted in the mini plot
*
* @param curveID :: The string index of the curve in the m_curves map
* @return A pair containing the maximum and minimum points of the curve
*/
std::pair<double, double> IndirectTab::getCurveRange(const QString& curveID)
{
size_t npts = m_curves[curveID]->data().size();

if( npts < 2 )
throw std::invalid_argument("Too few points on data curve to determine range.");

return std::make_pair(m_curves[curveID]->data().x(0), m_curves[curveID]->data().x(npts-1));
}

/**
* Set the range of an axis on a miniplot
*
* @param plotID :: Index of plot in m_plots map
* @param axis :: ID of axis to set range of
* @param range :: Pair of double values specifying range
*/
void IndirectTab::setAxisRange(const QString& plotID, QwtPlot::Axis axis,
std::pair<double, double> range)
{
m_plots[plotID]->setAxisScale(axis, range.first, range.second);
}

/**
* Sets the X axis of a plot to match the range of x values on a curve
*
* @param plotID :: Index of plot in m_plots map
* @param curveID :: Index of curve in m_curves map
*/
void IndirectTab::setXAxisToCurve(const QString& plotID, const QString& curveID)
{
auto range = getCurveRange(curveID);
setAxisRange(plotID, QwtPlot::xBottom, range);
}

/**
* Plot a workspace to the miniplot given a workspace name and
* a specturm index.
*
* This method uses the analysis data service to retrieve the workspace.
*
* @param workspace :: The name of the workspace
* @param index :: The spectrum index of the workspace
* @param plotID :: String index of the plot in the m_plots map
* @param curveID :: String index of the curve in the m_curves map, defaults to plot ID
*/
void IndirectTab::plotMiniPlot(const QString& workspace, size_t index,
const QString& plotID, const QString& curveID)
{
auto ws = AnalysisDataService::Instance().retrieveWS<const MatrixWorkspace>(workspace.toStdString());
plotMiniPlot(ws, index, plotID, curveID);
}

/**
* Replot a given mini plot
*
* @param plotID :: ID of plot in m_plots map
*/
void IndirectTab::replot(const QString& plotID)
{
m_plots[plotID]->replot();
}

/**
* Removes a curve from a mini plot and deletes it.
*
* @param curveID :: ID of plot in m_plots map
*/
void IndirectTab::removeCurve(const QString& curveID)
{
if(m_curves[curveID] == NULL)
return;

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.
*
* @param workspace :: Pointer to the workspace
* @param wsIndex :: The spectrum index of the workspace
* @param plotID :: String index of the plot in the m_plots map
* @param curveID :: String index of the curve in the m_curves map, defaults to plot ID
*/
void IndirectTab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex,
const QString& plotID, const QString& curveID)
{
using Mantid::MantidVec;

QString cID = curveID;
if(cID == "")
cID = plotID;

//check if we can plot
if( wsIndex >= workspace->getNumberHistograms() || workspace->readX(0).size() < 2 )
return;

const bool logScale(false), distribution(false);
QwtWorkspaceSpectrumData wsData(*workspace, static_cast<int>(wsIndex), logScale, distribution);

removeCurve(cID);

size_t nhist = workspace->getNumberHistograms();
if ( wsIndex >= nhist )
{
emit showMessageBox("Error: Workspace index out of range.");
}
else
{
m_curves[cID] = new QwtPlotCurve();
m_curves[cID]->setData(wsData);
m_curves[cID]->attach(m_plots[plotID]);

m_plots[plotID]->replot();
}
}

/**
* Sets the edge bounds of plot to prevent the user inputting invalid values
* Also sets limits for range selector movement
Expand All @@ -292,8 +151,8 @@ namespace CustomInterfaces
* @param max :: The upper bound property in the property browser
* @param bounds :: The upper and lower bounds to be set
*/
void IndirectTab::setPlotRange(const QString& rsID, QtProperty* min, QtProperty* max,
const std::pair<double, double>& bounds)
void IndirectTab::setPlotPropertyRange(const QString& rsID, QtProperty* min, QtProperty* max,
const QPair<double, double> & bounds)
{
m_dblManager->setMinimum(min, bounds.first);
m_dblManager->setMaximum(min, bounds.second);
Expand All @@ -303,15 +162,15 @@ namespace CustomInterfaces
}

/**
* Set the position of the guides on the mini plot
* Set the position of the range selectors on the mini plot
*
* @param rsID :: The string index of the range selector in the map m_rangeSelectors
* @param lower :: The lower bound property in the property browser
* @param upper :: The upper bound property in the property browser
* @param bounds :: The upper and lower bounds to be set
*/
void IndirectTab::setMiniPlotGuides(const QString& rsID, QtProperty* lower, QtProperty* upper,
const std::pair<double, double>& bounds)
void IndirectTab::setRangeSelector(const QString& rsID, QtProperty* lower, QtProperty* upper,
const QPair<double, double> & bounds)
{
m_dblManager->setValue(lower, bounds.first);
m_dblManager->setValue(upper, bounds.second);
Expand Down

0 comments on commit 5b18086

Please sign in to comment.