Main Page · Class Overview · Hierarchy · All Classes
Public Functions | Protected Functions
QCPStatisticalBox Class Reference

A plottable representing a single statistical box in a plot. More...

Inheritance diagram for QCPStatisticalBox:
Inheritance graph

Public Functions

 QCPStatisticalBox (QCPAxis *keyAxis, QCPAxis *valueAxis)
double key () const
double minimum () const
double lowerQuartile () const
double median () const
double upperQuartile () const
double maximum () const
QVector< double > outliers () const
double width () const
double whiskerWidth () const
QPen whiskerPen () const
QPen whiskerBarPen () const
QPen medianPen () const
QCPScatterStyle outlierStyle () const
void setKey (double key)
void setMinimum (double value)
void setLowerQuartile (double value)
void setMedian (double value)
void setUpperQuartile (double value)
void setMaximum (double value)
void setOutliers (const QVector< double > &values)
void setData (double key, double minimum, double lowerQuartile, double median, double upperQuartile, double maximum)
void setWidth (double width)
void setWhiskerWidth (double width)
void setWhiskerPen (const QPen &pen)
void setWhiskerBarPen (const QPen &pen)
void setMedianPen (const QPen &pen)
void setOutlierStyle (const QCPScatterStyle &style)
virtual void clearData ()
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const
- Public Functions inherited from QCPAbstractPlottable
 QCPAbstractPlottable (QCPAxis *keyAxis, QCPAxis *valueAxis)
QString name () const
bool antialiasedFill () const
bool antialiasedScatters () const
bool antialiasedErrorBars () const
QPen pen () const
QPen selectedPen () const
QBrush brush () const
QBrush selectedBrush () const
QCPAxiskeyAxis () const
QCPAxisvalueAxis () const
bool selectable () const
bool selected () const
void setName (const QString &name)
void setAntialiasedFill (bool enabled)
void setAntialiasedScatters (bool enabled)
void setAntialiasedErrorBars (bool enabled)
void setPen (const QPen &pen)
void setSelectedPen (const QPen &pen)
void setBrush (const QBrush &brush)
void setSelectedBrush (const QBrush &brush)
void setKeyAxis (QCPAxis *axis)
void setValueAxis (QCPAxis *axis)
Q_SLOT void setSelectable (bool selectable)
Q_SLOT void setSelected (bool selected)
virtual bool addToLegend ()
virtual bool removeFromLegend () const
void rescaleAxes (bool onlyEnlarge=false) const
void rescaleKeyAxis (bool onlyEnlarge=false) const
void rescaleValueAxis (bool onlyEnlarge=false) const
- Public Functions inherited from QCPLayerable
 QCPLayerable (QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0)
bool visible () const
QCustomPlotparentPlot () const
QCPLayerableparentLayerable () const
QCPLayerlayer () const
bool antialiased () const
void setVisible (bool on)
Q_SLOT bool setLayer (QCPLayer *layer)
bool setLayer (const QString &layerName)
void setAntialiased (bool enabled)
bool realVisibility () const

Protected Functions

