QGIS API Documentation  3.21.0-Master (5b68dc587e)
qgsannotationlayer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsannotationlayer.h
3  ----------------
4  copyright : (C) 2019 by Sandro Mani
5  email : smani at sourcepole dot ch
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef QGSANNOTATIONLAYER_H
18 #define QGSANNOTATIONLAYER_H
19 
20 #include "qgis_core.h"
21 #include "qgis_sip.h"
22 #include "qgsmaplayer.h"
23 #include "qgsmaplayerrenderer.h"
24 
25 
26 class QgsAnnotationItem;
28 class QgsPaintEffect;
29 
30 
32 class QgsAnnotationLayerSpatialIndex;
34 
46 class CORE_EXPORT QgsAnnotationLayer : public QgsMapLayer
47 {
48  Q_OBJECT
49 
50  public:
51 
56  struct LayerOptions
57  {
58 
62  explicit LayerOptions( const QgsCoordinateTransformContext &transformContext )
63  : transformContext( transformContext )
64  {}
65 
70 
71  };
72 
73 
79  QgsAnnotationLayer( const QString &name, const QgsAnnotationLayer::LayerOptions &options );
80  ~QgsAnnotationLayer() override;
81 
82 #ifdef SIP_RUN
83  SIP_PYOBJECT __repr__();
84  % MethodCode
85  QString str = QStringLiteral( "<QgsAnnotationLayer: '%1'>" ).arg( sipCpp->name() );
86  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
87  % End
88 #endif
89 
93  void reset();
94 
102  QString addItem( QgsAnnotationItem *item SIP_TRANSFER );
103 
111  void replaceItem( const QString &id, QgsAnnotationItem *item SIP_TRANSFER );
112 
116  bool removeItem( const QString &id );
117 
121  void clear();
122 
126  bool isEmpty() const;
127 
134  QMap<QString, QgsAnnotationItem *> items() const { return mItems; }
135 
141  QgsAnnotationItem *item( const QString &id );
142 
151  QStringList itemsInBounds( const QgsRectangle &bounds, QgsRenderContext &context, QgsFeedback *feedback = nullptr ) const;
152 
161 
162  Qgis::MapLayerProperties properties() const override;
163  QgsAnnotationLayer *clone() const override SIP_FACTORY;
164  QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) override SIP_FACTORY;
165  QgsRectangle extent() const override;
166  void setTransformContext( const QgsCoordinateTransformContext &context ) override;
167  bool readXml( const QDomNode &layerNode, QgsReadWriteContext &context ) override;
168  bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
169  bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &, StyleCategories categories = AllStyleCategories ) const override;
170  bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) override;
171  bool isEditable() const override;
172  bool supportsEditing() const override;
173  QgsDataProvider *dataProvider() override;
174  const QgsDataProvider *dataProvider() const override SIP_SKIP;
175  QString htmlMetadata() const override;
176 
182  QgsPaintEffect *paintEffect() const;
183 
192  void setPaintEffect( QgsPaintEffect *effect SIP_TRANSFER );
193 
194  private:
195 
196  QStringList queryIndex( const QgsRectangle &bounds, QgsFeedback *feedback = nullptr ) const;
197 
198  QMap<QString, QgsAnnotationItem *> mItems;
199  QgsCoordinateTransformContext mTransformContext;
200 
201  std::unique_ptr< QgsAnnotationLayerSpatialIndex > mSpatialIndex;
202  QSet< QString > mNonIndexedItems;
203 
204  QgsDataProvider *mDataProvider = nullptr;
205 
206  std::unique_ptr< QgsPaintEffect > mPaintEffect;
207 
209 
210 };
211 
212 #ifndef SIP_RUN
214 
220 class QgsAnnotationLayerDataProvider : public QgsDataProvider
221 {
222  Q_OBJECT
223 
224  public:
225  QgsAnnotationLayerDataProvider( const QgsDataProvider::ProviderOptions &providerOptions,
226  QgsDataProvider::ReadFlags flags );
227  QgsCoordinateReferenceSystem crs() const override;
228  QString name() const override;
229  QString description() const override;
230  QgsRectangle extent() const override;
231  bool isValid() const override;
232 
233 };
235 #endif
236 
237 #endif // QGSANNOTATIONLAYER_H
AnnotationItemEditOperationResult
Results from an edit operation on an annotation item.
Definition: qgis.h:814
Abstract base class for annotation item edit operations.
Abstract base class for annotation items which are drawn with QgsAnnotationLayers.
Implementation of threaded rendering for annotation layers.
Represents a map layer containing a set of georeferenced annotations, e.g.
QMap< QString, QgsAnnotationItem * > items() const
Returns a map of items contained in the layer, by unique item ID.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
virtual Qgis::MapLayerProperties properties() const
Returns the map layer properties of this layer.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
Base class for visual effects which can be applied to QPicture drawings.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
#define str(x)
Definition: qgis.cpp:37
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
const QgsCoordinateReferenceSystem & crs
Setting options for loading annotation layers.
LayerOptions(const QgsCoordinateTransformContext &transformContext)
Constructor for LayerOptions.
QgsCoordinateTransformContext transformContext
Coordinate transform context.
Setting options for creating vector data providers.