QgsLayoutItemMapGridStack class

A collection of grids which is drawn above the map content in a QgsLayoutItemMap.

The grid stack controls which grids are drawn and the order they are drawn in.

Base classes

class QgsLayoutItemMapItemStack
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.

Constructors, destructors, conversion operators

QgsLayoutItemMapGridStack(QgsLayoutItemMap* map)
Constructor for QgsLayoutItemMapGridStack, attached to the specified map.

Public functions

void addGrid(QgsLayoutItemMapGrid* grid)
Adds a new map grid to the stack and takes ownership of the grid.
auto asList() const -> QList<QgsLayoutItemMapGrid*>
Returns a list of QgsLayoutItemMapGrids contained by the stack.
void calculateMaxGridExtension(double& top, double& right, double& bottom, double& left) const
Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect.
auto grid(const QString& gridId) const -> QgsLayoutItemMapGrid*
Returns a reference to a grid with matching gridId within the stack.
auto grid(int index) const -> QgsLayoutItemMapGrid*
Returns a reference to a grid at the specified index within the stack.
auto maxGridExtension() const -> double
Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect.
void moveGridDown(const QString& gridId)
Moves a grid with matching gridId down the stack, causing it to be rendered below other grids.
void moveGridUp(const QString& gridId)
Moves a grid with matching gridId up the stack, causing it to be rendered above other grids.
auto operator[](int index) -> QgsLayoutItemMapGrid&
Returns a reference to a grid at the specified index within the stack.
auto readXml(const QDomElement& element, const QDomDocument& doc, const QgsReadWriteContext& context) -> bool override
Sets the item stack's state from a DOM document, where element is a DOM node corresponding to a 'LayoutMap' tag.
void removeGrid(const QString& gridId)
Removes a grid with matching gridId from the stack and deletes the corresponding QgsLayoutItemMapGrid.

Function documentation

void QgsLayoutItemMapGridStack::addGrid(QgsLayoutItemMapGrid* grid)

Adds a new map grid to the stack and takes ownership of the grid.

The grid will be added to the end of the stack, and rendered above any existing map grids already present in the stack.

void QgsLayoutItemMapGridStack::calculateMaxGridExtension(double& top, double& right, double& bottom, double& left) const

Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect.

This method calculates the distance for each side of the map item separately.

double QgsLayoutItemMapGridStack::maxGridExtension() const

Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect.

void QgsLayoutItemMapGridStack::moveGridDown(const QString& gridId)

Moves a grid with matching gridId down the stack, causing it to be rendered below other grids.

void QgsLayoutItemMapGridStack::moveGridUp(const QString& gridId)

Moves a grid with matching gridId up the stack, causing it to be rendered above other grids.

QgsLayoutItemMapGrid& QgsLayoutItemMapGridStack::operator[](int index)

Returns a reference to a grid at the specified index within the stack.

bool QgsLayoutItemMapGridStack::readXml(const QDomElement& element, const QDomDocument& doc, const QgsReadWriteContext& context) override

Sets the item stack's state from a DOM document, where element is a DOM node corresponding to a 'LayoutMap' tag.

Returns true if read was successful.

void QgsLayoutItemMapGridStack::removeGrid(const QString& gridId)

Removes a grid with matching gridId from the stack and deletes the corresponding QgsLayoutItemMapGrid.