· · ·
Public Types | Public Functions | Protected Functions
QCPLayoutElement Class Reference

The abstract base class for all objects that form the layout system. More...

Inheritance diagram for QCPLayoutElement:

## Public Types
enum | UpdatePhase

## Public Functions
| QCPLayoutElement (QCustomPlot *parentPlot=0)
QCPLayout * | layout () const
QRect | rect () const
QRect | outerRect () const
QMargins | margins () const
QMargins | minimumMargins () const
QCP::MarginSides | autoMargins () const
QSize | minimumSize () const
QSize | maximumSize () const
QCPMarginGroup * | marginGroup (QCP::MarginSide side) const
QHash< QCP::MarginSide, QCPMarginGroup * > | marginGroups () const
void | setOuterRect (const QRect &rect)
void | setMargins (const QMargins &margins)
void | setMinimumMargins (const QMargins &margins)
void | setAutoMargins (QCP::MarginSides sides)
void | setMinimumSize (const QSize &size)
void | setMinimumSize (int width, int height)
void | setMaximumSize (const QSize &size)
void | setMaximumSize (int width, int height)
void | setMarginGroup (QCP::MarginSides sides, QCPMarginGroup *group)
virtual void | update (UpdatePhase phase)
virtual QSize | minimumSizeHint () const
virtual QSize | maximumSizeHint () const
virtual QList< QCPLayoutElement * > | elements (bool recursive) const
virtual double | selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const
Public Functions inherited from QCPLayerable
| QCPLayerable (QCustomPlot *plot, QString targetLayer="", QCPLayerable *parentLayerable=0)
bool | visible () const
QCustomPlot * | parentPlot () const
QCPLayerable * | parentLayerable () const
QCPLayer * | layer () 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 int | calculateAutoMargin (QCP::MarginSide side)
virtual void | mousePressEvent (QMouseEvent *event)
virtual void | mouseMoveEvent (QMouseEvent *event)
virtual void | mouseReleaseEvent (QMouseEvent *event)
virtual void | mouseDoubleClickEvent (QMouseEvent *event)
virtual void | wheelEvent (QWheelEvent *event)
virtual void | applyDefaultAntialiasingHint (QCPPainter *painter) const
virtual void | draw (QCPPainter *painter)
virtual void | parentPlotInitialized (QCustomPlot *parentPlot)
Protected Functions inherited from QCPLayerable
virtual QCP::Interaction | selectionCategory () const
virtual QRect | clipRect () const
virtual void | selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged)
virtual void | deselectEvent (bool *selectionStateChanged)
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 QCPLayerable
void | layerChanged (QCPLayer *newLayer)

## Detailed Description

The abstract base class for all objects that form the layout system.

This is an abstract base class. As such, it can't be instantiated directly, rather use one of its subclasses.

A Layout element is a rectangular object which can be placed in layouts. It has an outer rect (QCPLayoutElement::outerRect) and an inner rect (QCPLayoutElement::rect). The difference between outer and inner rect is called its margin. The margin can either be set to automatic or manual (setAutoMargins) on a per-side basis. If a side is set to manual, that margin can be set explicitly with setMargins and will stay fixed at that value. If it's set to automatic, the layout element subclass will control the value itself (via calculateAutoMargin).

Layout elements can be placed in layouts (base class QCPLayout) like QCPLayoutGrid. The top level layout is reachable via QCustomPlot::plotLayout, and is a QCPLayoutGrid. Since QCPLayout itself derives from QCPLayoutElement, layouts can be nested.

Thus in QCustomPlot one can divide layout elements into two categories: The ones that are invisible by themselves, because they don't draw anything. Their only purpose is to manage the position and size of other layout elements. This category of layout elements usually use QCPLayout as base class. Then there is the category of layout elements which actually draw something. For example, QCPAxisRect, QCPLegend and QCPPlotTitle are of this category. This does not necessarily mean that the latter category can't have child layout elements. QCPLegend for instance, actually derives from QCPLayoutGrid and the individual legend items are child layout elements in the grid layout.

## Member Enumeration Documentation

enum QCPLayoutElement::UpdatePhase

Defines the phases of the update process, that happens just before a replot. At each phase, update is called with the according UpdatePhase value.

Enumerator:

  upPreparation | Phase used for any type of preparation that needs to be done before margin calculation and layout.
  upMargins | Phase in which the margins are calculated and set.
  upLayout | Final phase in which the layout system places the rects of the elements.

## Constructor & Destructor Documentation

QCPLayoutElement::QCPLayoutElement | ( | QCustomPlot * | parentPlot = `0` | ) |
| explicit

