Main Page · Class Overview · Hierarchy · All Classes · Special Pages
Public Functions | Protected Functions
QCPLayout Class Referenceabstract

The abstract base class for layouts. More...

Inheritance diagram for QCPLayout:
Inheritance graph

Public Functions

 QCPLayout ()
 
virtual void update (UpdatePhase phase)
 
virtual QList< QCPLayoutElement * > elements (bool recursive) const
 
virtual int elementCount () const =0
 
virtual QCPLayoutElementelementAt (int index) const =0
 
virtual QCPLayoutElementtakeAt (int index)=0
 
virtual bool take (QCPLayoutElement *element)=0
 
virtual void simplify ()
 
bool removeAt (int index)
 
bool remove (QCPLayoutElement *element)
 
void clear ()
 
- Public Functions inherited from QCPLayoutElement
 QCPLayoutElement (QCustomPlot *parentPlot=0)
 
QCPLayoutlayout () const
 
QRect rect () const
 
QRect outerRect () const
 
QMargins margins () const
 
QMargins minimumMargins () const
 
QCP::MarginSides autoMargins () const
 
QSize minimumSize () const
 
QSize maximumSize () const
 
QCPMarginGroupmarginGroup (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 QSize minimumSizeHint () const
 
virtual QSize maximumSizeHint () const
 
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=0) const
 
