25#include "moc_qgslayoutitemmapitem.cpp"
31 ,
mUuid( QUuid::createUuid().toString() )
42 element.setAttribute( QStringLiteral(
"uuid" ),
mUuid );
43 element.setAttribute( QStringLiteral(
"name" ),
mName );
44 element.setAttribute( QStringLiteral(
"show" ),
mEnabled );
45 element.setAttribute( QStringLiteral(
"position" ),
static_cast< int >(
mStackingPosition ) );
49 element.setAttribute( QStringLiteral(
"stackingLayer" ),
mStackingLayer.layerId );
50 element.setAttribute( QStringLiteral(
"stackingLayerName" ),
mStackingLayer.name );
51 element.setAttribute( QStringLiteral(
"stackingLayerSource" ),
mStackingLayer.source );
52 element.setAttribute( QStringLiteral(
"stackingLayerProvider" ),
mStackingLayer.provider );
62 mUuid = itemElem.attribute( QStringLiteral(
"uuid" ) );
63 mName = itemElem.attribute( QStringLiteral(
"name" ) );
64 mEnabled = ( itemElem.attribute( QStringLiteral(
"show" ), QStringLiteral(
"0" ) ) != QLatin1String(
"0" ) );
67 const QString layerId = itemElem.attribute( QStringLiteral(
"stackingLayer" ) );
68 const QString layerName = itemElem.attribute( QStringLiteral(
"stackingLayerName" ) );
69 const QString layerSource = itemElem.attribute( QStringLiteral(
"stackingLayerSource" ) );
70 const QString layerProvider = itemElem.attribute( QStringLiteral(
"stackingLayerProvider" ) );
130 return mMap->createExpressionContext();
167 for (
int i =
mItems.size() - 1; i >= 0; --i )
169 if (
mItems.at( i )->id() == itemId )
171 delete mItems.takeAt( i );
185 int index =
mItems.indexOf( targetItem );
186 if ( index >=
mItems.size() - 1 )
190 mItems.swapItemsAt( index, index + 1 );
201 int index =
mItems.indexOf( targetItem );
206 mItems.swapItemsAt( index, index - 1 );
213 if (
item->id() == itemId )
224 if ( index <
mItems.length() )
226 return mItems.at( index );
239 QList< QgsLayoutItemMapItem * > list;
240 list.reserve(
mItems.size() );
253 item->writeXml( elem, doc, context );
263 item->finalizeRestoreFromXml();
276 switch (
item->stackingPosition() )
282 if ( !ignoreStacking )
287 item->draw( painter );
298 if (
item->enabled() &&
item->usesAdvancedEffects() )
310 if (
item->enabled() )
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.
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.
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.
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.
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.
QgsLayoutObject(QgsLayout *layout)
Constructor for QgsLayoutObject, with the specified parent layout.
bool writeObjectPropertiesToElement(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores object properties within an XML DOM element.
Base class for all map layer types.
A container for the context for various read/write operations on objects.
An interface for classes which can visit style entity (e.g.
_LayerRef< QgsMapLayer > QgsMapLayerRef