QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
33class CORE_EXPORT QgsLayoutItemMapItem : public QgsLayoutObject
34{
35 Q_OBJECT
36
37 public:
38
41 {
47 };
48
54 QgsLayoutItemMapItem( const QString &name, QgsLayoutItemMap *map );
55
59 virtual void draw( QPainter *painter ) = 0;
60
66 virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
67
73 virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context );
74
83 virtual void finalizeRestoreFromXml();
84
89 void setMap( QgsLayoutItemMap *map );
90
95 const QgsLayoutItemMap *map() const;
96
100 QString id() const { return mUuid; }
101
106 void setName( const QString &name );
107
112 QString name() const;
113
118 virtual void setEnabled( bool enabled );
119
124 bool enabled() const;
125
129 virtual bool usesAdvancedEffects() const;
130
140 StackingPosition stackingPosition() const { return mStackingPosition; }
141
151 void setStackingPosition( StackingPosition position ) { mStackingPosition = position; }
152
165 QgsMapLayer *stackingLayer() const;
166
179 void setStackingLayer( QgsMapLayer *layer );
180
190 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
191
197 virtual QgsMapLayer *mapLayer();
198
200
201 protected:
202
204 QString mName;
205
207 QgsLayoutItemMap *mMap = nullptr;
208
210 QString mUuid;
211
214
215 StackingPosition mStackingPosition = StackBelowMapLabels;
216
218
219};
220
231{
232 public:
233
239
241
245 int size() const { return mItems.size(); }
246
252 virtual bool writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) const;
253
259 virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context ) = 0;
260
269 virtual void finalizeRestoreFromXml();
270
278 void drawItems( QPainter *painter, bool ignoreStacking = true );
279
284 bool containsAdvancedEffects() const;
285
291 bool hasEnabledItems() const;
292
296 QgsLayoutItemMapItem *item( int index ) const;
297
298 protected:
299
308 void addItem( QgsLayoutItemMapItem *item SIP_TRANSFER );
309
316 void removeItem( const QString &itemId );
317
324 void moveItemUp( const QString &itemId );
325
332 void moveItemDown( const QString &itemId );
333
337 QgsLayoutItemMapItem *item( const QString &itemId ) const;
338
344 QgsLayoutItemMapItem &operator[]( int index ) SIP_SKIP;
345
349 QList< QgsLayoutItemMapItem * > asList() const;
350
351 protected:
352
353 QList< QgsLayoutItemMapItem * > mItems;
354
355 QgsLayoutItemMap *mMap = nullptr;
356
361 void removeItems();
362};
363
364#endif //QGSLAYOUTITEMMAPITEM_H
365
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
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...
QList< QgsLayoutItemMapItem * > mItems
int size() const
Returns the number of items in the stack.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
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.
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...
virtual void draw(QPainter *painter)=0
Draws the item on to a destination painter.
Layout graphical items for displaying a map.
A base class for objects which belong to a layout.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
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.
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36