QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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  void stopRender( QgsRenderContext &context ) override;
138  void renderTile( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) override;
139  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
140  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
141 
143  void setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles );
145  QList<QgsVectorTileBasicRendererStyle> styles() const;
147  void setStyle( int index, const QgsVectorTileBasicRendererStyle &style ) { mStyles[index] = style; }
149  QgsVectorTileBasicRendererStyle style( int index ) const { return mStyles[index]; }
150 
152  static QList<QgsVectorTileBasicRendererStyle> simpleStyle(
153  const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
154  const QColor &lineStrokeColor, double lineStrokeWidth,
155  const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize );
156 
158  static QList<QgsVectorTileBasicRendererStyle> simpleStyleWithRandomColors();
159 
160  private:
161  void setDefaultStyle();
162 
163  private:
165  QList<QgsVectorTileBasicRendererStyle> mStyles;
166 
167  // temporary bits
168 
170  QMap<QString, QSet<QString> > mRequiredFields;
171 
172 };
173 
174 #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:149
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsVectorTileRenderer::stopRender
virtual void stopRender(QgsRenderContext &context)=0
Finishes rendering and cleans up any resources.
QgsTileRange
Definition: qgstiles.h:65
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
Definition: qgsvectortilebasicrenderer.h:127
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsVectorTileRendererData
Definition: qgsvectortilerenderer.h:37
QgsSymbol
Definition: qgssymbol.h:63
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: 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
Definition: qgsvectortilerenderer.h:88
QgsMarkerSymbol
Definition: qgssymbol.h:917
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
Definition: qgssymbol.h:1117
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:116
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:139
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
Definition: qgssymbol.h:1212
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:144
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:147
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.
QgsVectorTileBasicRendererStyle::setGeometryType
void setGeometryType(QgsWkbTypes::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon)
Definition: qgsvectortilebasicrenderer.h:68