virtual void draw (QCPPainter *painter)
virtual void drawLegendIcon (QCPPainter *painter, const QRectF &rect) const
virtual QCPRange getKeyRange (bool &foundRange, SignDomain inSignDomain=sdBoth) const
virtual QCPRange getValueRange (bool &foundRange, SignDomain inSignDomain=sdBoth) const
virtual void drawQuartileBox (QCPPainter *painter, QRectF *quartileBox=0) const
virtual void drawMedian (QCPPainter *painter) const
virtual void drawWhiskers (QCPPainter *painter) const
virtual void drawOutliers (QCPPainter *painter) const
- Protected Functions inherited from QCPAbstractPlottable
virtual QRect clipRect () const
virtual QCP::Interaction selectionCategory () const
void applyDefaultAntialiasingHint (QCPPainter *painter) const
virtual void selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged)
virtual void deselectEvent (bool *selectionStateChanged)
void coordsToPixels (double key, double value, double &x, double &y) const
const QPointF coordsToPixels (double key, double value) const
void pixelsToCoords (double x, double y, double &key, double &value) const
void pixelsToCoords (const QPointF &pixelPos, double &key, double &value) const
QPen mainPen () const
QBrush mainBrush () const
void applyFillAntialiasingHint (QCPPainter *painter) const
void applyScattersAntialiasingHint (QCPPainter *painter) const
void applyErrorBarsAntialiasingHint (QCPPainter *painter) const
double distSqrToLine (const QPointF &start, const QPointF &end, const QPointF &point) const
- Protected Functions inherited from QCPLayerable
virtual void parentPlotInitialized (QCustomPlot *parentPlot)
void initializeParentPlot (QCustomPlot *parentPlot)
void setParentLayerable (QCPLayerable *parentLayerable)
bool moveToLayer (QCPLayer *layer, bool prepend)
void applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const

Additional Inherited Members

- Signals inherited from QCPAbstractPlottable
void selectionChanged (bool selected)
void selectableChanged (bool selectable)
- Protected Types inherited from QCPAbstractPlottable
enum  SignDomain

Detailed Description

A plottable representing a single statistical box in a plot.

QCPStatisticalBox.png

To plot data, assign it with the individual parameter functions or use setData to set all parameters at once. The individual functions are:

Additionally you can define a list of outliers, drawn as scatter datapoints:

Changing the appearance

The appearance of the box itself is controlled via setPen and setBrush. You may change the width of the box with setWidth in plot coordinates (not pixels).

Analog functions exist for the minimum/maximum-whiskers: setWhiskerPen, setWhiskerBarPen, setWhiskerWidth. The whisker width is the width of the bar at the top (maximum) and bottom (minimum).

The median indicator line has its own pen, setMedianPen.

If the whisker backbone pen is changed, make sure to set the capStyle to Qt::FlatCap. Else, the backbone line might exceed the whisker bars by a few pixels due to the pen cap being not perfectly flat.

The Outlier data points are drawn as normal scatter points. Their look can be controlled with setOutlierStyle

Usage

Like all data representing objects in QCustomPlot, the QCPStatisticalBox is a plottable (QCPAbstractPlottable). So the plottable-interface of QCustomPlot applies (QCustomPlot::plottable, QCustomPlot::addPlottable, QCustomPlot::removePlottable, etc.)

Usually, you first create an instance:

QCPStatisticalBox *newBox = new QCPStatisticalBox(customPlot->xAxis, customPlot->yAxis);

add it to the customPlot with QCustomPlot::addPlottable:

customPlot->addPlottable(newBox);

and then modify the properties of the newly created plottable, e.g.:

newBox->setName("Measurement Series 1");
newBox->setData(1, 3, 4, 5, 7);
newBox->setOutliers(QVector<double>() << 0.5 << 0.64 << 7.2 << 7.42);

Constructor & Destructor Documentation

QCPStatisticalBox::QCPStatisticalBox ( QCPAxis keyAxis,
QCPAxis valueAxis 
)
explicit

Constructs a statistical box which uses keyAxis as its key axis ("x") and valueAxis as its value axis ("y"). keyAxis and valueAxis must reside in the same QCustomPlot instance and not have the same orientation. If either of these restrictions is violated, a corresponding message is printed to the debug output (qDebug), the construction is not aborted, though.

The constructed statistical box can be added to the plot with QCustomPlot::addPlottable, QCustomPlot then takes ownership of the statistical box.

Member Function Documentation

void QCPStatisticalBox::setKey ( double  key)

Sets the key coordinate of the statistical box.

void QCPStatisticalBox::setMinimum ( double  value)

Sets the parameter "minimum" of the statistical box plot. This is the position of the lower whisker, typically the minimum measurement of the sample that's not considered an outlier.

