QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgssymbol.h:1307
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1204
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:1004
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:65
Range of tiles in a tile matrix to be rendered.
Definition: qgstiles.h:66
Definition of map rendering of a subset of vector tile data.
QgsSymbol * symbol() const
Returns symbol for rendering.
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering)
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit)
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match)
void setGeometryType(QgsWkbTypes::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon)
QString filterExpression() const
Returns filter expression (empty filter means that all features match)
QString styleName() const
Returns human readable name of this style.
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match)
void setStyleName(const QString &name)
Sets human readable name of this style.
QgsWkbTypes::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
bool isEnabled() const
Returns whether this style is enabled (used for rendering)
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit)
int minZoomLevel() const
Returns minimum zoom level index (negative number means no limit)
int maxZoomLevel() const
Returns maxnimum zoom level index (negative number means no limit)
QString layerName() const
Returns name of the sub-layer to render (empty layer means that all layers match)
bool isActive(int zoomLevel) const
Returns whether the style is active at given zoom level (also checks "enabled" flag)
The default vector tile renderer implementation.
void setStyle(int index, const QgsVectorTileBasicRendererStyle &style)
Updates style definition at the paricular index of the list (the index must be in interval [0,...
QgsVectorTileBasicRendererStyle style(int index) const
Returns style definition at the particular index.
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
Abstract base class for all vector tile renderer implementations.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76