QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsvectortilerenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortilerenderer.h
3  --------------------------------------
4  Date : March 2020
5  Copyright : (C) 2020 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVECTORTILERENDERER_H
17 #define QGSVECTORTILERENDERER_H
18 
19 #include "qgis_core.h"
20 
21 #include "qgsfeature.h"
22 
23 #include "qgstiles.h"
24 
25 class QgsRenderContext;
27 class QgsProject;
28 
30 typedef QMap<QString, QVector<QgsFeature> > QgsVectorTileFeatures SIP_SKIP;
31 
39 class CORE_EXPORT QgsVectorTileRendererData
40 {
41  public:
44  : mId( id )
45  {}
46 
48  QgsTileXYZ id() const { return mId; }
49 
51  void setTilePolygon( QPolygon polygon ) { mTilePolygon = polygon; }
53  QPolygon tilePolygon() const { return mTilePolygon; }
54 
56  void setFields( const QMap<QString, QgsFields> &fields ) { mFields = fields; }
58  QMap<QString, QgsFields> fields() const { return mFields; }
59 
61  void setFeatures( const QgsVectorTileFeatures &features ) SIP_SKIP { mFeatures = features; }
63  QgsVectorTileFeatures features() const SIP_SKIP { return mFeatures; }
65  QStringList layers() const { return mFeatures.keys(); }
67  QVector<QgsFeature> layerFeatures( const QString &layerName ) const { return mFeatures[layerName]; }
68 
69  private:
71  QgsTileXYZ mId;
73  QMap<QString, QgsFields> mFields;
75  QgsVectorTileFeatures mFeatures;
77  QPolygon mTilePolygon;
78 };
79 
92 class CORE_EXPORT QgsVectorTileRenderer
93 {
94 
95 #ifdef SIP_RUN
97 
98  const QString type = sipCpp->type();
99 
100  if ( type == QLatin1String( "basic" ) )
101  sipType = sipType_QgsVectorTileBasicRenderer;
102  else
103  sipType = 0;
104  SIP_END
105 #endif
106 
107  public:
108  virtual ~QgsVectorTileRenderer() = default;
109 
111  virtual QString type() const = 0;
112 
114  virtual QgsVectorTileRenderer *clone() const = 0 SIP_FACTORY;
115 
117  virtual void startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange ) = 0;
118 
120  virtual QMap<QString, QSet<QString> > usedAttributes( const QgsRenderContext & ) SIP_SKIP { return QMap<QString, QSet<QString> >(); }
121 
122  //TODO QGIS 4.0 -- make pure virtual
123 
133  virtual QSet< QString > requiredLayers( QgsRenderContext &context, int tileZoom ) const { Q_UNUSED( context ); Q_UNUSED( tileZoom ); return QSet< QString >() << QString(); }
134 
136  virtual void stopRender( QgsRenderContext &context ) = 0;
137 
139  virtual void renderTile( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) = 0;
140 
142  virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const = 0;
144  virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) = 0;
146  virtual void resolveReferences( const QgsProject &project ) { Q_UNUSED( project ) }
147 
148 };
149 
150 #endif // QGSVECTORTILERENDERER_H
QgsTileXYZ
Stores coordinates of a tile in a tile matrix set. Tile matrix is identified by the zoomLevel(),...
Definition: qgstiles.h:37
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsVectorTileRendererData::setFields
void setFields(const QMap< QString, QgsFields > &fields)
Sets per-layer fields.
Definition: qgsvectortilerenderer.h:56
QgsTileRange
Range of tiles in a tile matrix to be rendered. The selection is rectangular, given by start/end row ...
Definition: qgstiles.h:70
qgsfeature.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsVectorTileRendererData
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
Definition: qgsvectortilerenderer.h:39
QgsVectorTileRendererData::tilePolygon
QPolygon tilePolygon() const
Returns polygon (made out of four corners of the tile) in screen coordinates calculated from render c...
Definition: qgsvectortilerenderer.h:53
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsVectorTileRendererData::id
QgsTileXYZ id() const
Returns coordinates of the tile.
Definition: qgsvectortilerenderer.h:48
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsVectorTileRendererData::QgsVectorTileRendererData
QgsVectorTileRendererData(QgsTileXYZ id)
Constructs the object.
Definition: qgsvectortilerenderer.h:43
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QgsVectorTileRendererData::fields
QMap< QString, QgsFields > fields() const
Returns per-layer fields.
Definition: qgsvectortilerenderer.h:58
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsVectorTileRenderer
Abstract base class for all vector tile renderer implementations.
Definition: qgsvectortilerenderer.h:92
QgsVectorTileRendererData::setFeatures
void setFeatures(const QgsVectorTileFeatures &features)
Sets features of the tile.
Definition: qgsvectortilerenderer.h:61
QgsVectorTileRenderer::usedAttributes
virtual QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &)
Returns field names of sub-layers that will be used for rendering. Must be called between startRender...
Definition: qgsvectortilerenderer.h:120
QgsVectorTileRendererData::setTilePolygon
void setTilePolygon(QPolygon polygon)
Sets polygon of the tile.
Definition: qgsvectortilerenderer.h:51
qgstiles.h
QgsVectorTileRendererData::layers
QStringList layers() const
Returns list of layer names present in the tile.
Definition: qgsvectortilerenderer.h:65
QgsVectorTileRendererData::layerFeatures
QVector< QgsFeature > layerFeatures(const QString &layerName) const
Returns list of all features within a single sub-layer.
Definition: qgsvectortilerenderer.h:67
QgsVectorTileRendererData::features
QgsVectorTileFeatures features() const
Returns features of the tile grouped by sub-layer names.
Definition: qgsvectortilerenderer.h:63
QgsVectorTileFeatures
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map)
Definition: qgsvectortilerenderer.h:27
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
QgsVectorTileRenderer::resolveReferences
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
Definition: qgsvectortilerenderer.h:146
QgsVectorTileRenderer::requiredLayers
virtual QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const
Returns a list of the layers required for rendering.
Definition: qgsvectortilerenderer.h:133