See Also
setMaximum, setWhiskerPen, setWhiskerBarPen, setWhiskerWidth
void QCPStatisticalBox::setLowerQuartile ( double  value)

Sets the parameter "lower Quartile" of the statistical box plot. This is the lower end of the box. The lower and the upper quartiles are the two statistical quartiles around the median of the sample, they contain 50% of the sample data.

See Also
setUpperQuartile, setPen, setBrush, setWidth
void QCPStatisticalBox::setMedian ( double  value)

Sets the parameter "median" of the statistical box plot. This is the value of the median mark inside the quartile box. The median separates the sample data in half (50% of the sample data is below/above the median).

See Also
setMedianPen
void QCPStatisticalBox::setUpperQuartile ( double  value)

Sets the parameter "upper Quartile" of the statistical box plot. This is the upper end of the box. The lower and the upper quartiles are the two statistical quartiles around the median of the sample, they contain 50% of the sample data.

See Also
setLowerQuartile, setPen, setBrush, setWidth
void QCPStatisticalBox::setMaximum ( double  value)

Sets the parameter "maximum" of the statistical box plot. This is the position of the upper whisker, typically the maximum measurement of the sample that's not considered an outlier.

See Also
setMinimum, setWhiskerPen, setWhiskerBarPen, setWhiskerWidth
void QCPStatisticalBox::setOutliers ( const QVector< double > &  values)

Sets a vector of outlier values that will be drawn as scatters. Any data points in the sample that are not within the whiskers (setMinimum, setMaximum) should be considered outliers and displayed as such.

See Also
setOutlierStyle
void QCPStatisticalBox::setData ( double  key,
double  minimum,
double  lowerQuartile,
double  median,
double  upperQuartile,
double  maximum 
)

Sets all parameters of the statistical box plot at once.

See Also
setKey, setMinimum, setLowerQuartile, setMedian, setUpperQuartile, setMaximum
void QCPStatisticalBox::setWidth ( double  width)

Sets the width of the box in key coordinates.

See Also
setWhiskerWidth
void QCPStatisticalBox::setWhiskerWidth ( double  width)

Sets the width of the whiskers (setMinimum, setMaximum) in key coordinates.

See Also
setWidth
void QCPStatisticalBox::setWhiskerPen ( const QPen &  pen)