Creates an instance of QCPLayoutElement and sets default values.

## Member Function Documentation

QCPLayout * QCPLayoutElement::layout | ( |  | ) | const
| inline

Returns the parent layout of this layout element.

QRect QCPLayoutElement::rect | ( |  | ) | const
| inline

Returns the inner rect of this layout element. The inner rect is the outer rect (setOuterRect) shrinked by the margins (setMargins, setAutoMargins).

In some cases, the area between outer and inner rect is left blank. In other cases the margin area is used to display peripheral graphics while the main content is in the inner rect. This is where automatic margin calculation becomes interesting because it allows the layout element to adapt the margins to the peripheral graphics it wants to draw. For example, QCPAxisRect draws the axis labels and tick labels in the margin area, thus needs to adjust the margins (if setAutoMargins is enabled) according to the space required by the labels of the axes.

void QCPLayoutElement::setOuterRect | ( | const QRect & | rect | ) |

Sets the outer rect of this layout element. If the layout element is inside a layout, the layout sets the position and size of this layout element using this function.

Calling this function externally has no effect, since the layout will overwrite any changes to the outer rect upon the next replot.

The layout element will adapt its inner rect by applying the margins inward to the outer rect.

See Also
  rect

void QCPLayoutElement::setMargins | ( | const QMargins & | margins | ) |

Sets the margins of this layout element. If setAutoMargins is disabled for some or all sides, this function is used to manually set the margin on those sides. Sides that are still set to be handled automatically are ignored and may have any value in margins.

The margin is the distance between the outer rect (controlled by the parent layout via setOuterRect) and the inner rect (which usually contains the main content of this layout element).

See Also
  setAutoMargins

void QCPLayoutElement::setMinimumMargins | ( | const QMargins & | margins | ) |

If setAutoMargins is enabled on some or all margins, this function is used to provide minimum values for those margins.

The minimum values are not enforced on margin sides that were set to be under manual control via setAutoMargins.

See Also
  setAutoMargins

void QCPLayoutElement::setAutoMargins | ( | QCP::MarginSides | sides | ) |

Sets on which sides the margin shall be calculated automatically. If a side is calculated automatically, a minimum margin value may be provided with setMinimumMargins. If a side is set to be controlled manually, the value may be specified with setMargins.

Margin sides that are under automatic control may participate in a QCPMarginGroup (see setMarginGroup), to synchronize (align) it with other layout elements in the plot.

See Also
  setMinimumMargins, setMargins

void QCPLayoutElement::setMinimumSize | ( | const QSize & | size | ) |

Sets the minimum size for the inner rect of this layout element. A parent layout tries to respect the size here by changing row/column sizes in the layout accordingly.

If the parent layout size is not sufficient to satisfy all minimum size constraints of its child layout elements, the layout may set a size that is actually smaller than size. QCustomPlot propagates the layout's size constraints to the outside by setting its own minimum QWidget size accordingly, so violations of size should be exceptions.

void QCPLayoutElement::setMinimumSize | ( | int | width,
|  | int | height
| ) |  |

This is an overloaded function.

Sets the minimum size for the inner rect of this layout element.

void QCPLayoutElement::setMaximumSize | ( | const QSize & | size | ) |

Sets the maximum size for the inner rect of this layout element. A parent layout tries to respect the size here by changing row/column sizes in the layout accordingly.

void QCPLayoutElement::setMaximumSize | ( | int | width,
|  | int | height
| ) |  |

This is an overloaded function.

Sets the maximum size for the inner rect of this layout element.

void QCPLayoutElement::setMarginGroup | ( | QCP::MarginSides | sides,
|  | QCPMarginGroup * | group
| ) |  |

Sets the margin group of the specified margin sides.

Margin groups allow synchronizing specified margins across layout elements, see the documentation of QCPMarginGroup.

To unset the margin group of sides, set group to 0.

Note that margin groups only work for margin sides that are set to automatic (setAutoMargins).

void QCPLayoutElement::update | ( | UpdatePhase | phase | ) |
| virtual

Updates the layout element and sub-elements. This function is automatically called before every replot by the parent layout element. It is called multiple times, once for every UpdatePhase. The phases are run through in the order of the enum values. For details about what happens at the different phases, see the documentation of UpdatePhase.

Layout elements that have child elements should call the update method of their child elements, and pass the current phase unchanged.

The default implementation executes the automatic margin mechanism in the upMargins phase. Subclasses should make sure to call the base class implementation.

Reimplemented in QCPLayout, QCPColorScale, and QCPAxisRect.

QSize QCPLayoutElement::minimumSizeHint | ( |  | ) | const
| virtual

