Base class for all objects that can be placed on layers. More...
Public Functions | |
QCPLayerable (QCustomPlot *parentPlot) | |
bool | visible () const |
QCustomPlot * | parentPlot () const |
QCPLayer * | layer () const |
bool | antialiased () const |
void | setVisible (bool on) |
bool | setLayer (QCPLayer *layer) |
bool | setLayer (const QString &layerName) |
void | setAntialiased (bool enabled) |
Protected Functions | |
bool | moveToLayer (QCPLayer *layer, bool prepend) |
void | applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const |
virtual void | applyDefaultAntialiasingHint (QCPPainter *painter) const =0 |
virtual QRect | clipRect () const |
virtual void | draw (QCPPainter *painter)=0 |
Base class for all objects that can be placed on layers.
This is the abstract base class most visible objects derive from, e.g. plottables, axes, grid etc.
Every layerable is on a layer (QCPLayer) which allows controlling the rendering order by stacking the layers accordingly.
For details about the layering mechanism, see the QCPLayer documentation.
QCPLayerable::QCPLayerable | ( | QCustomPlot * | parentPlot | ) |
Creates a new QCPLayerable instance.
Since QCPLayerable is an abstract base class, it can't be instantiated directly. Use one of the derived classes.
void QCPLayerable::setVisible | ( | bool | on | ) |
Sets the visibility of this layerable object. If an object is not visible, it will not be drawn on the QCustomPlot surface, and user interaction with it (e.g. click/selection) is not possible.
bool QCPLayerable::setLayer | ( | QCPLayer * | layer | ) |
Sets the layer of this layerable object. The object will be placed on top of the other objects already on layer.
Returns true on success, i.e. if layer is a valid layer.
bool QCPLayerable::setLayer | ( | const QString & | layerName | ) |
This is an overloaded function.
Sets the layer of this layerable object by name
Returns true on success, i.e. if layerName is a valid layer name.
void QCPLayerable::setAntialiased | ( | bool | enabled | ) |
Sets whether this object will be drawn antialiased or not.
Note that antialiasing settings may be overridden by QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.
bool QCPLayerable::moveToLayer | ( | QCPLayer * | layer, |
bool | prepend | ||
) | [protected] |
Moves this layerable object to layer. If prepend is true, this object will be prepended to the new layer's list, i.e. it will be drawn below the objects already on the layer. If it is false, the object will be appended.
Returns true on success, i.e. if layer is a valid layer.
void QCPLayerable::applyAntialiasingHint | ( | QCPPainter * | painter, |
bool | localAntialiased, | ||
QCP::AntialiasedElement | overrideElement | ||
) | const [protected] |
Sets the QPainter::Antialiasing render hint on the provided painter, depending on the localAntialiased value as well as the overrides QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements. Which override enum this function takes into account is controlled via overrideElement.
void QCPLayerable::applyDefaultAntialiasingHint | ( | QCPPainter * | painter | ) | const [protected, pure virtual] |
This function applies the default antialiasing setting to the specified painter, using the function applyAntialiasingHint. This is the antialiasing state the painter is in, when draw is called on the layerable. If the layerable has multiple entities whose antialiasing setting may be specified individually, this function should set the antialiasing state of the most prominent entity. In this case however, the draw function usually calls the specialized versions of this function before drawing each entity, effectively overriding the setting of the default antialiasing hint.
First example: QCPGraph has multiple entities that have an antialiasing setting: The graph line, fills, scatters and error bars. Those can be configured via QCPGraph::setAntialiased, QCPGraph::setAntialiasedFill, QCPGraph::setAntialiasedScatters etc. Consequently, there isn't only the QCPGraph::applyDefaultAntialiasingHint function (which corresponds to the graph line's antialiasing), but specialized ones like QCPGraph::applyFillAntialiasingHint and QCPGraph::applyScattersAntialiasingHint. So before drawing one of those entities, QCPGraph::draw calls the respective specialized applyAntialiasingHint function.
Second example: QCPItemLine consists only of a line so there is only one antialiasing setting which can be controlled with QCPItemLine::setAntialiased. (This function is inherited by all layerables. The specialized functions, as seen on QCPGraph, must be added explicitly to the respective layerable subclass.) Consequently it only has the normal QCPItemLine::applyDefaultAntialiasingHint. The QCPItemLine::draw function doesn't need to care about setting any antialiasing states, because the default antialiasing hint is already set on the painter when the draw function is called, and that's the state it wants to draw the line with.
Implemented in QCPAxis, QCPGrid, QCPLegend, QCPAbstractItem, and QCPAbstractPlottable.
QRect QCPLayerable::clipRect | ( | ) | const [protected, virtual] |
Returns the clipping rectangle of this layerable object. By default, this is the viewport of the parent QCustomPlot. Specific subclasses may reimplement this function to provide different clipping rects.
The returned clipping rect is set on the painter before the draw function of the respective object is called.
Reimplemented in QCPAbstractItem, and QCPAbstractPlottable.
void QCPLayerable::draw | ( | QCPPainter * | painter | ) | [protected, pure virtual] |
This function draws the layerable to the specified painter.
Before this function is called, the painter's antialiasing state is set via applyDefaultAntialiasingHint, see the documentation there. Further, its clipping rectangle was set to clipRect.
Implemented in QCPAxis, QCPGrid, QCPLegend, QCPItemTracer, QCPItemBracket, QCPItemCurve, QCPItemText, QCPItemPixmap, QCPItemRect, QCPItemEllipse, QCPItemLine, QCPItemStraightLine, QCPAbstractItem, QCPStatisticalBox, QCPBars, QCPCurve, QCPGraph, and QCPAbstractPlottable.