QGIS API Documentation  3.0.2-Girona (307d082)
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 
24 class QgsLayoutItemMap;
25 
32 class CORE_EXPORT QgsLayoutItemMapItem : public QgsLayoutObject
33 {
34  Q_OBJECT
35 
36  public:
37 
43  QgsLayoutItemMapItem( const QString &name, QgsLayoutItemMap *map );
44 
48  virtual void draw( QPainter *painter ) = 0;
49 
55  virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
56 
62  virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context );
63 
72  virtual void finalizeRestoreFromXml();
73 
78  void setMap( QgsLayoutItemMap *map );
79 
84  const QgsLayoutItemMap *map() const;
85 
89  QString id() const { return mUuid; }
90 
95  void setName( const QString &name );
96 
101  QString name() const;
102 
107  void setEnabled( bool enabled );
108 
113  bool enabled() const;
114 
118  virtual bool usesAdvancedEffects() const;
119 
120  protected:
121 
123  QString mName;
124 
126  QgsLayoutItemMap *mMap = nullptr;
127 
129  QString mUuid;
130 
132  bool mEnabled;
133 
134 };
135 
136 
137 
147 class CORE_EXPORT QgsLayoutItemMapItemStack
148 {
149  public:
150 
156 
157  virtual ~QgsLayoutItemMapItemStack();
158 
162  int size() const { return mItems.size(); }
163 
169  virtual bool writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) const;
170 
176  virtual bool readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context ) = 0;
177 
186  virtual void finalizeRestoreFromXml();
187 
191  void drawItems( QPainter *painter );
192 
197  bool containsAdvancedEffects() const;
198 
199  protected:
200 
209  void addItem( QgsLayoutItemMapItem *item SIP_TRANSFER );
210 
217  void removeItem( const QString &itemId );
218 
225  void moveItemUp( const QString &itemId );
226 
233  void moveItemDown( const QString &itemId );
234 
239  QgsLayoutItemMapItem *item( const QString &itemId ) const;
240 
245  QgsLayoutItemMapItem *item( int index ) const;
246 
253  QgsLayoutItemMapItem &operator[]( int index ) SIP_SKIP;
254 
258  QList< QgsLayoutItemMapItem * > asList() const;
259 
260  protected:
261 
262  QList< QgsLayoutItemMapItem * > mItems;
263 
264  QgsLayoutItemMap *mMap = nullptr;
265 
270  void removeItems();
271 };
272 
273 #endif //QGSLAYOUTITEMMAPITEM_H
274 
The class is used as a container of context for various read/write operations on other objects...
QString mName
Friendly display name.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
int size() const
Returns the number of items in the stack.
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
#define SIP_TRANSFER
Definition: qgis_sip.h:36
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.