Qt 4.8
|
The QGraphicsLayout class provides the base class for all layouts in Graphics View. More...
#include <qgraphicslayout.h>
Public Functions | |
void | activate () |
Activates the layout, causing all items in the layout to be immediately rearranged. More... | |
virtual int | count () const =0 |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return the number of items in the layout. More... | |
void | getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const |
Reimplemented Function More... | |
virtual void | invalidate () |
Clears any cached geometry and size hint information in the layout, and posts a LayoutRequest event to the managed parent QGraphicsLayoutItem. More... | |
bool | isActivated () const |
Returns true if the layout is currently being activated; otherwise, returns false. More... | |
virtual QGraphicsLayoutItem * | itemAt (int i) const =0 |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return a pointer to the item at index i. More... | |
QGraphicsLayout (QGraphicsLayoutItem *parent=0) | |
Contructs a QGraphicsLayout object. More... | |
virtual void | removeAt (int index)=0 |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to remove the item at index. More... | |
void | setContentsMargins (qreal left, qreal top, qreal right, qreal bottom) |
Sets the contents margins to left, top, right and bottom. More... | |
virtual void | updateGeometry () |
Reimplemented Function More... | |
virtual void | widgetEvent (QEvent *e) |
This virtual event handler receives all events for the managed widget. More... | |
~QGraphicsLayout () | |
Destroys the QGraphicsLayout object. More... | |
Public Functions inherited from QGraphicsLayoutItem | |
QRectF | contentsRect () const |
Returns the contents rect in local coordinates. More... | |
QSizeF | effectiveSizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const |
Returns the effective size hint for this QGraphicsLayoutItem. More... | |
QRectF | geometry () const |
Returns the item's geometry (e. More... | |
QGraphicsItem * | graphicsItem () const |
Returns the QGraphicsItem that this layout item represents. More... | |
bool | isLayout () const |
Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges other QGraphicsLayoutItem objects); otherwise returns false. More... | |
qreal | maximumHeight () const |
Returns the maximum height. More... | |
QSizeF | maximumSize () const |
Returns the maximum size. More... | |
qreal | maximumWidth () const |
Returns the maximum width. More... | |
qreal | minimumHeight () const |
Returns the minimum height. More... | |
QSizeF | minimumSize () const |
Returns the minimum size. More... | |
qreal | minimumWidth () const |
Returns the minimum width. More... | |
bool | ownedByLayout () const |
Returns whether a layout should delete this item in its destructor. More... | |
QGraphicsLayoutItem * | parentLayoutItem () const |
Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not inherit from QGraphicsLayoutItem (QGraphicsLayoutItem is often used through multiple inheritance with QObject-derived classes). More... | |
qreal | preferredHeight () const |
Returns the preferred height. More... | |
QSizeF | preferredSize () const |
Returns the preferred size. More... | |
qreal | preferredWidth () const |
Returns the preferred width. More... | |
QGraphicsLayoutItem (QGraphicsLayoutItem *parent=0, bool isLayout=false) | |
Constructs the QGraphicsLayoutItem object. More... | |
virtual void | setGeometry (const QRectF &rect) |
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordinates (e. More... | |
void | setMaximumHeight (qreal height) |
Sets the maximum height to height. More... | |
void | setMaximumSize (const QSizeF &size) |
Sets the maximum size to size. More... | |
void | setMaximumSize (qreal w, qreal h) |
This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)). More... | |
void | setMaximumWidth (qreal width) |
Sets the maximum width to width. More... | |
void | setMinimumHeight (qreal height) |
Sets the minimum height to height. More... | |
void | setMinimumSize (const QSizeF &size) |
Sets the minimum size to size. More... | |
void | setMinimumSize (qreal w, qreal h) |
This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)). More... | |
void | setMinimumWidth (qreal width) |
Sets the minimum width to width. More... | |
void | setParentLayoutItem (QGraphicsLayoutItem *parent) |
Sets the parent of this QGraphicsLayoutItem to parent. More... | |
void | setPreferredHeight (qreal height) |
Sets the preferred height to height. More... | |
void | setPreferredSize (const QSizeF &size) |
Sets the preferred size to size. More... | |
void | setPreferredSize (qreal w, qreal h) |
This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)). More... | |
void | setPreferredWidth (qreal width) |
Sets the preferred width to width. More... | |
void | setSizePolicy (const QSizePolicy &policy) |
Sets the size policy to policy. More... | |
void | setSizePolicy (QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType=QSizePolicy::DefaultType) |
This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)). More... | |
QSizePolicy | sizePolicy () const |
Returns the current size policy. More... | |
virtual | ~QGraphicsLayoutItem () |
Destroys the QGraphicsLayoutItem object. More... | |
Static Public Functions | |
static bool | instantInvalidatePropagation () |
static void | setInstantInvalidatePropagation (bool enable) |
Protected Functions | |
void | addChildLayoutItem (QGraphicsLayoutItem *layoutItem) |
This function is a convenience function provided for custom layouts, and will go through all items in the layout and reparent their graphics items to the closest QGraphicsWidget ancestor of the layout. More... | |
QGraphicsLayout (QGraphicsLayoutPrivate &, QGraphicsLayoutItem *) | |
Protected Functions inherited from QGraphicsLayoutItem | |
QGraphicsLayoutItem (QGraphicsLayoutItemPrivate &dd) | |
void | setGraphicsItem (QGraphicsItem *item) |
If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of QGraphicsLayout it should set this value. More... | |
void | setOwnedByLayout (bool ownedByLayout) |
Sets whether a layout should delete this item in its destructor or not. More... | |
virtual QSizeF | sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const =0 |
This pure virtual function returns the size hint for which of the QGraphicsLayoutItem, using the width or height of constraint to constrain the output. More... | |
Friends | |
class | QGraphicsWidget |
Additional Inherited Members | |
Protected Variables inherited from QGraphicsLayoutItem | |
QScopedPointer< QGraphicsLayoutItemPrivate > | d_ptr |
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
QGraphicsLayout is an abstract class that defines a virtual API for arranging QGraphicsWidget children and other QGraphicsLayoutItem objects for a QGraphicsWidget. QGraphicsWidget assigns responsibility to a QGraphicsLayout through QGraphicsWidget::setLayout(). As the widget is resized, the layout will automatically arrange the widget's children. QGraphicsLayout inherits QGraphicsLayoutItem, so, it can be managed by any layout, including its own subclasses.
You can use QGraphicsLayout as a base to write your own custom layout (e.g., a flowlayout), but it is more common to use one of its subclasses instead - QGraphicsLinearLayout or QGraphicsGridLayout. When creating a custom layout, the following functions must be reimplemented as a bare minimum:
Function | Description |
QGraphicsLayoutItem::setGeometry() | Notifies you when the geometry of the layout is set. You can store the geometry in your own layout class in a reimplementation of this function. |
QGraphicsLayoutItem::sizeHint() | Returns the layout's size hints. |
QGraphicsLayout::count() | Returns the number of items in your layout. |
QGraphicsLayout::itemAt() | Returns a pointer to an item in your layout. |
QGraphicsLayout::removeAt() | Removes an item from your layout without destroying it. |
For more details on how to implement each function, refer to the individual function documentation.
Each layout defines its own API for arranging widgets and layout items. For example, with a grid layout, you require a row and a column index with optional row and column spans, alignment, spacing, and more. A linear layout, however, requires a single row or column index to position its items. For a grid layout, the order of insertion does not affect the layout in any way, but for a linear layout, the order is essential. When writing your own layout subclass, you are free to choose the API that best suits your layout.
For adding layout items to the custom layout, the QGraphicsLayout provides convenience function addChildLayoutItem(). The function will take care of automatically reparenting graphics items, if needed.
When the layout's geometry changes, QGraphicsLayout immediately rearranges all of its managed items by calling setGeometry() on each item. This rearrangement is called activating the layout.
QGraphicsLayout updates its own geometry to match the contentsRect() of the QGraphicsLayoutItem it is managing. Thus, it will automatically rearrange all its items when the widget is resized. QGraphicsLayout caches the sizes of all its managed items to avoid calling setGeometry() too often.
The layout can be activated implicitly using one of two ways: by calling activate() or by calling invalidate(). Calling activate() activates the layout immediately. In contrast, calling invalidate() is delayed, as it posts a LayoutRequest event to the managed widget. Due to event compression, the activate() will only be called once after control has returned to the event loop. This is referred to as invalidating the layout. Invalidating the layout also invalidates any cached information. Also, the invalidate() function is a virtual function. So, you can invalidate your own cache in a subclass of QGraphicsLayout by reimplementing this function.
QGraphicsLayout listens to events for the widget it manages through the virtual widgetEvent() event handler. When the layout is assigned to a widget, all events delivered to the widget are first processed by widgetEvent(). This allows the layout to be aware of any relevant state changes on the widget such as visibility changes or layout direction changes.
The margins of a QGraphicsLayout can be modified by reimplementing setContentsMargins() and getContentsMargins().
Definition at line 59 of file qgraphicslayout.h.
QGraphicsLayout::QGraphicsLayout | ( | QGraphicsLayoutItem * | parent = 0 | ) |
Contructs a QGraphicsLayout object.
parent is passed to QGraphicsLayoutItem's constructor and the QGraphicsLayoutItem's isLayout argument is set to true.
If parent is a QGraphicsWidget the layout will be installed on that widget. (Note that installing a layout will delete the old one installed.)
Definition at line 163 of file qgraphicslayout.cpp.
QGraphicsLayout::~QGraphicsLayout | ( | ) |
Destroys the QGraphicsLayout object.
Definition at line 205 of file qgraphicslayout.cpp.
|
protected |
Definition at line 184 of file qgraphicslayout.cpp.
void QGraphicsLayout::activate | ( | ) |
Activates the layout, causing all items in the layout to be immediately rearranged.
This function is based on calling count() and itemAt(), and then calling setGeometry() on all items sequentially. When activated, the layout will adjust its geometry to its parent's contentsRect(). The parent will then invalidate any layout of its own.
If called in sequence or recursively, e.g., by one of the arranged items in response to being resized, this function will do nothing.
Note that the layout is free to use geometry caching to optimize this process. To forcefully invalidate any such cache, you can call invalidate() before calling activate().
Definition at line 262 of file qgraphicslayout.cpp.
Referenced by widgetEvent().
|
protected |
This function is a convenience function provided for custom layouts, and will go through all items in the layout and reparent their graphics items to the closest QGraphicsWidget ancestor of the layout.
If layoutItem is already in a different layout, it will be removed from that layout.
If custom layouts want special behaviour they can ignore to use this function, and implement their own behaviour.
Definition at line 476 of file qgraphicslayout.cpp.
|
pure virtual |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return the number of items in the layout.
The subclass is free to decide how to store the items.
Implemented in QGraphicsGridLayout, QGraphicsAnchorLayout, and QGraphicsLinearLayout.
Referenced by QGraphicsLayoutPrivate::activateRecursive(), QGraphicsLinearLayout::addStretch(), QGraphicsLayoutItemPrivate::hasHeightForWidth(), QGraphicsLayoutItemPrivate::hasWidthForHeight(), removeLayoutItemFromLayout(), and QGraphicsLayoutItem::~QGraphicsLayoutItem().
|
virtual |
Reimplemented Function
Reimplemented from QGraphicsLayoutItem.
Definition at line 237 of file qgraphicslayout.cpp.
Referenced by QGraphicsLinearLayout::setGeometry(), QGraphicsGridLayout::setGeometry(), QGraphicsLinearLayout::sizeHint(), QGraphicsAnchorLayout::sizeHint(), and QGraphicsGridLayout::sizeHint().
|
static |
returns true if the complete widget/layout hierarchy is rearranged in one go.
Definition at line 519 of file qgraphicslayout.cpp.
Referenced by activate(), QGraphicsLayoutPrivate::activateRecursive(), invalidate(), QGraphicsWidget::setGeometry(), updateGeometry(), and QGraphicsWidget::updateGeometry().
|
virtual |
Clears any cached geometry and size hint information in the layout, and posts a LayoutRequest event to the managed parent QGraphicsLayoutItem.
Reimplemented in QGraphicsGridLayout, QGraphicsAnchorLayout, and QGraphicsLinearLayout.
Definition at line 306 of file qgraphicslayout.cpp.
Referenced by QGraphicsLayoutPrivate::activateRecursive(), QGraphicsLinearLayout::addStretch(), QGraphicsLinearLayout::invalidate(), QGraphicsAnchorLayout::invalidate(), QGraphicsGridLayout::invalidate(), setContentsMargins(), QGraphicsWidget::setLayout(), updateGeometry(), and widgetEvent().
bool QGraphicsLayout::isActivated | ( | ) | const |
Returns true if the layout is currently being activated; otherwise, returns false.
If the layout is being activated, this means that it is currently in the process of rearranging its items (i.e., the activate() function has been called, and has not yet returned).
Definition at line 293 of file qgraphicslayout.cpp.
Referenced by widgetEvent().
|
pure virtual |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to return a pointer to the item at index i.
The reimplementation can assume that i is valid (i.e., it respects the value of count()). Together with count(), it is provided as a means of iterating over all items in a layout.
The subclass is free to decide how to store the items, and the visual arrangement does not have to be reflected through this function.
Implemented in QGraphicsGridLayout, QGraphicsAnchorLayout, and QGraphicsLinearLayout.
Referenced by QGraphicsLayoutPrivate::activateRecursive(), QGraphicsLinearLayout::addStretch(), QGraphicsLayoutItemPrivate::hasHeightForWidth(), QGraphicsLayoutItemPrivate::hasWidthForHeight(), removeLayoutItemFromLayout(), and QGraphicsLayoutItem::~QGraphicsLayoutItem().
|
pure virtual |
This pure virtual function must be reimplemented in a subclass of QGraphicsLayout to remove the item at index.
The reimplementation can assume that index is valid (i.e., it respects the value of count()).
The implementation must ensure that the parentLayoutItem() of the removed item does not point to this layout, since the item is considered to be removed from the layout hierarchy.
If the layout is to be reused between applications, we recommend that the layout deletes the item, but the graphics view framework does not depend on this.
The subclass is free to decide how to store the items.
Implemented in QGraphicsGridLayout, QGraphicsAnchorLayout, and QGraphicsLinearLayout.
Referenced by QGraphicsLinearLayout::addStretch(), removeLayoutItemFromLayout(), and QGraphicsLayoutItem::~QGraphicsLayoutItem().
Sets the contents margins to left, top, right and bottom.
The default contents margins for toplevel layouts are style dependent (by querying the pixelMetric for QStyle::PM_LayoutLeftMargin, QStyle::PM_LayoutTopMargin, QStyle::PM_LayoutRightMargin and QStyle::PM_LayoutBottomMargin).
For sublayouts the default margins are 0.
Changing the contents margins automatically invalidates the layout.
Definition at line 222 of file qgraphicslayout.cpp.
|
static |
Calling this function with enable set to true will enable a feature that makes propagation of invalidation up to ancestor layout items to be done in one go. It will propagate up the parentLayoutItem() hierarchy until it has reached the root. If the root item is a QGraphicsWidget, it will post a layout request to it. When the layout request is consumed it will traverse down the hierarchy of layouts and widgets and activate all layouts that is invalid (not activated). This is the recommended behaviour.
If not set it will also propagate up the parentLayoutItem() hierarchy, but it will stop at the first widget it encounters, and post a layout request to the widget. When the layout request is consumed, this might cause it to continue propagation up to the parentLayoutItem() of the widget. It will continue in this fashion until it has reached a widget with no parentLayoutItem(). This strategy might cause drawing artifacts, since it is not done in one go, and the consumption of layout requests might be interleaved by consumption of paint events, which might cause significant flicker. Note, this is not the recommended behavior, but for compatibility reasons this is the default behaviour.
Definition at line 508 of file qgraphicslayout.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QGraphicsLayoutItem.
Definition at line 345 of file qgraphicslayout.cpp.
Referenced by invalidate().
|
virtual |
This virtual event handler receives all events for the managed widget.
QGraphicsLayout uses this event handler to listen for layout related events such as geometry changes, layout changes or layout direction changes.
e is a pointer to the event.
You can reimplement this event handler to track similar events for your own custom layout.
Definition at line 385 of file qgraphicslayout.cpp.
|
friend |
Definition at line 88 of file qgraphicslayout.h.