QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsvectortilebasicrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortilebasicrenderer.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 QGSVECTORTILEBASICRENDERER_H
17 #define QGSVECTORTILEBASICRENDERER_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 
22 #include "qgsvectortilerenderer.h"
23 
24 class QgsLineSymbol;
25 class QgsFillSymbol;
26 class QgsMarkerSymbol;
27 
28 class QgsSymbol;
29 
48 {
49  public:
51  QgsVectorTileBasicRendererStyle( const QString &stName = QString(), const QString &laName = QString(), QgsWkbTypes::GeometryType geomType = QgsWkbTypes::UnknownGeometry );
56 
58  void setStyleName( const QString &name ) { mStyleName = name; }
60  QString styleName() const { return mStyleName; }
61 
63  void setLayerName( const QString &name ) { mLayerName = name; }
65  QString layerName() const { return mLayerName; }
66 
68  void setGeometryType( QgsWkbTypes::GeometryType geomType ) { mGeometryType = geomType; }
70  QgsWkbTypes::GeometryType geometryType() const { return mGeometryType; }
71 
73  void setFilterExpression( const QString &expr ) { mExpression = expr; }
75  QString filterExpression() const { return mExpression; }
76 
78  void setSymbol( QgsSymbol *sym SIP_TRANSFER );
80  QgsSymbol *symbol() const { return mSymbol.get(); }
81 
83  void setEnabled( bool enabled ) { mEnabled = enabled; }
85  bool isEnabled() const { return mEnabled; }
86 
88  void setMinZoomLevel( int minZoom ) { mMinZoomLevel = minZoom; }
90  int minZoomLevel() const { return mMinZoomLevel; }
91 
93  void setMaxZoomLevel( int maxZoom ) { mMaxZoomLevel = maxZoom; }
95  int maxZoomLevel() const { return mMaxZoomLevel; }
96 
98  bool isActive( int zoomLevel ) const
99  {
100  return mEnabled && ( mMinZoomLevel == -1 || zoomLevel >= mMinZoomLevel ) && ( mMaxZoomLevel == -1 || zoomLevel <= mMaxZoomLevel );
101  }
102 
104  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
106  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
107 
108  private:
109  QString mStyleName;
110  QString mLayerName;
111  QgsWkbTypes::GeometryType mGeometryType;
112  std::unique_ptr<QgsSymbol> mSymbol;
113  bool mEnabled = true;
114  QString mExpression;
115  int mMinZoomLevel = -1;
116  int mMaxZoomLevel = -1;
117 };
118 
119 
128 {
129  public:
132 
133  QString type() const override;
134  QgsVectorTileBasicRenderer *clone() const override SIP_FACTORY;
135  void startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange ) override;
136  QMap<QString, QSet<QString> > usedAttributes( const QgsRenderContext & ) override SIP_SKIP;
137  QSet< QString > requiredLayers( QgsRenderContext &context, int tileZoom ) const override;
138  void stopRender( QgsRenderContext &context ) override;
139  void renderTile( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) override;
140  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
141  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
142 
144  void setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles );
146  QList<QgsVectorTileBasicRendererStyle> styles() const;
148  void setStyle( int index, const QgsVectorTileBasicRendererStyle &style ) { mStyles[index] = style; }
150  QgsVectorTileBasicRendererStyle style( int index ) const { return mStyles[index]; }
151 
153  static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
154  const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
155  const QColor &lineStrokeColor, double lineStrokeWidth,
156  const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize );
157 
159  static QList<QgsVectorTileBasicRendererStyle> simpleStyleWithRandomColors();
160 
161  private:
162  void setDefaultStyle();
163 
164  private:
166  QList<QgsVectorTileBasicRendererStyle> mStyles;
167 
168  // temporary bits
169 
171  QMap<QString, QSet<QString> > mRequiredFields;
172 
173 };
174 
175 #endif // QGSVECTORTILEBASICRENDERER_H
QgsVectorTileRenderer::type
virtual QString type() const =0
Returns unique type name of the renderer implementation.
qgsvectortilerenderer.h
QgsVectorTileBasicRenderer::style
QgsVectorTileBasicRendererStyle style(int index) const
Returns style definition at the particular index.
Definition: qgsvectortilebasicrenderer.h:150
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsVectorTileRenderer::stopRender
virtual void stopRender(QgsRenderContext &context)=0
Finishes rendering and cleans up any resources.
QgsTileRange
Range of tiles in a tile matrix to be rendered. The selection is rectangular, given by start/end row ...
Definition: qgstiles.h:70
QgsVectorTileBasicRendererStyle::setEnabled
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering)
Definition: qgsvectortilebasicrenderer.h:83
QgsVectorTileBasicRendererStyle::isEnabled
bool isEnabled() const
Returns whether this style is enabled (used for rendering)
Definition: qgsvectortilebasicrenderer.h:85
QgsVectorTileBasicRenderer
The default vector tile renderer implementation. It has an ordered list of "styles",...
Definition: qgsvectortilebasicrenderer.h:127
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
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsVectorTileBasicRendererStyle::maxZoomLevel
int maxZoomLevel() const
Returns maxnimum zoom level index (negative number means no limit)
Definition: qgsvectortilebasicrenderer.h:95
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsVectorTileBasicRendererStyle
Definition of map rendering of a subset of vector tile data. The subset of data is defined by:
Definition: qgsvectortilebasicrenderer.h:47
QgsVectorTileBasicRendererStyle::isActive
bool isActive(int zoomLevel) const
Returns whether the style is active at given zoom level (also checks "enabled" flag)
Definition: qgsvectortilebasicrenderer.h:98
QgsVectorTileBasicRendererStyle::layerName
QString layerName() const
Returns name of the sub-layer to render (empty layer means that all layers match)
Definition: qgsvectortilebasicrenderer.h:65
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsVectorTileBasicRendererStyle::geometryType
QgsWkbTypes::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
Definition: qgsvectortilebasicrenderer.h:70
QgsVectorTileRenderer
Abstract base class for all vector tile renderer implementations.
Definition: qgsvectortilerenderer.h:92
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
QgsVectorTileRenderer::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads renderer's properties from given XML element.
QgsVectorTileBasicRendererStyle::setFilterExpression
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match)
Definition: qgsvectortilebasicrenderer.h:73
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:29
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
QgsVectorTileBasicRendererStyle::setLayerName
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match)
Definition: qgsvectortilebasicrenderer.h:63
QgsVectorTileBasicRendererStyle::minZoomLevel
int minZoomLevel() const
Returns minimum zoom level index (negative number means no limit)
Definition: qgsvectortilebasicrenderer.h:90
QgsVectorTileRenderer::renderTile
virtual void renderTile(const QgsVectorTileRendererData &tile, QgsRenderContext &context)=0
Renders given vector tile. Must be called between startRender/stopRender.
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsVectorTileBasicRendererStyle::setMinZoomLevel
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit)
Definition: qgsvectortilebasicrenderer.h:88
QgsVectorTileBasicRendererStyle::symbol
QgsSymbol * symbol() const
Returns symbol for rendering.
Definition: qgsvectortilebasicrenderer.h:80
QgsFillSymbol
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:29
QgsVectorTileBasicRendererStyle::filterExpression
QString filterExpression() const
Returns filter expression (empty filter means that all features match)
Definition: qgsvectortilebasicrenderer.h:75
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
QgsVectorTileBasicRendererStyle::setMaxZoomLevel
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit)
Definition: qgsvectortilebasicrenderer.h:93
QgsVectorTileRenderer::clone
virtual QgsVectorTileRenderer * clone() const =0
Returns a clone of the renderer.
QgsVectorTileRenderer::startRender
virtual void startRender(QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange)=0
Initializes rendering. It should be paired with a stopRender() call.
QgsVectorTileBasicRenderer::setStyle
void setStyle(int index, const QgsVectorTileBasicRendererStyle &style)
Updates style definition at the paricular index of the list (the index must be in interval [0,...
Definition: qgsvectortilebasicrenderer.h:148
QgsVectorTileBasicRendererStyle::setStyleName
void setStyleName(const QString &name)
Sets human readable name of this style.
Definition: qgsvectortilebasicrenderer.h:58
QgsVectorTileBasicRendererStyle::styleName
QString styleName() const
Returns human readable name of this style.
Definition: qgsvectortilebasicrenderer.h:60
QgsVectorTileRenderer::writeXml
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
QgsVectorTileRenderer::requiredLayers
virtual QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const
Returns a list of the layers required for rendering.
Definition: qgsvectortilerenderer.h:133
QgsVectorTileBasicRendererStyle::setGeometryType
void setGeometryType(QgsWkbTypes::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon)
Definition: qgsvectortilebasicrenderer.h:68