QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgslayoutitemmapitem.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutitemmapitem.h
3 -------------------
4 begin : October 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSLAYOUTITEMMAPITEM_H
18#define QGSLAYOUTITEMMAPITEM_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22#include "qgslayoutobject.h"
23#include "qgsmaplayerref.h"
24
26
32class CORE_EXPORT QgsLayoutItemMapItem : public QgsLayoutObject
33{
34 Q_OBJECT
35
36 public:
37
47
53 QgsLayoutItemMapItem( const QString &name, QgsLayoutItemMap *map );
54
58 virtual void draw( QPainter *painter ) = 0;
59
65 virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
66
72 virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context );
73
82 virtual void finalizeRestoreFromXml();
83
89
94 const QgsLayoutItemMap *map() const;
95
99 QString id() const { return mUuid; }
100
105 void setName( const QString &name );
106
111 QString name() const;
112
117 virtual void setEnabled( bool enabled );
118
123 bool enabled() const;
124
128 virtual bool usesAdvancedEffects() const;
129
140
151
164 QgsMapLayer *stackingLayer() const;
165
178 void setStackingLayer( QgsMapLayer *layer );
179
189 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
190
196 virtual QgsMapLayer *mapLayer();
197
199
200 protected:
201
203 QString mName;
204
207
209 QString mUuid;
210
212 bool mEnabled = true;
213
215
217
218};
219
229{
230 public:
231
237
239
243 int size() const { return mItems.size(); }
244
250 virtual bool writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) const;
251
257 virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context ) = 0;
258
267 virtual void finalizeRestoreFromXml();
268
276 void drawItems( QPainter *painter, bool ignoreStacking = true );
277
282 bool containsAdvancedEffects() const;
283
289 bool hasEnabledItems() const;
290
294 QgsLayoutItemMapItem *item( int index ) const;
295
296 protected:
297
307
314 void removeItem( const QString &itemId );
315
322 void moveItemUp( const QString &itemId );
323
330 void moveItemDown( const QString &itemId );
331
335 QgsLayoutItemMapItem *item( const QString &itemId ) const;
336
343
347 QList< QgsLayoutItemMapItem * > asList() const;
348
349 protected:
350
351 QList< QgsLayoutItemMapItem * > mItems;
352
354
359 void removeItems();
360};
361
362#endif //QGSLAYOUTITEMMAPITEM_H
363
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
virtual bool readXml(const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context)=0
Sets the item stack's state from a DOM document, where element is a DOM node corresponding to a 'Layo...
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.
QgsLayoutItemMapItemStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItemStack, attached to the specified map.
QList< QgsLayoutItemMapItem * > mItems
int size() const
Returns the number of items in the stack.
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...
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.
bool mEnabled
True if item is to be displayed on map.
void setStackingPosition(StackingPosition position)
Sets the item's stacking position, which specifies where the in the map's stack the item should be re...
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
QgsLayoutItemMapItem(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItem, attached to the specified map.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
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.
Layout graphical items for displaying a map.
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.
Base class for all map layer types.
Definition qgsmaplayer.h:80
A container for the context for various read/write operations on objects.
An interface for classes which can visit style entity (e.g.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
_LayerRef< QgsMapLayer > QgsMapLayerRef