Skip to content

Commit

Permalink
Add methods to get error bar settings for a curve. Re #2657.
Browse files Browse the repository at this point in the history
Although a Mantid curve's error bar settings can be accessed,
they aren't applied yet.
  • Loading branch information
RussellTaylor committed Jan 8, 2012
1 parent 14cddb6 commit cb26d89
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 21 deletions.
12 changes: 12 additions & 0 deletions Code/Mantid/MantidPlot/mantidplotpy/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ def addErrorBars(self, yColName, errTable, errColName, type=1, width=1, cap=8, c
"""
self._getHeldObject().addErrorBars(yColName,errTable._getHeldObject(),errColName,type,width,cap,color,through,minus,plus)

def errorBarSettings(self, curveIndex, errorBarIndex=0):
"""Get a handle to the error bar settings for a specified curve.
Args:
curveIndex: The curve to get the settings for
errorBarIndex: A curve can hold more than one set of error bars. Specify which one (default: the first).
Note that a curve plotted from a workspace can have only one set of error bars (and hence settings).
Returns: A handle to the error bar settings object.
"""
return QtProxyObject(self._getHeldObject().errorBarSettings(curveIndex,errorBarIndex))

def addHistogram(self, matrix):
"""Add a matrix histogram to the graph"""
self._getHeldObject().addHistogram(matrix._getHeldObject())
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/MantidPlot/src/FunctionCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class FunctionCurve: public PlotCurve
QString legend();

void loadData(int points = 0);


/// No error bars on this curve: Always return an empty list.
QList<ErrorBarSettings *> errorBarSettingsList() const {return QList<ErrorBarSettings*>();}

/// returns identifier where this curve plots a IFitFunction
const Mantid::API::IFitFunction* getIFitFunctionIdentifier() const {return m_identifier;};
private:
Expand Down
15 changes: 15 additions & 0 deletions Code/Mantid/MantidPlot/src/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "UserFunction.h"
#include "Mantid/MantidMatrixCurve.h"
#include "Mantid/MantidQwtMatrixWorkspaceData.h"
#include "Mantid/ErrorBarSettings.h"

#ifdef EMF_OUTPUT
#include "EmfEngine.h"
Expand Down Expand Up @@ -3010,6 +3011,20 @@ void Graph::removeMantidErrorBars(const QString& curveName)
return;
}

ErrorBarSettings* Graph::errorBarSettings(int curveIndex, int errorBarIndex)
{
PlotCurve* c = dynamic_cast<PlotCurve*>(curve(curveIndex));
if ( c && errorBarIndex >= 0 )
{
QList<ErrorBarSettings*> settings = c->errorBarSettingsList();
if ( errorBarIndex < settings.size() )
{
return settings[errorBarIndex];
}
}
return NULL;
}

QwtPieCurve* Graph::plotPie(Table* w, const QString& name, const QPen& pen, int brush,
int size, int firstColor, int startRow, int endRow, bool visible,
double d_start_azimuth, double d_view_angle, double d_thickness,
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/MantidPlot/src/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class BoxCurve;
class QwtHistogram;
class UserHelperFunction;
class QMutex;
class ErrorBarSettings;

namespace Mantid
{
Expand Down Expand Up @@ -336,6 +337,8 @@ public slots:

void updateErrorBars(QwtErrorPlotCurve *er, bool xErr, double width, int cap, const QColor& c, bool plus, bool minus, bool through);

ErrorBarSettings* errorBarSettings(int curveIndex, int errorBarIndex = 0);

//! Returns a valid master curve for the error bars curve.
DataCurve* masterCurve(QwtErrorPlotCurve *er);
//! Returns a valid master curve for a plot association.
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/ErrorBarSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "ErrorBarSettings.h"

/** Constructor.
* Sets defaults of black lines having width 1.0 and caps of length 10,
* Sets defaults of black lines having width 1.0 and caps of length 6,
* that show on both sides of the symbol but don't draw through it.
*/
ErrorBarSettings::ErrorBarSettings()
: m_cap(10), m_plus(true), m_minus(true), m_through(false),
: m_cap(6), m_plus(true), m_minus(true), m_through(false),
m_width(1.0), m_color(Qt::black)
{}

Expand Down
26 changes: 15 additions & 11 deletions Code/Mantid/MantidPlot/src/Mantid/MantidCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,27 @@
#include "../Graph.h"
#include "../ApplicationWindow.h"
#include "../MultiLayer.h"

/**
Constructor
@param wsName : Name of the workspace
@param err : flag indicating that errors should be used.
*/
MantidCurve::MantidCurve(const QString& wsName, bool err) : PlotCurve(wsName), WorkspaceObserver(), m_drawErrorBars(err), m_drawAllErrorBars(false)
{
}
#include "ErrorBarSettings.h"

/**
Constructor
@param wsName : Name of the workspace
@param err : flag indicating that all error bars should be used.
@param allError : flag indicating that all error bars should be plotted.
*/
MantidCurve::MantidCurve(const QString& wsName, bool err, bool allError) : PlotCurve(wsName), WorkspaceObserver(), m_drawErrorBars(err), m_drawAllErrorBars(allError)
MantidCurve::MantidCurve(const QString& wsName, bool err, bool allError)
: PlotCurve(wsName), WorkspaceObserver(),
m_drawErrorBars(err), m_drawAllErrorBars(allError), m_errorSettings(new ErrorBarSettings)
{
}

/**
Constructor
@param err : flag indicating that errors should be used.
*/
MantidCurve::MantidCurve(bool err) : PlotCurve(), WorkspaceObserver(), m_drawErrorBars(err), m_drawAllErrorBars(false)
MantidCurve::MantidCurve(bool err)
: PlotCurve(), WorkspaceObserver(),
m_drawErrorBars(err), m_drawAllErrorBars(false), m_errorSettings(new ErrorBarSettings)
{
}

Expand Down Expand Up @@ -120,6 +116,7 @@ void MantidCurve::axisScaleChanged(int axis, bool toLog)
/// Destructor
MantidCurve::~MantidCurve()
{
delete m_errorSettings;
}


Expand All @@ -129,6 +126,13 @@ void MantidCurve::itemChanged()
PlotCurve::itemChanged();
}

QList<ErrorBarSettings*> MantidCurve::errorBarSettingsList() const
{
QList<ErrorBarSettings*> retval;
retval.append(m_errorSettings);
return retval;
}

/** Create the name for a curve which is a copy of another curve.
* @param curveName :: The original curve name.
*/
Expand Down
15 changes: 9 additions & 6 deletions Code/Mantid/MantidPlot/src/Mantid/MantidCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include "MantidAPI/Workspace.h"
#include "MantidQwtWorkspaceData.h"

class Graph;
class ErrorBarSettings;

/** Base class for MantidCurve types.
@date 17/11/2011
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand All @@ -31,15 +32,12 @@
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class Graph;
class MantidCurve :public PlotCurve, public MantidQt::API::WorkspaceObserver
{
Q_OBJECT
public:
/// Constructor
MantidCurve(const QString& wsName, bool error);
/// Constructor
MantidCurve(const QString& wsName, bool error, bool allerror);
MantidCurve(const QString& wsName, bool error, bool allerror = false);
/// Default constructor
MantidCurve(bool err);
/// Destructor
Expand All @@ -59,6 +57,9 @@ class MantidCurve :public PlotCurve, public MantidQt::API::WorkspaceObserver
return m_drawErrorBars;
}

/// Returns the error bar settings for this curve (a MantidCurve has only one set of error bars)
virtual QList<ErrorBarSettings*> errorBarSettingsList() const;

/// Invalidates the bounding rect forcing it to be recalculated
void invalidateBoundingRect(){m_boundingRect = QwtDoubleRect();}

Expand Down Expand Up @@ -104,6 +105,8 @@ protected slots:
//To ensure that all MantidCurves can work with Mantid Workspaces.
virtual void init(Graph* g, bool distr, Graph::CurveType style) = 0;

// The error bar settings for this curve. Owned by this class.
ErrorBarSettings * m_errorSettings;
};

#endif
Expand Down
12 changes: 12 additions & 0 deletions Code/Mantid/MantidPlot/src/PlotCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "SymbolBox.h"
#include "PatternBox.h"
#include "plot2D/ScaleEngine.h"
#include "Mantid/ErrorBarSettings.h"
#include <QDateTime>
#include <QMessageBox>
#include <QPainter>
Expand Down Expand Up @@ -558,6 +559,17 @@ void DataCurve::loadData()
}
}

QList<ErrorBarSettings *> DataCurve::errorBarSettingsList() const
{
QList<ErrorBarSettings *> retval;
foreach(DataCurve* crv, d_error_bars)
{
ErrorBarSettings* err = dynamic_cast<ErrorBarSettings*>(crv);
if ( err ) retval << err; // (Should always be true)
}
return retval;
}

void DataCurve::removeErrorBars(DataCurve *c)
{
if (!c || d_error_bars.isEmpty())
Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/MantidPlot/src/PlotCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

class PlotMarker;
class Graph;
class ErrorBarSettings;

namespace Mantid
{
Expand Down Expand Up @@ -74,6 +75,9 @@ Q_OBJECT
//! Returns the number of symbols not to be drawn
int skipSymbolsCount() {return d_skip_symbols;}

/// Returns a list of error bar settings for each set of error bars associated to this curve
virtual QList<ErrorBarSettings*> errorBarSettingsList() const = 0;

// remove this curve form the graph (and delete from memory)
void removeMe(){emit removeMe(this);}

Expand Down Expand Up @@ -180,6 +184,8 @@ class DataCurve: public PlotCurve

//! The list of attached error bars.
QList<DataCurve *> errorBarsList()const{return d_error_bars;};
/// Returns a list of error bar settings for each set of error bars associated to this curve
virtual QList<ErrorBarSettings *> errorBarSettingsList() const;
//! Adds a single error bars curve to the list of attached error bars.
void addErrorBars(DataCurve *c){if (c) d_error_bars << c;};
//! Remove a single error bars curve from the list of attached error bars.
Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/MantidPlot/src/qti.sip
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ public:
int type = 1, double width = 1, int cap = 8, const QColor& color = QColor(Qt::black),
bool through = true, bool minus = true, bool plus = true);

ErrorBarSettings* errorBarSettings(int curveIndex, int errorBarIndex = 0);

void addHistogram(Matrix*);
void addArrow(ArrowMarker*);

Expand Down Expand Up @@ -868,7 +870,7 @@ private:
MultiLayer(const MultiLayer&);
};

class ErrorBarSettings
class ErrorBarSettings : QObject
{
%TypeHeaderCode
#include "../src/Mantid/ErrorBarSettings.h"
Expand Down

0 comments on commit cb26d89

Please sign in to comment.