QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
40 {
46 };
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
88 void setMap( QgsLayoutItemMap *map );
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
139 StackingPosition stackingPosition() const { return mStackingPosition; }
140
150 void setStackingPosition( StackingPosition position ) { mStackingPosition = position; }
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
206 QgsLayoutItemMap *mMap = nullptr;
207
209 QString mUuid;
210
213
214 StackingPosition mStackingPosition = StackBelowMapLabels;
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
306 void addItem( QgsLayoutItemMapItem *item SIP_TRANSFER );
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
342 QgsLayoutItemMapItem &operator[]( int index ) SIP_SKIP;
343
347 QList< QgsLayoutItemMapItem * > asList() const;
348
349 protected:
350
351 QList< QgsLayoutItemMapItem * > mItems;
352
353 QgsLayoutItemMap *mMap = nullptr;
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...
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:75
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