iCub-main
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
QCPMarginGroup Class Reference

A margin group allows synchronization of margin sides if working with multiple layout elements. More...

#include <qcustomplot.h>

+ Inheritance diagram for QCPMarginGroup:

Public Member Functions

 QCPMarginGroup (QCustomPlot *parentPlot)
 Creates a new QCPMarginGroup instance in parentPlot. More...
 
 ~QCPMarginGroup ()
 
QList< QCPLayoutElement * > elements (QCP::MarginSide side) const
 Returns a list of all layout elements that have their margin side associated with this margin group. More...
 
bool isEmpty () const
 Returns whether this margin group is empty. More...
 
void clear ()
 Clears this margin group. More...
 

Protected Member Functions

int commonMargin (QCP::MarginSide side) const
 
void addChild (QCP::MarginSide side, QCPLayoutElement *element)
 
void removeChild (QCP::MarginSide side, QCPLayoutElement *element)
 

Protected Attributes

QCustomPlotmParentPlot
 
QHash< QCP::MarginSide, QList< QCPLayoutElement * > > mChildren
 

Friends

class QCPLayoutElement
 

Detailed Description

A margin group allows synchronization of margin sides if working with multiple layout elements.

QCPMarginGroup allows you to tie a margin side of two or more layout elements together, such that they will all have the same size, based on the largest required margin in the group.


Demonstration of QCPMarginGroup


In certain situations it is desirable that margins at specific sides are synchronized across layout elements. For example, if one QCPAxisRect is below another one in a grid layout, it will provide a cleaner look to the user if the left and right margins of the two axis rects are of the same size. The left axis of the top axis rect will then be at the same horizontal position as the left axis of the lower axis rect, making them appear aligned. The same applies for the right axes. This is what QCPMarginGroup makes possible.

To add/remove a specific side of a layout element to/from a margin group, use the QCPLayoutElement::setMarginGroup method. To completely break apart the margin group, either call clear, or just delete the margin group.

Example

First create a margin group:

QCPMarginGroup *group = new QCPMarginGroup(customPlot);
A margin group allows synchronization of margin sides if working with multiple layout elements.
Definition: qcustomplot.h:600
QCPMarginGroup(QCustomPlot *parentPlot)
Creates a new QCPMarginGroup instance in parentPlot.

Then set this group on the layout element sides:

customPlot->axisRect(0)->setMarginGroup(QCP::msLeft|QCP::msRight, group);
customPlot->axisRect(1)->setMarginGroup(QCP::msLeft|QCP::msRight, group);
@ msRight
0x02 right margin
Definition: qcustomplot.h:100
@ msLeft
0x01 left margin
Definition: qcustomplot.h:99

Here, we've used the first two axis rects of the plot and synchronized their left margins with each other and their right margins with each other.

Definition at line 599 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPMarginGroup()

QCPMarginGroup::QCPMarginGroup ( QCustomPlot parentPlot)

Creates a new QCPMarginGroup instance in parentPlot.

Definition at line 1675 of file qcustomplot.cpp.

◆ ~QCPMarginGroup()

QCPMarginGroup::~QCPMarginGroup ( )

Definition at line 1685 of file qcustomplot.cpp.

Member Function Documentation

◆ addChild()

void QCPMarginGroup::addChild ( QCP::MarginSide  side,
QCPLayoutElement element 
)
protected

Definition at line 1755 of file qcustomplot.cpp.

◆ clear()

void QCPMarginGroup::clear ( )

Clears this margin group.

The synchronization of the margin sides that use this margin group is lifted and they will use their individual margin sizes again.

Definition at line 1710 of file qcustomplot.cpp.

◆ commonMargin()

int QCPMarginGroup::commonMargin ( QCP::MarginSide  side) const
protected

Definition at line 1733 of file qcustomplot.cpp.

◆ elements()

QList< QCPLayoutElement * > QCPMarginGroup::elements ( QCP::MarginSide  side) const
inline

Returns a list of all layout elements that have their margin side associated with this margin group.

Definition at line 607 of file qcustomplot.h.

◆ isEmpty()

bool QCPMarginGroup::isEmpty ( ) const

Returns whether this margin group is empty.

If this function returns true, no layout elements use this margin group to synchronize margin sides.

Definition at line 1694 of file qcustomplot.cpp.

◆ removeChild()

void QCPMarginGroup::removeChild ( QCP::MarginSide  side,
QCPLayoutElement element 
)
protected

Definition at line 1769 of file qcustomplot.cpp.

Friends And Related Function Documentation

◆ QCPLayoutElement

friend class QCPLayoutElement
friend

Definition at line 624 of file qcustomplot.h.

Member Data Documentation

◆ mChildren

QHash<QCP::MarginSide, QList<QCPLayoutElement*> > QCPMarginGroup::mChildren
protected

Definition at line 614 of file qcustomplot.h.

◆ mParentPlot

QCustomPlot* QCPMarginGroup::mParentPlot
protected

Definition at line 613 of file qcustomplot.h.


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