27 , mUuid( QUuid::createUuid().toString() )
39 element.setAttribute( QStringLiteral(
"uuid" ),
mUuid );
40 element.setAttribute( QStringLiteral(
"name" ),
mName );
41 element.setAttribute( QStringLiteral(
"show" ),
mEnabled );
42 element.setAttribute( QStringLiteral(
"position" ),
static_cast< int >(
mStackingPosition ) );
59 mUuid = itemElem.attribute( QStringLiteral(
"uuid" ) );
60 mName = itemElem.attribute( QStringLiteral(
"name" ) );
61 mEnabled = ( itemElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
64 const QString layerId = itemElem.attribute( QStringLiteral(
"stackingLayer" ) );
65 const QString layerName = itemElem.attribute( QStringLiteral(
"stackingLayerName" ) );
66 const QString layerSource = itemElem.attribute( QStringLiteral(
"stackingLayerSource" ) );
67 const QString layerProvider = itemElem.attribute( QStringLiteral(
"stackingLayerProvider" ) );
164 for (
int i =
mItems.size() - 1; i >= 0; --i )
166 if (
mItems.at( i )->id() == itemId )
168 delete mItems.takeAt( i );
182 int index =
mItems.indexOf( targetItem );
183 if ( index >=
mItems.size() - 1 )
187 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
188 mItems.swap( index, index + 1 );
190 mItems.swapItemsAt( index, index + 1 );
202 int index =
mItems.indexOf( targetItem );
207 #if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
208 mItems.swap( index, index - 1 );
210 mItems.swapItemsAt( index, index - 1 );
218 if (
item->
id() == itemId )
229 if ( index <
mItems.length() )
231 return mItems.at( index );
244 QList< QgsLayoutItemMapItem * > list;
245 list.reserve(
mItems.size() );
287 if ( !ignoreStacking )
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual bool writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Stores the state of the item stack in a DOM node, where element is the DOM element corresponding to a...
void addItem(QgsLayoutItemMapItem *item)
Adds a new map item to the stack and takes ownership of the item.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
bool containsAdvancedEffects() const
Returns whether any items within the stack contain advanced effects, such as blending modes.
void removeItem(const QString &itemId)
Removes an item which matching itemId from the stack and deletes the corresponding QgsLayoutItemMapIt...
QgsLayoutItemMapItem * item(int index) const
Returns a reference to the item at the specified index within the stack.
QList< QgsLayoutItemMapItem * > asList() const
Returns a list of QgsLayoutItemMapItems contained by the stack.
void drawItems(QPainter *painter, bool ignoreStacking=true)
Draws the items from the stack on a specified painter.
void moveItemUp(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
void removeItems()
Clears the item stack and deletes all QgsLayoutItemMapItems contained by the stack.
virtual ~QgsLayoutItemMapItemStack()
QgsLayoutItemMapItemStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItemStack, attached to the specified map.
QList< QgsLayoutItemMapItem * > mItems
void moveItemDown(const QString &itemId)
Moves an item which matching itemId up the stack, causing it to be rendered above other items.
QgsLayoutItemMapItem & operator[](int index)
Returns a reference to an item at the specified index within the stack.
bool hasEnabledItems() const
Returns true if the stack has any currently enabled items.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
void setMap(QgsLayoutItemMap *map)
Sets the corresponding layout map for the item.
QString id() const
Returns the unique id for the map item.
StackingPosition
Item stacking position, specifies where the in the map's stack the item should be rendered.
@ StackBelowMapLabels
Render above all map layers, but below map labels.
@ StackAboveMapLabels
Render above all map layers and labels.
@ StackBelowMapLayer
Render below a specific map layer (see stackingLayer())
@ StackAboveMapLayer
Render above a specific map layer (see stackingLayer())
@ StackBelowMap
Render below all map layers.
QgsLayoutItemMap * mMap
Associated map.
virtual bool readXml(const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context)
Sets the map item state from a DOM document, where element is the DOM node corresponding to a 'Layout...
void setStackingLayer(QgsMapLayer *layer)
Sets the item's stacking layer, which specifies where the in the map's stack the item should be rende...
StackingPosition mStackingPosition
virtual bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores map item state in a DOM element, where element is the DOM element corresponding to a 'LayoutMa...
QString mName
Friendly display name.
virtual bool usesAdvancedEffects() const
Returns true if the item is drawn using advanced effects, such as blend modes.
QgsMapLayerRef mStackingLayer
bool mEnabled
True if item is to be displayed on map.
virtual void setEnabled(bool enabled)
Controls whether the item will be drawn.
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
QString name() const
Returns the friendly display name for the item.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
void setName(const QString &name)
Sets the friendly display name for the item.
QgsLayoutItemMapItem(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItem, attached to the specified map.
bool enabled() const
Returns whether the item will be drawn.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
const QgsLayoutItemMap * map() const
Returns the layout item map for the item.
virtual void draw(QPainter *painter)=0
Draws the item on to a destination painter.
QgsMapLayer * stackingLayer() const
Returns the item's stacking layer, which specifies where the in the map's stack the item should be re...
virtual QgsMapLayer * mapLayer()
Returns the internal map layer used by this item, if available.
Layout graphical items for displaying a map.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
A base class for objects which belong to a layout.
bool readObjectPropertiesFromElement(const QDomElement &parentElement, const QDomDocument &document, const QgsReadWriteContext &context)
Sets object properties from a DOM element.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
QgsProject * project() const
The project associated with the layout.
Base class for all map layer types.
The class is used as a container of context for various read/write operations on other objects.
An interface for classes which can visit style entity (e.g.
_LayerRef< QgsMapLayer > QgsMapLayerRef
QString source
Weak reference to layer public source.
QString name
Weak reference to layer name.
TYPE * get() const
Returns a pointer to the layer, or nullptr if the reference has not yet been matched to a layer.
QString provider
Weak reference to layer provider.
TYPE * resolveWeakly(const QgsProject *project, MatchType matchType=MatchType::All)
Resolves the map layer by attempting to find a matching layer in a project using a weak match.
void setLayer(TYPE *l)
Sets the reference to point to a specified layer.
QString layerId
Original layer ID.