QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
197  virtual QgsMapLayer *mapLayer();
198 
200 
201  protected:
202 
204  QString mName;
205 
207  QgsLayoutItemMap *mMap = nullptr;
208 
210  QString mUuid;
211 
213  bool mEnabled;
214 
215  StackingPosition mStackingPosition = StackBelowMapLabels;
216 
218 
219 };
220 
230 class CORE_EXPORT QgsLayoutItemMapItemStack
231 {
232  public:
233 
239 
240  virtual ~QgsLayoutItemMapItemStack();
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 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsLayoutItemMapItem::StackAboveMapLayer
@ StackAboveMapLayer
Render above a specific map layer (see stackingLayer())
Definition: qgslayoutitemmapitem.h:44
QgsLayoutItemMapItemStack::readXml
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...
QgsLayoutItemMapItem::StackBelowMapLayer
@ StackBelowMapLayer
Render below a specific map layer (see stackingLayer())
Definition: qgslayoutitemmapitem.h:43
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsLayoutItemMapItem::draw
virtual void draw(QPainter *painter)=0
Draws the item on to a destination painter.
QgsLayoutItemMapItem::mName
QString mName
Friendly display name.
Definition: qgslayoutitemmapitem.h:204
QgsLayoutItemMapItem
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Definition: qgslayoutitemmapitem.h:34
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsLayoutItemMapItem::id
QString id() const
Returns the unique id for the map item.
Definition: qgslayoutitemmapitem.h:100
QgsLayoutItemMapItemStack
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
Definition: qgslayoutitemmapitem.h:231
QgsLayoutItemMapItem::StackBelowMap
@ StackBelowMap
Render below all map layers.
Definition: qgslayoutitemmapitem.h:42
QgsLayoutItemMapItem::setStackingPosition
void setStackingPosition(StackingPosition position)
Sets the item's stacking position, which specifies where the in the map's stack the item should be re...
Definition: qgslayoutitemmapitem.h:151
QgsLayoutItemMapItem::mEnabled
bool mEnabled
True if item is to be displayed on map.
Definition: qgslayoutitemmapitem.h:213
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayoutItemMapItem::StackBelowMapLabels
@ StackBelowMapLabels
Render above all map layers, but below map labels.
Definition: qgslayoutitemmapitem.h:45
QgsLayoutItemMapItem::mUuid
QString mUuid
Unique id.
Definition: qgslayoutitemmapitem.h:210
QgsLayoutObject::createExpressionContext
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
Definition: qgslayoutobject.cpp:156
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:318
QgsLayoutItemMapItemStack::mItems
QList< QgsLayoutItemMapItem * > mItems
Definition: qgslayoutitemmapitem.h:353
QgsLayoutItemMapItem::stackingPosition
StackingPosition stackingPosition() const
Returns the item's stacking position, which specifies where the in the map's stack the item should be...
Definition: qgslayoutitemmapitem.h:140
QgsLayoutItemMapItemStack::size
int size() const
Returns the number of items in the stack.
Definition: qgslayoutitemmapitem.h:245
QgsLayoutItemMapItem::StackAboveMapLabels
@ StackAboveMapLabels
Render above all map layers and labels.
Definition: qgslayoutitemmapitem.h:46
QgsLayoutItemMapItem::StackingPosition
StackingPosition
Item stacking position, specifies where the in the map's stack the item should be rendered.
Definition: qgslayoutitemmapitem.h:41
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsLayoutItemMapItem::mStackingLayer
QgsMapLayerRef mStackingLayer
Definition: qgslayoutitemmapitem.h:217
qgsmaplayerref.h
_LayerRef< QgsMapLayer >
qgslayoutobject.h
QgsLayoutObject
A base class for objects which belong to a layout.
Definition: qgslayoutobject.h:40