Sets the pen used for drawing the whisker backbone (That's the line parallel to the value axis).

Make sure to set the pen capStyle to Qt::FlatCap to prevent the whisker backbone from reaching a few pixels past the whisker bars, when using a non-zero pen width.

See Also
setWhiskerBarPen
void QCPStatisticalBox::setWhiskerBarPen ( const QPen &  pen)

Sets the pen used for drawing the whisker bars (Those are the lines parallel to the key axis at each end of the whisker backbone).

See Also
setWhiskerPen
void QCPStatisticalBox::setMedianPen ( const QPen &  pen)

Sets the pen used for drawing the median indicator line inside the statistical box.

void QCPStatisticalBox::setOutlierStyle ( const QCPScatterStyle style)

Sets the appearance of the outlier data points.

See Also
setOutliers
void QCPStatisticalBox::clearData ( )
virtual

Clears all data in the plottable.

Implements QCPAbstractPlottable.

double QCPStatisticalBox::selectTest ( const QPointF &  pos,
bool  onlySelectable,
QVariant *  details = 0 
) const
virtual

This function is used to decide whether a click hits a layerable object or not.

pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the shortest pixel distance of this point to the object. If the object is either invisible or the distance couldn't be determined, -1.0 is returned. Further, if onlySelectable is true and the object is not selectable, -1.0 is returned, too.

If the item is represented not by single lines but by an area like QCPItemRect or QCPItemText, a click inside the area returns a constant value greater zero (typically the selectionTolerance of the parent QCustomPlot multiplied by 0.99). If the click lies outside the area, this function returns -1.0.

Providing a constant value for area objects allows selecting line objects even when they are obscured by such area objects, by clicking close to the lines (i.e. closer than 0.99*selectionTolerance).

The actual setting of the selection state is not done by this function. This is handled by the parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified via the selectEvent/deselectEvent methods.

details is an optional output parameter. Every layerable subclass may place any information in details. This information will be passed to selectEvent when the parent QCustomPlot decides on the basis of this selectTest call, that the object was successfully selected. The subsequent call to selectEvent will carry the details. This is useful for multi-part objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked is only done once in selectTest. The result (i.e. the actually clicked part) can then be placed in details. So in the subsequent selectEvent, the decision which part was selected doesn't have to be done a second time for a single selection operation.

You may pass 0 as details to indicate that you are not interested in those selection details.

See Also
selectEvent, deselectEvent, QCustomPlot::setInteractions

Implements QCPAbstractPlottable.

void QCPStatisticalBox::draw ( QCPPainter painter)
protectedvirtual

This function draws the layerable with the specified painter. It is only called by QCustomPlot, if the layerable is visible (setVisible).

Before this function is called, the painter's antialiasing state is set via applyDefaultAntialiasingHint, see the documentation there. Further, the clipping rectangle was set to clipRect.

Implements QCPAbstractPlottable.

void QCPStatisticalBox::drawLegendIcon ( QCPPainter painter,
const QRectF &  rect 
) const
protectedvirtual

called by QCPLegend::draw (via QCPPlottableLegendItem::draw) to create a graphical representation of this plottable inside rect, next to the plottable name.

Implements QCPAbstractPlottable.

QCPRange QCPStatisticalBox::getKeyRange ( bool &  foundRange,
SignDomain  inSignDomain = sdBoth 
) const
protectedvirtual

called by rescaleAxes functions to get the full data key bounds. For logarithmic plots, one can set inSignDomain to either sdNegative or sdPositive in order to restrict the returned range to that sign domain. E.g. when only negative range is wanted, set inSignDomain to sdNegative and all positive points will be ignored for range calculation. For no restriction, just set inSignDomain to sdBoth (default). foundRange is an output parameter that indicates whether a range could be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data).

Note that foundRange is not the same as QCPRange::validRange, since the range returned by this function may have size zero, which wouldn't count as a valid range.

See Also
rescaleAxes, getValueRange

Implements QCPAbstractPlottable.

QCPRange QCPStatisticalBox::getValueRange ( bool &  foundRange,
SignDomain  inSignDomain = sdBoth 
) const
protectedvirtual

called by rescaleAxes functions to get the full data value bounds. For logarithmic plots, one can set inSignDomain to either sdNegative or sdPositive in order to restrict the returned range to that sign domain. E.g. when only negative range is wanted, set inSignDomain to sdNegative and all positive points will be ignored for range calculation. For no restriction, just set inSignDomain to sdBoth (default). foundRange is an output parameter that indicates whether a range could be found or not. If this is false, you shouldn't use the returned range (e.g. no points in data).

Note that foundRange is not the same as QCPRange::validRange, since the range returned by this function may have size zero, which wouldn't count as a valid range.

See Also
rescaleAxes, getKeyRange

Implements QCPAbstractPlottable.

void QCPStatisticalBox::drawQuartileBox ( QCPPainter painter,
QRectF *  quartileBox = 0 
) const
protectedvirtual

Draws the quartile box. box is an output parameter that returns the quartile box (in pixel coordinates) which is used to set the clip rect of the painter before calling drawMedian (so the median doesn't draw outside the quartile box).

void QCPStatisticalBox::drawMedian ( QCPPainter painter) const
protectedvirtual

Draws the median line inside the quartile box.

void QCPStatisticalBox::drawWhiskers ( QCPPainter painter) const
protectedvirtual

Draws both whisker backbones and bars.

void QCPStatisticalBox::drawOutliers ( QCPPainter painter) const
protectedvirtual

Draws the outlier scatter points.


The documentation for this class was generated from the following files: