Skip to content

Commit

Permalink
Add class holding settings for error bars. Re #2657.
Browse files Browse the repository at this point in the history
Very simple class of attributes and getters & setters,
pulled out of QwtErrorPlotCurve.
  • Loading branch information
RussellTaylor committed Jan 8, 2012
1 parent 6b8b7ff commit ad3d3b3
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 44 deletions.
82 changes: 82 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/ErrorBarSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "ErrorBarSettings.h"

/** Constructor.
* Sets defaults of black lines having width 1.0 and caps of length 10,
* 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_width(1.0), m_color(Qt::black)
{}

/// Return the length of the cap decoration on the error bars
int ErrorBarSettings::capLength() const
{
return m_cap;
}

/// Set the length of the cap decoration on the error bars
void ErrorBarSettings::setCapLength(int t)
{
m_cap = t;
}

/// Returns the width of the error bar lines. Overridden in QwtErrorPlotCurve.
double ErrorBarSettings::width() const
{
return m_width;
}

/// Sets the width of the error bar lines. Overridden in QwtErrorPlotCurve.
void ErrorBarSettings::setWidth(double w)
{
m_width = w;
}

/// Returns the color of the error bars. Overridden in QwtErrorPlotCurve.
QColor ErrorBarSettings::color() const
{
return m_color;
}

/// Sets the color of the error bars. Overridden in QwtErrorPlotCurve.
void ErrorBarSettings::setColor(const QColor& c)
{
m_color = c;
}

/// Returns whether the error bar lines are drawn through any symbol
bool ErrorBarSettings::throughSymbol() const
{
return m_through;
}

/// Sets whether to draw through any symbol
void ErrorBarSettings::drawThroughSymbol(bool yes)
{
m_through=yes;
}

/// Returns whether these error bars will be drawn on the positive side
bool ErrorBarSettings::plusSide() const
{
return m_plus;
}

/// Set whether these error bars will be drawn on the positive side
void ErrorBarSettings::drawPlusSide(bool yes)
{
m_plus=yes;
}

/// Returns whether these error bars will be drawn on the negative side
bool ErrorBarSettings::minusSide() const
{
return m_minus;
}

/// Set whether these error bars will be drawn on the negative side
void ErrorBarSettings::drawMinusSide(bool yes)
{
m_minus=yes;
}
58 changes: 58 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/ErrorBarSettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef ERRORBARSETTINGS_H
#define ERRORBARSETTINGS_H

#include <QColor>

/** Holds the settings for how a set of error bars are to be drawn.
Copyright &copy; 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class ErrorBarSettings
{
public:
ErrorBarSettings();

int capLength() const;
void setCapLength(int t);

virtual double width() const;
virtual void setWidth(double w);

virtual QColor color() const;
virtual void setColor(const QColor& c);

bool throughSymbol() const;
void drawThroughSymbol(bool yes);

bool plusSide() const;
void drawPlusSide(bool yes);

bool minusSide() const;
void drawMinusSide(bool yes);

private:
int m_cap; ///< Length of the bar cap decoration
bool m_plus; ///< Whether to draw these errors on the positive side
bool m_minus; ///< Whether to draw these errors on the negative side
bool m_through; ///< Whether to draw through any symbol on the curve

double m_width; ///< Width of the error bars (only used for Mantid error bars)
QColor m_color; ///< Color of the error bars (only used for Mantid error bars)
};

#endif
40 changes: 16 additions & 24 deletions Code/Mantid/MantidPlot/src/QwtErrorPlotCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,28 @@
#include <QPainter>

QwtErrorPlotCurve::QwtErrorPlotCurve(int orientation, Table *t, const QString& name) :
DataCurve(t, QString(), name), d_master_curve(NULL)
DataCurve(t, QString(), name), ErrorBarSettings(), d_master_curve(NULL)
{
cap = 10;
type = orientation;
plus = true;
minus = true;
through = false;
setType(Graph::ErrorBars);
setStyle(QwtPlotCurve::UserCurve);
}

QwtErrorPlotCurve::QwtErrorPlotCurve(Table *t, const QString& name) :
DataCurve(t, QString(), name), d_master_curve(NULL)
DataCurve(t, QString(), name), ErrorBarSettings(), d_master_curve(NULL)
{
cap = 10;
type = Vertical;
plus = true;
minus = true;
through = false;
setType(Graph::ErrorBars);
setStyle(QwtPlotCurve::UserCurve);
}

void QwtErrorPlotCurve::copy(const QwtErrorPlotCurve *e)
{
cap = e->cap;
setCapLength(e->capLength());
type = e->type;
plus = e->plus;
minus = e->minus;
through = e->through;
drawPlusSide(e->plusSide());
drawMinusSide(e->minusSide());
drawThroughSymbol(e->throughSymbol());
setPen(e->pen());
err = e->err;
}
Expand Down Expand Up @@ -116,17 +108,17 @@ void QwtErrorPlotCurve::drawErrorBars(QPainter *painter, const QwtScaleMap &xMap
const int yhl = yi - sh / 2;
const int ylh = yi + sh / 2;

if (plus)
if (plusSide())
{
QwtPainter::drawLine(painter, xi, yhl, xi, yh);
QwtPainter::drawLine(painter, xi - cap / 2, yh, xi + cap / 2, yh);
QwtPainter::drawLine(painter, xi - capLength() / 2, yh, xi + capLength() / 2, yh);
}
if (minus)
if (minusSide())
{
QwtPainter::drawLine(painter, xi, ylh, xi, yl);
QwtPainter::drawLine(painter, xi - cap / 2, yl, xi + cap / 2, yl);
QwtPainter::drawLine(painter, xi - capLength() / 2, yl, xi + capLength() / 2, yl);
}
if (through)
if (throughSymbol())
QwtPainter::drawLine(painter, xi, yhl, xi, ylh);
}
else if (type == Horizontal)
Expand All @@ -136,17 +128,17 @@ void QwtErrorPlotCurve::drawErrorBars(QPainter *painter, const QwtScaleMap &xMap
const int xpm = xi + sw / 2;
const int xmp = xi - sw / 2;

if (plus)
if (plusSide())
{
QwtPainter::drawLine(painter, xp, yi, xpm, yi);
QwtPainter::drawLine(painter, xp, yi - cap / 2, xp, yi + cap / 2);
QwtPainter::drawLine(painter, xp, yi - capLength() / 2, xp, yi + capLength() / 2);
}
if (minus)
if (minusSide())
{
QwtPainter::drawLine(painter, xm, yi, xmp, yi);
QwtPainter::drawLine(painter, xm, yi - cap / 2, xm, yi + cap / 2);
QwtPainter::drawLine(painter, xm, yi - capLength() / 2, xm, yi + capLength() / 2);
}
if (through)
if (throughSymbol())
QwtPainter::drawLine(painter, xmp, yi, xpm, yi);
}
}
Expand Down
24 changes: 4 additions & 20 deletions Code/Mantid/MantidPlot/src/QwtErrorPlotCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
#define ERRORBARS_H

#include "PlotCurve.h"
#include "Mantid/ErrorBarSettings.h"
#include <qwt_plot.h>

//! Error bars curve
class QwtErrorPlotCurve: public DataCurve
class QwtErrorPlotCurve: public DataCurve, public ErrorBarSettings
{
public:
enum Orientation{Horizontal = 0, Vertical = 1};
Expand All @@ -49,9 +50,6 @@ class QwtErrorPlotCurve: public DataCurve
QwtArray<double> errors(){return err;};
void setErrors(const QwtArray<double>&data){err=data;};

int capLength(){return cap;};
void setCapLength(int t){cap=t;};

double width(){return pen().widthF();};
void setWidth(double w);

Expand All @@ -64,15 +62,6 @@ class QwtErrorPlotCurve: public DataCurve
bool xErrors();
void setXErrors(bool yes);

bool throughSymbol(){return through;};
void drawThroughSymbol(bool yes){through=yes;};

bool plusSide(){return plus;};
void drawPlusSide(bool yes){plus=yes;};

bool minusSide(){return minus;};
void drawMinusSide(bool yes){minus=yes;};

//! Returns the master curve to which this error bars curve is attached.
DataCurve* masterCurve(){return d_master_curve;};
void setMasterCurve(DataCurve *c);
Expand All @@ -96,13 +85,8 @@ class QwtErrorPlotCurve: public DataCurve
//! Stores the error bar values
QwtArray<double> err;

//! Orientation of the bars: Horizontal or Vertical
int type;

//! Length of the bar cap decoration
int cap;

bool plus, minus, through;
//! Orientation of the bars: Horizontal or Vertical
int type;

//! Reference to the master curve to which this error bars curve is attached.
DataCurve *d_master_curve;
Expand Down

0 comments on commit ad3d3b3

Please sign in to comment.