QGIS API Documentation  3.6.0-Noosa (5873452)
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  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 
181  protected:
182 
184  QString mName;
185 
187  QgsLayoutItemMap *mMap = nullptr;
188 
190  QString mUuid;
191 
193  bool mEnabled;
194 
195  StackingPosition mStackingPosition = StackBelowMapLabels;
196 
198 
199 };
200 
210 class CORE_EXPORT QgsLayoutItemMapItemStack
211 {
212  public:
213 
219 
220  virtual ~QgsLayoutItemMapItemStack();
221 
225  int size() const { return mItems.size(); }
226 
232  virtual bool writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) const;
233 
239  virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context ) = 0;
240 
249  virtual void finalizeRestoreFromXml();
250 
258  void drawItems( QPainter *painter, bool ignoreStacking = true );
259 
264  bool containsAdvancedEffects() const;
265 
266  protected:
267 
276  void addItem( QgsLayoutItemMapItem *item SIP_TRANSFER );
277 
284  void removeItem( const QString &itemId );
285 
292  void moveItemUp( const QString &itemId );
293 
300  void moveItemDown( const QString &itemId );
301 
305  QgsLayoutItemMapItem *item( const QString &itemId ) const;
306 
310  QgsLayoutItemMapItem *item( int index ) const;
311 
317  QgsLayoutItemMapItem &operator[]( int index ) SIP_SKIP;
318 
322  QList< QgsLayoutItemMapItem * > asList() const;
323 
324  protected:
325 
326  QList< QgsLayoutItemMapItem * > mItems;
327 
328  QgsLayoutItemMap *mMap = nullptr;
329 
334  void removeItems();
335 };
336 
337 #endif //QGSLAYOUTITEMMAPITEM_H
338 
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:64
QString mName
Friendly display name.
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.
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:119
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.