Vespucci  1.0.0
QCPLayer Class Reference

A layer that may contain objects, to control the rendering order. More...

#include <qcustomplot.h>

Inheritance diagram for QCPLayer:

Public Member Functions

 QCPLayer (QCustomPlot *parentPlot, const QString &layerName)
 ~QCPLayer ()
QCustomPlotparentPlot () const
QString name () const
int index () const
QList< QCPLayerable * > children () const
bool visible () const
void setVisible (bool visible)

Protected Member Functions

void addChild (QCPLayerable *layerable, bool prepend)
void removeChild (QCPLayerable *layerable)

Protected Attributes

QString mName
int mIndex
QList< QCPLayerable * > mChildren
bool mVisible


class QCustomPlot
class QCPLayerable

Detailed Description

A layer that may contain objects, to control the rendering order.

The Layering system of QCustomPlot is the mechanism to control the rendering order of the elements inside the plot.

It is based on the two classes QCPLayer and QCPLayerable. QCustomPlot holds an ordered list of one or more instances of QCPLayer (see QCustomPlot::addLayer, QCustomPlot::layer, QCustomPlot::moveLayer, etc.). When replotting, QCustomPlot goes through the list of layers bottom to top and successively draws the layerables of the layers.

A QCPLayer contains an ordered list of QCPLayerable instances. QCPLayerable is an abstract base class from which almost all visible objects derive, like axes, grids, graphs, items, etc.

Initially, QCustomPlot has five layers: "background", "grid", "main", "axes" and "legend" (in that order). The top two layers "axes" and "legend" contain the default axes and legend, so they will be drawn on top. In the middle, there is the "main" layer. It is initially empty and set as the current layer (see QCustomPlot::setCurrentLayer). This means, all new plottables, items etc. are created on this layer by default. Then comes the "grid" layer which contains the QCPGrid instances (which belong tightly to QCPAxis, see QCPAxis::grid). The Axis rect background shall be drawn behind everything else, thus the default QCPAxisRect instance is placed on the "background" layer. Of course, the layer affiliation of the individual objects can be changed as required (QCPLayerable::setLayer).

Controlling the ordering of objects is easy: Create a new layer in the position you want it to be, e.g. above "main", with QCustomPlot::addLayer. Then set the current layer with QCustomPlot::setCurrentLayer to that new layer and finally create the objects normally. They will be placed on the new layer automatically, due to the current layer setting. Alternatively you could have also ignored the current layer setting and just moved the objects with QCPLayerable::setLayer to the desired layer after creating them.

It is also possible to move whole layers. For example, If you want the grid to be shown in front of all plottables/items on the "main" layer, just move it above "main" with QCustomPlot::moveLayer.

The rendering order within one layer is simply by order of creation or insertion. The item created last (or added last to the layer), is drawn on top of all other objects on that layer.

When a layer is deleted, the objects on it are not deleted with it, but fall on the layer below the deleted layer, see QCustomPlot::removeLayer.

Definition at line 370 of file qcustomplot.h.

Constructor & Destructor Documentation

QCPLayer::QCPLayer ( QCustomPlot parentPlot,
const QString &  layerName 

Creates a new QCPLayer instance.

Normally you shouldn't directly instantiate layers, use QCustomPlot::addLayer instead.

It is not checked that layerName is actually a unique layer name in parentPlot. This check is only performed by QCustomPlot::addLayer.

Definition at line 755 of file qcustomplot.cpp.

QCPLayer::~QCPLayer ( )

Definition at line 766 of file qcustomplot.cpp.

Member Function Documentation

void QCPLayer::addChild ( QCPLayerable layerable,
bool  prepend 

Definition at line 803 of file qcustomplot.cpp.

QList< QCPLayerable * > QCPLayer::children ( ) const

Returns a list of all layerables on this layer. The order corresponds to the rendering order: layerables with higher indices are drawn above layerables with lower indices.

Definition at line 388 of file qcustomplot.h.

int QCPLayer::index ( ) const

Returns the index this layer has in the QCustomPlot. The index is the integer number by which this layer can be accessed via QCustomPlot::layer.

Layers with higher indices will be drawn above layers with lower indices.

Definition at line 387 of file qcustomplot.h.

QString QCPLayer::name ( ) const

Definition at line 386 of file qcustomplot.h.

QCustomPlot* QCPLayer::parentPlot ( ) const

Definition at line 385 of file qcustomplot.h.

void QCPLayer::removeChild ( QCPLayerable layerable)

Definition at line 824 of file qcustomplot.cpp.

void QCPLayer::setVisible ( bool  visible)

Sets whether this layer is visible or not. If visible is set to false, all layerables on this layer will be invisible.

This function doesn't change the visibility property of the layerables (QCPLayerable::setVisible), but the QCPLayerable::realVisibility of each layerable takes the visibility of the parent layer into account.

Definition at line 788 of file qcustomplot.cpp.

bool QCPLayer::visible ( ) const

Definition at line 389 of file qcustomplot.h.

Friends And Related Function Documentation

friend class QCPLayerable

Definition at line 410 of file qcustomplot.h.

friend class QCustomPlot

Definition at line 409 of file qcustomplot.h.

Member Data Documentation

QList<QCPLayerable*> QCPLayer::mChildren

Definition at line 399 of file qcustomplot.h.

int QCPLayer::mIndex

Definition at line 398 of file qcustomplot.h.

QString QCPLayer::mName

Definition at line 397 of file qcustomplot.h.

QCustomPlot* QCPLayer::mParentPlot

Definition at line 396 of file qcustomplot.h.

bool QCPLayer::mVisible

Definition at line 400 of file qcustomplot.h.

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