- Public Functions inherited from QCPLayerable
 QCPLayerable (QCustomPlot *plot, QString targetLayer=QString(), 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 updateLayout ()
 
void sizeConstraintsChanged () const
 
void adoptElement (QCPLayoutElement *el)
 
void releaseElement (QCPLayoutElement *el)
 
QVector< int > getSectionSizes (QVector< int > maxSizes, QVector< int > minSizes, QVector< double > stretchFactors, int totalSize) const
 
- Protected Functions inherited from QCPLayoutElement
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

- Public Types inherited from QCPLayoutElement
enum  UpdatePhase
 
- Signals inherited from QCPLayerable
void layerChanged (QCPLayer *newLayer)
 

Detailed Description

The abstract base class for layouts.

This is an abstract base class for layout elements whose main purpose is to define the position and size of other child layout elements. In most cases, layouts don't draw anything themselves (but there are exceptions to this, e.g. QCPLegend).

QCPLayout derives from QCPLayoutElement, and thus can itself be nested in other layouts.

QCPLayout introduces a common interface for accessing and manipulating the child elements. Those functions are most notably elementCount, elementAt, takeAt, take, simplify, removeAt, remove and clear. Individual subclasses may add more functions to this interface which are more specialized to the form of the layout. For example, QCPLayoutGrid adds functions that take row and column indices to access cells of the layout grid more conveniently.

Since this is an abstract base class, you can't instantiate it directly. Rather use one of its subclasses like QCPLayoutGrid or QCPLayoutInset.

For a general introduction to the layout system, see the dedicated documentation page The Layout System.

Constructor & Destructor Documentation

QCPLayout::QCPLayout ( )
explicit

Creates an instance of QCPLayout and sets default values. Note that since QCPLayout is an abstract base class, it can't be instantiated directly.

Member Function Documentation

void QCPLayout::update ( UpdatePhase  phase)
virtual

First calls the QCPLayoutElement::update base class implementation to update the margins on this layout.

Then calls updateLayout which subclasses reimplement to reposition and resize their cells.

Finally, update is called on all child elements.

Reimplemented from QCPLayoutElement.

QList< QCPLayoutElement * > QCPLayout::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 from QCPLayoutElement.

Reimplemented in QCPLayoutGrid.

int QCPLayout::elementCount ( ) const
pure virtual

Returns the number of elements/cells in the layout.

See Also
elements, elementAt

Implemented in QCPLayoutInset, and QCPLayoutGrid.

QCPLayoutElement * QCPLayout::elementAt ( int  index) const
pure virtual

Returns the element in the cell with the given index. If index is invalid, returns 0.

Note that even if index is valid, the respective cell may be empty in some layouts (e.g. QCPLayoutGrid), so this function may return 0 in those cases. You may use this function to check whether a cell is empty or not.

See Also
elements, elementCount, takeAt

Implemented in QCPLayoutInset, and QCPLayoutGrid.

QCPLayoutElement * QCPLayout::takeAt ( int  index)
pure virtual

Removes the element with the given index from the layout and returns it.

If the index is invalid or the cell with that index is empty, returns 0.

Note that some layouts don't remove the respective cell right away but leave an empty cell after successful removal of the layout element. To collapse empty cells, use simplify.

See Also
elementAt, take

Implemented in QCPLayoutInset, and QCPLayoutGrid.

bool QCPLayout::take ( QCPLayoutElement element)
pure virtual

Removes the specified element from the layout and returns true on success.

If the element isn't in this layout, returns false.

Note that some layouts don't remove the respective cell right away but leave an empty cell after successful removal of the layout element. To collapse empty cells, use simplify.

See Also
takeAt

Implemented in QCPLayoutInset, and QCPLayoutGrid.

void QCPLayout::simplify ( )
virtual

Simplifies the layout by collapsing empty cells. The exact behavior depends on subclasses, the default implementation does nothing.

Not all layouts need simplification. For example, QCPLayoutInset doesn't use explicit simplification while QCPLayoutGrid does.

Reimplemented in QCPLayoutInset, and QCPLayoutGrid.

bool QCPLayout::removeAt ( int  index)

Removes and deletes the element at the provided index. Returns true on success. If index is invalid or points to an empty cell, returns false.

This function internally uses takeAt to remove the element from the layout and then deletes the returned element. Note that some layouts don't remove the respective cell right away but leave an empty cell after successful removal of the layout element. To collapse empty cells, use simplify.

See Also
remove, takeAt
bool QCPLayout::remove ( QCPLayoutElement element)

Removes and deletes the provided element. Returns true on success. If element is not in the layout, returns false.

This function internally uses takeAt to remove the element from the layout and then deletes the element. Note that some layouts don't remove the respective cell right away but leave an empty cell after successful removal of the layout element. To collapse empty cells, use simplify.

See Also
removeAt, take
void QCPLayout::clear ( )

Removes and deletes all layout elements in this layout. Finally calls simplify to make sure all empty cells are collapsed.

See Also
remove, removeAt
void QCPLayout::updateLayout ( )
protectedvirtual

Subclasses reimplement this method to update the position and sizes of the child elements/cells via calling their QCPLayoutElement::setOuterRect. The default implementation does nothing.

The geometry used as a reference is the inner rect of this layout. Child elements should stay within that rect.

getSectionSizes may help with the reimplementation of this function.

See Also
update

Reimplemented in QCPLayoutInset, and QCPLayoutGrid.

void QCPLayout::sizeConstraintsChanged ( ) const
protected

Subclasses call this method to report changed (minimum/maximum) size constraints.

If the parent of this layout is again a QCPLayout, forwards the call to the parent's sizeConstraintsChanged. If the parent is a QWidget (i.e. is the QCustomPlot::plotLayout of QCustomPlot), calls QWidget::updateGeometry, so if the QCustomPlot widget is inside a Qt QLayout, it may update itself and resize cells accordingly.

void QCPLayout::adoptElement ( QCPLayoutElement el)
protected

Associates el with this layout. This is done by setting the QCPLayoutElement::layout, the QCPLayerable::parentLayerable and the QObject parent to this layout.

Further, if el didn't previously have a parent plot, calls QCPLayerable::initializeParentPlot on el to set the paret plot.

This method is used by subclass specific methods that add elements to the layout. Note that this method only changes properties in el. The removal from the old layout and the insertion into the new layout must be done additionally.

void QCPLayout::releaseElement ( QCPLayoutElement el)
protected

Disassociates el from this layout. This is done by setting the QCPLayoutElement::layout and the QCPLayerable::parentLayerable to zero. The QObject parent is set to the parent QCustomPlot.

This method is used by subclass specific methods that remove elements from the layout (e.g. take or takeAt). Note that this method only changes properties in el. The removal from the old layout must be done additionally.

QVector< int > QCPLayout::getSectionSizes ( QVector< int >  maxSizes,
QVector< int >  minSizes,
QVector< double >  stretchFactors,
int  totalSize 
) const
protected

This is a helper function for the implementation of updateLayout in subclasses.

It calculates the sizes of one-dimensional sections with provided constraints on maximum section sizes, minimum section sizes, relative stretch factors and the final total size of all sections.

The QVector entries refer to the sections. Thus all QVectors must have the same size.

maxSizes gives the maximum allowed size of each section. If there shall be no maximum size imposed, set all vector values to Qt's QWIDGETSIZE_MAX.

minSizes gives the minimum allowed size of each section. If there shall be no minimum size imposed, set all vector values to zero. If the minSizes entries add up to a value greater than totalSize, sections will be scaled smaller than the proposed minimum sizes. (In other words, not exceeding the allowed total size is taken to be more important than not going below minimum section sizes.)

stretchFactors give the relative proportions of the sections to each other. If all sections shall be scaled equally, set all values equal. If the first section shall be double the size of each individual other section, set the first number of stretchFactors to double the value of the other individual values (e.g. {2, 1, 1, 1}).

totalSize is the value that the final section sizes will add up to. Due to rounding, the actual sum may differ slightly. If you want the section sizes to sum up to exactly that value, you could distribute the remaining difference on the sections.

The return value is a QVector containing the section sizes.


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