Returns the minimum size this layout element (the inner rect) may be compressed to.

if a minimum size (setMinimumSize) was not set manually, parent layouts consult this function to determine the minimum allowed size of this layout element. (A manual minimum size is considered set if it is non-zero.)

Reimplemented in QCPLayoutGrid, QCPPlottableLegendItem, and QCPPlotTitle.

QSize QCPLayoutElement::maximumSizeHint | ( |  | ) | const
| virtual

Returns the maximum size this layout element (the inner rect) may be expanded to.

if a maximum size (setMaximumSize) was not set manually, parent layouts consult this function to determine the maximum allowed size of this layout element. (A manual maximum size is considered set if it is smaller than Qt's QWIDGETSIZE_MAX.)

Reimplemented in QCPLayoutGrid, and QCPPlotTitle.

QList< QCPLayoutElement * > QCPLayoutElement::elements | ( | bool | recursive | ) | const
| virtual

Returns a list of all child elements in this layout element. If recursive is true, all sub-child elements are included in the list, too.

Warning
  There may be entries with value 0 in the returned list. (For example, QCPLayoutGrid may have empty cells which yield 0 at the respective index.)

Reimplemented in QCPLayoutGrid, QCPLayout, and QCPAxisRect.

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

Layout elements are sensitive to events inside their outer rect. If pos is within the outer rect, this method returns a value corresponding to 0.99 times the parent plot's selection tolerance. However, layout elements are not selectable by default. So if onlySelectable is true, -1.0 is returned.

See QCPLayerable::selectTest for a general explanation of this virtual method.

QCPLayoutElement subclasses may reimplement this method to provide more specific selection test behaviour.

Reimplemented from QCPLayerable.

Reimplemented in QCPLayoutInset, QCPLegend, QCPAbstractLegendItem, and QCPPlotTitle.

int QCPLayoutElement::calculateAutoMargin | ( | QCP::MarginSide | side | ) |
| protected virtual

Returns the margin size for this side. It is used if automatic margins is enabled for this side (see setAutoMargins). If a minimum margin was set with setMinimumMargins, the returned value will not be smaller than the specified minimum margin.

The default implementation just returns the respective manual margin (setMargins) or the minimum margin, whichever is larger.

Reimplemented in QCPAxisRect.

void QCPLayoutElement::mousePressEvent | ( | QMouseEvent * | event | ) |
| inline protected virtual

This event is called, if the mouse was pressed while being inside the outer rect of this layout element.

Reimplemented in QCPAxisRect, and QCPColorScale.

void QCPLayoutElement::mouseMoveEvent | ( | QMouseEvent * | event | ) |
| inline protected virtual

This event is called, if the mouse is moved inside the outer rect of this layout element.

Reimplemented in QCPAxisRect, and QCPColorScale.

void QCPLayoutElement::mouseReleaseEvent | ( | QMouseEvent * | event | ) |
| inline protected virtual

This event is called, if the mouse was previously pressed inside the outer rect of this layout element and is now released.

Reimplemented in QCPAxisRect, and QCPColorScale.

void QCPLayoutElement::mouseDoubleClickEvent | ( | QMouseEvent * | event | ) |
| inline protected virtual

This event is called, if the mouse is double-clicked inside the outer rect of this layout element.

void QCPLayoutElement::wheelEvent | ( | QWheelEvent * | event | ) |
| inline protected virtual

This event is called, if the mouse wheel is scrolled while the cursor is inside the rect of this layout element.

Reimplemented in QCPAxisRect, and QCPColorScale.

virtual void QCPLayoutElement::applyDefaultAntialiasingHint | ( | QCPPainter * | painter | ) | const
| inline protected virtual

This function applies the default antialiasing setting to the specified painter, using the function applyAntialiasingHint. It is the antialiasing state the painter is put 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.

Implements QCPLayerable.

Reimplemented in QCPLegend, QCPAxisRect, QCPColorScale, QCPAbstractLegendItem, and QCPPlotTitle.

virtual void QCPLayoutElement::draw | ( | QCPPainter * | painter | ) |
| inline protected virtual

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 QCPLayerable.

Reimplemented in QCPLegend, QCPAxisRect, QCPPlottableLegendItem, QCPAbstractLegendItem, and QCPPlotTitle.

void QCPLayoutElement::parentPlotInitialized | ( | QCustomPlot * | parentPlot | ) |
| protected virtual

propagates the parent plot initialization to all child elements, by calling QCPLayerable::initializeParentPlot on them.

Reimplemented from QCPLayerable.

Reimplemented in QCPLegend.

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

- src/layout.h
- src/layout.cpp

Generated with Doxygen 1.8.1.2