QgsLayoutItemGroup class
A container for grouping several QgsLayoutItems.
Contents
Base classes
- class QgsLayoutItem
- Base class for graphical items within a QgsLayout.
Public static functions
- static auto create(QgsLayout* layout) -> QgsLayoutItemGroup*
- Returns a new group item for the specified layout.
Constructors, destructors, conversion operators
- QgsLayoutItemGroup(QgsLayout* layout) explicit
- Constructor for QgsLayoutItemGroup, belonging to the specified layout.
Public functions
- void addItem(QgsLayoutItem* item)
- Adds an item to the group.
- void attemptMove(const QgsLayoutPoint& point, bool useReferencePoint = true, bool includesFrame = false, int page = -1) override
- Attempts to move the item to a specified point.
- void attemptResize(const QgsLayoutSize& size, bool includesFrame = false) override
- Attempts to resize the item to a specified target size.
- void cleanup() override
- Called just before a batch of items are deleted, allowing them to run cleanup tasks.
- auto displayName() const -> QString override
- Gets item display name.
- void finalizeRestoreFromXml() override
- Called after all pending items have been restored from XML.
- auto items() const -> QList<QgsLayoutItem*>
- Returns a list of items contained by the group.
- void removeItems()
- Removes all items from the group (but does not delete them).
- void setVisibility(bool visible) override
- Sets whether the item is visible.
Protected functions
- void draw(QgsLayoutItemRenderContext& context) override
- Draws the item's contents using the specified item render context.
- auto readPropertiesFromElement(const QDomElement& element, const QDomDocument& document, const QgsReadWriteContext& context) -> bool override
- Sets item state from a DOM element.
- auto writePropertiesToElement(QDomElement& element, QDomDocument& document, const QgsReadWriteContext& context) const -> bool override
- Stores item state within an XML DOM element.
Function documentation
static QgsLayoutItemGroup* QgsLayoutItemGroup:: create(QgsLayout* layout)
Returns a new group item for the specified layout.
The caller takes responsibility for deleting the returned object.
void QgsLayoutItemGroup:: addItem(QgsLayoutItem* item)
Adds an item to the group.
Ownership of the item is transferred to the group.
void QgsLayoutItemGroup:: attemptMove(const QgsLayoutPoint& point,
bool useReferencePoint = true,
bool includesFrame = false,
int page = -1) override
Attempts to move the item to a specified point.
If useReferencePoint is true, this method will respect the item's reference point, in that the item will be moved so that its current reference point is placed at the specified target point.
If useReferencePoint is false, the item will be moved so that point falls at the top-left corner of the item.
If includesFrame is true, then the position specified by point represents the point at which to place the outside of the item's frame.
If page is not left at the default -1 value, then the position specified by point refers to the relative position on the corresponding layout page (where a page of 0 represents the first page).
Note that the final position of the item may not match the specified target position, as data defined item position may override the specified value.
void QgsLayoutItemGroup:: attemptResize(const QgsLayoutSize& size,
bool includesFrame = false) override
Attempts to resize the item to a specified target size.
Note that the final size of the item may not match the specified target size, as items with a fixed or minimum size will place restrictions on the allowed item size. Data defined item size overrides will also override the specified target size.
If includesFrame is true, then the size specified by size includes the item's frame.
QString QgsLayoutItemGroup:: displayName() const override
Gets item display name.
This is the item's id if set, and if not, a user-friendly string identifying item type.
void QgsLayoutItemGroup:: finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
Items can use this method to run steps which must take place after all items have been restored to the layout, such as connecting to signals emitted by other items, which may not have existed in the layout at the time readXml() was called. E.g. a scalebar can use this to connect to its linked map item after restoration from XML.
void QgsLayoutItemGroup:: removeItems()
Removes all items from the group (but does not delete them).
Items remain in the scene but are no longer grouped together
void QgsLayoutItemGroup:: setVisibility(bool visible) override
Sets whether the item is visible.
void QgsLayoutItemGroup:: draw(QgsLayoutItemRenderContext& context) override protected
Draws the item's contents using the specified item render context.
Note that the context's painter has been scaled so that painter units are pixels. Use the QgsRenderContext methods to convert from millimeters or other units to the painter's units.
bool QgsLayoutItemGroup:: readPropertiesFromElement(const QDomElement& element,
const QDomDocument& document,
const QgsReadWriteContext& context) override protected
Sets item state from a DOM element.
| Parameters | |
|---|---|
| element | is the DOM element for the item |
| document | DOM document |
| context | read write context |
Note that item subclasses should not rely on all other items being present in the layout at the time this method is called. Instead, any connections and links to other items must be made in the finalizeRestoreFromXml() method. E.g. when restoring a scalebar, the connection to the linked map's signals should be implemented in finalizeRestoreFromXml(), not readPropertiesFromElement().
bool QgsLayoutItemGroup:: writePropertiesToElement(QDomElement& element,
QDomDocument& document,
const QgsReadWriteContext& context) const override protected
Stores item state within an XML DOM element.
| Parameters | |
|---|---|
| element | is the DOM element to store the item's properties in |
| document | DOM document |
| context | read write context |