QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
25 class QgsLayoutItemMap;
26 
33 class 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 
193 
194  protected:
195 
197  QString mName;
198 
200  QgsLayoutItemMap *mMap = nullptr;
201 
203  QString mUuid;
204 
206  bool mEnabled;
207 
208  StackingPosition mStackingPosition = StackBelowMapLabels;
209 
211 
212 };
213 
223 class CORE_EXPORT QgsLayoutItemMapItemStack
224 {
225  public:
226 
232 
233  virtual ~QgsLayoutItemMapItemStack();
234 
238  int size() const { return mItems.size(); }
239 
245  virtual bool writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) const;
246 
252  virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context ) = 0;
253 
262  virtual void finalizeRestoreFromXml();
263 
271  void drawItems( QPainter *painter, bool ignoreStacking = true );
272 
277  bool containsAdvancedEffects() const;
278 
284  bool hasEnabledItems() const;
285 
289  QgsLayoutItemMapItem *item( int index ) const;
290 
291  protected:
292 
301  void addItem( QgsLayoutItemMapItem *item SIP_TRANSFER );
302 
309  void removeItem( const QString &itemId );
310 
317  void moveItemUp( const QString &itemId );
318 
325  void moveItemDown( const QString &itemId );
326 
330  QgsLayoutItemMapItem *item( const QString &itemId ) const;
331 
337  QgsLayoutItemMapItem &operator[]( int index ) SIP_SKIP;
338 
342  QList< QgsLayoutItemMapItem * > asList() const;
343 
344  protected:
345 
346  QList< QgsLayoutItemMapItem * > mItems;
347 
348  QgsLayoutItemMap *mMap = nullptr;
349 
354  void removeItems();
355 };
356 
357 #endif //QGSLAYOUTITEMMAPITEM_H
358 
The class is used as a container of context for various read/write operations on other objects...
Base class for all map layer types.
Definition: qgsmaplayer.h:79
QString mName
Friendly display name.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects&#39; current state.
StackingPosition
Item stacking position, specifies where the in the map&#39;s stack the item should be rendered...
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Render above a specific map layer (see stackingLayer())
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
An interface for classes which can visit style entity (e.g.
Render below a specific map layer (see stackingLayer())
int size() const
Returns the number of items in the stack.
Render above all map layers, but below map labels.
bool mEnabled
True if item is to be displayed on map.
Layout graphical items for displaying a map.
#define SIP_SKIP
Definition: qgis_sip.h:126
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
StackingPosition stackingPosition() const
Returns the item&#39;s stacking position, which specifies where the in the map&#39;s stack the item should be...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
void setStackingPosition(StackingPosition position)
Sets the item&#39;s stacking position, which specifies where the in the map&#39;s stack the item should be re...
QString id() const
Returns the unique id for the map item.
A base class for objects which belong to a layout.
QList< QgsLayoutItemMapItem *> mItems
QString mUuid
Unique id.
Render above all map layers and labels.
Render below all map layers.