QGIS API Documentation 3.99.0-Master (8e76e220402)
Loading...
Searching...
No Matches
qgsvectortilebasicrenderer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectortilebasicrenderer.cpp
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
17
18#include "qgsapplication.h"
21#include "qgsfillsymbol.h"
22#include "qgsfillsymbollayer.h"
23#include "qgslinesymbol.h"
24#include "qgslinesymbollayer.h"
25#include "qgsmarkersymbol.h"
27#include "qgssymbollayerutils.h"
28
29#include <QString>
30
31using namespace Qt::StringLiterals;
32
33QgsVectorTileBasicRendererStyle::QgsVectorTileBasicRendererStyle( const QString &stName, const QString &laName, Qgis::GeometryType geomType )
34 : mStyleName( stName )
35 , mLayerName( laName )
36 , mGeometryType( geomType )
37{
38}
39
44
46{
47 if ( &other == this )
48 return *this;
49
50 mStyleName = other.mStyleName;
51 mLayerName = other.mLayerName;
52 mGeometryType = other.mGeometryType;
53 mSymbol.reset( other.mSymbol ? other.mSymbol->clone() : nullptr );
54 mEnabled = other.mEnabled;
55 mExpression = other.mExpression;
56 mMinZoomLevel = other.mMinZoomLevel;
57 mMaxZoomLevel = other.mMaxZoomLevel;
58 return *this;
59}
60
62
64{
65 mSymbol.reset( sym );
66}
67
68void QgsVectorTileBasicRendererStyle::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
69{
70 elem.setAttribute( u"name"_s, mStyleName );
71 elem.setAttribute( u"layer"_s, mLayerName );
72 elem.setAttribute( u"geometry"_s, static_cast<int>( mGeometryType ) );
73 elem.setAttribute( u"enabled"_s, mEnabled ? u"1"_s : u"0"_s );
74 elem.setAttribute( u"expression"_s, mExpression );
75 elem.setAttribute( u"min-zoom"_s, mMinZoomLevel );
76 elem.setAttribute( u"max-zoom"_s, mMaxZoomLevel );
77
78 QDomDocument doc = elem.ownerDocument();
79 QgsSymbolMap symbols;
80 symbols[u"0"_s] = mSymbol.get();
81 QDomElement symbolsElem = QgsSymbolLayerUtils::saveSymbols( symbols, u"symbols"_s, doc, context );
82 elem.appendChild( symbolsElem );
83}
84
85void QgsVectorTileBasicRendererStyle::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
86{
87 mStyleName = elem.attribute( u"name"_s );
88 mLayerName = elem.attribute( u"layer"_s );
89 mGeometryType = static_cast<Qgis::GeometryType>( elem.attribute( u"geometry"_s ).toInt() );
90 mEnabled = elem.attribute( u"enabled"_s ).toInt();
91 mExpression = elem.attribute( u"expression"_s );
92 mMinZoomLevel = elem.attribute( u"min-zoom"_s ).toInt();
93 mMaxZoomLevel = elem.attribute( u"max-zoom"_s ).toInt();
94
95 mSymbol.reset();
96 QDomElement symbolsElem = elem.firstChildElement( u"symbols"_s );
97 if ( !symbolsElem.isNull() )
98 {
99 QgsSymbolMap symbolMap = QgsSymbolLayerUtils::loadSymbols( symbolsElem, context );
100 if ( symbolMap.contains( u"0"_s ) )
101 {
102 mSymbol.reset( symbolMap.take( u"0"_s ) );
103 }
104 }
105}
106
108
109
113
115{
116 return u"basic"_s;
117}
118
120{
122 r->mStyles = mStyles;
123 r->mStyles.detach(); // make a deep copy to make sure symbols get cloned
124 return r;
125}
126
127void QgsVectorTileBasicRenderer::startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange )
128{
129 Q_UNUSED( context )
130 Q_UNUSED( tileRange )
131 // figure out required fields for different layers
132 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
133 {
134 if ( layerStyle.isActive( tileZoom ) )
135 {
136 if ( !layerStyle.filterExpression().isEmpty() )
137 {
138 QgsExpression expr( layerStyle.filterExpression() );
139 mRequiredFields[layerStyle.layerName()].unite( expr.referencedColumns() );
140 }
141 if ( auto *lSymbol = layerStyle.symbol() )
142 {
143 mRequiredFields[layerStyle.layerName()].unite( lSymbol->usedAttributes( context ) );
144 }
145 }
146 }
147}
148
149QMap<QString, QSet<QString> > QgsVectorTileBasicRenderer::usedAttributes( const QgsRenderContext & )
150{
151 return mRequiredFields;
152}
153
155{
156 QSet< QString > res;
157 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
158 {
159 if ( layerStyle.isActive( tileZoom ) )
160 {
161 res.insert( layerStyle.layerName() );
162 }
163 }
164 return res;
165}
166
168{
169 Q_UNUSED( context )
170}
171
173{
174 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
175 {
176 if ( !layerStyle.symbol() || layerStyle.layerName() != "background"_L1 )
177 continue;
178
179 if ( layerStyle.isEnabled() )
180 {
181 QgsSymbol *sym = layerStyle.symbol();
182 sym->startRender( context, QgsFields() );
183
184 QgsFillSymbol *fillSym = dynamic_cast<QgsFillSymbol *>( sym );
185 if ( fillSym )
186 {
187 QPolygon polygon;
188 polygon << QPoint( 0, 0 );
189 polygon << QPoint( 0, context.outputSize().height() );
190 polygon << QPoint( context.outputSize().width(), context.outputSize().height() );
191 polygon << QPoint( context.outputSize().width(), 0 );
192 fillSym->renderPolygon( polygon, nullptr, nullptr, context );
193 }
194 sym->stopRender( context );
195 }
196 break;
197 }
198}
199
201{
202 const QgsVectorTileFeatures tileData = tile.features();
203 const int zoomLevel = tile.renderZoomLevel();
204
205 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
206 {
207 if ( !layerStyle.isActive( zoomLevel ) || !layerStyle.symbol() || layerStyle.layerName() == "background"_L1 )
208 continue;
209
210 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
211 scope->setFields( tile.fields()[layerStyle.layerName()] );
212 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
213
214 QgsExpression filterExpression( layerStyle.filterExpression() );
215 filterExpression.prepare( &context.expressionContext() );
216
217 QgsSymbol *sym = layerStyle.symbol();
218 sym->startRender( context, QgsFields() );
219 if ( layerStyle.layerName().isEmpty() )
220 {
221 // matching all layers
222 for ( const auto &features : tileData )
223 {
224 for ( const QgsFeature &f : features )
225 {
226 scope->setFeature( f );
227 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
228 continue;
229
230 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
231 if ( featureType == layerStyle.geometryType() )
232 {
233 sym->renderFeature( f, context );
234 }
235 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
236 {
237 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
238 // to render the polygon borders only
239 QgsFeature exterior = f;
240 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
241 sym->renderFeature( exterior, context );
242 }
243 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
244 {
245 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
246 // to render the polygon center
247 QgsFeature centroid = f;
248 const QgsRectangle boundingBox = f.geometry().boundingBox();
249 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
250 sym->renderFeature( centroid, context );
251 }
252 }
253 }
254 }
255 else if ( tileData.contains( layerStyle.layerName() ) )
256 {
257 // matching one particular layer
258 for ( const QgsFeature &f : tileData[layerStyle.layerName()] )
259 {
260 scope->setFeature( f );
261 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
262 continue;
263
264 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
265 if ( featureType == layerStyle.geometryType() )
266 {
267 sym->renderFeature( f, context );
268 }
269 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
270 {
271 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
272 // to render the polygon borders only
273 QgsFeature exterior = f;
274 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
275 sym->renderFeature( exterior, context );
276 }
277 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
278 {
279 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
280 // to render the polygon center
281 QgsFeature centroid = f;
282 const QgsRectangle boundingBox = f.geometry().boundingBox();
283 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
284 sym->renderFeature( centroid, context );
285 }
286 }
287 }
288 sym->stopRender( context );
289 }
290}
291
292void QgsVectorTileBasicRenderer::renderSelectedFeatures( const QList<QgsFeature> &selection, QgsRenderContext &context )
293{
294 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
295 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
296
297 for ( const QgsFeature &feature : selection )
298 {
299 bool ok = false;
300 int featureTileZoom = feature.attribute( u"tile_zoom"_s ).toInt( &ok );
301 if ( !ok )
302 featureTileZoom = -1;
303 const QString featureTileLayer = feature.attribute( u"tile_layer"_s ).toString();
304
305 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
306 {
307 if ( ( featureTileZoom >= 0 && !layerStyle.isActive( featureTileZoom ) )
308 || !layerStyle.symbol() || layerStyle.layerName() == "background"_L1 )
309 continue;
310
311 if ( !layerStyle.layerName().isEmpty() && !featureTileLayer.isEmpty() && layerStyle.layerName() != featureTileLayer )
312 continue;
313
314 scope->setFields( feature.fields() );
315
316 QgsExpression filterExpression( layerStyle.filterExpression() );
317 filterExpression.prepare( &context.expressionContext() );
318
319 scope->setFeature( feature );
320 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
321 continue;
322
323 QgsSymbol *sym = layerStyle.symbol();
324 sym->startRender( context, feature.fields() );
325
326 const Qgis::GeometryType featureType = feature.geometry().type();
327 bool renderedFeature = false;
328 if ( featureType == layerStyle.geometryType() )
329 {
330 sym->renderFeature( feature, context, -1, true );
331 renderedFeature = true;
332 }
333 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
334 {
335 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
336 // to render the polygon borders only
337 QgsFeature exterior = feature;
338 exterior.setGeometry( QgsGeometry( feature.geometry().constGet()->boundary() ) );
339 sym->renderFeature( exterior, context, -1, true );
340 renderedFeature = true;
341 }
342 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
343 {
344 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
345 // to render the polygon center
346 QgsFeature centroid = feature;
347 const QgsRectangle boundingBox = feature.geometry().boundingBox();
348 centroid.setGeometry( feature.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
349 sym->renderFeature( centroid, context, -1, true );
350 renderedFeature = true;
351 }
352 sym->stopRender( context );
353
354 if ( renderedFeature )
355 break;
356 }
357 }
358}
359
360bool QgsVectorTileBasicRenderer::willRenderFeature( const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context )
361{
362 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
363 scope->setFields( feature.fields() );
364 scope->setFeature( feature );
365 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
366
367 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
368 {
369 if ( !layerStyle.isActive( tileZoom ) || !layerStyle.symbol() )
370 continue;
371
372 if ( layerStyle.layerName() == "background"_L1 )
373 continue;
374
375 if ( !layerStyle.layerName().isEmpty() && layerStyle.layerName() != layerName )
376 continue;
377
378 QgsExpression filterExpression( layerStyle.filterExpression() );
379 filterExpression.prepare( &context.expressionContext() );
380
381 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
382 continue;
383
384 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( feature.geometry().wkbType() );
385 if ( featureType == layerStyle.geometryType() )
386 {
387 return true;
388 }
389 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
390 {
391 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
392 // to render the polygon borders only
393 return true;
394 }
395 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
396 {
397 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
398 // to render the polygon center
399 return true;
400 }
401 }
402 return false;
403}
404
405void QgsVectorTileBasicRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
406{
407 QDomDocument doc = elem.ownerDocument();
408 QDomElement elemStyles = doc.createElement( u"styles"_s );
409 for ( const QgsVectorTileBasicRendererStyle &layerStyle : mStyles )
410 {
411 QDomElement elemStyle = doc.createElement( u"style"_s );
412 layerStyle.writeXml( elemStyle, context );
413 elemStyles.appendChild( elemStyle );
414 }
415 elem.appendChild( elemStyles );
416}
417
418void QgsVectorTileBasicRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
419{
420 mStyles.clear();
421
422 QDomElement elemStyles = elem.firstChildElement( u"styles"_s );
423 QDomElement elemStyle = elemStyles.firstChildElement( u"style"_s );
424 while ( !elemStyle.isNull() )
425 {
427 layerStyle.readXml( elemStyle, context );
428 mStyles.append( layerStyle );
429 elemStyle = elemStyle.nextSiblingElement( u"style"_s );
430 }
431}
432
433void QgsVectorTileBasicRenderer::setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles )
434{
435 mStyles = styles;
436}
437
438QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::styles() const
439{
440 return mStyles;
441}
442
443QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyleWithRandomColors()
444{
445 QColor polygonFillColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
446 QColor polygonStrokeColor = polygonFillColor;
447 polygonFillColor.setAlpha( 100 );
448 double polygonStrokeWidth = Qgis::DEFAULT_LINE_WIDTH;
449
451 double lineStrokeWidth = Qgis::DEFAULT_LINE_WIDTH;
452
454 QColor pointStrokeColor = pointFillColor;
455 pointFillColor.setAlpha( 100 );
456 double pointSize = Qgis::DEFAULT_POINT_SIZE;
457
458 return simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
459 lineStrokeColor, lineStrokeWidth,
460 pointFillColor, pointStrokeColor, pointSize );
461}
462
463QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyle(
464 const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
465 const QColor &lineStrokeColor, double lineStrokeWidth,
466 const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize )
467{
468 QgsSimpleFillSymbolLayer *fillSymbolLayer = new QgsSimpleFillSymbolLayer();
469 fillSymbolLayer->setFillColor( polygonFillColor );
470 fillSymbolLayer->setStrokeColor( polygonStrokeColor );
471 fillSymbolLayer->setStrokeWidth( polygonStrokeWidth );
472 QgsFillSymbol *fillSymbol = new QgsFillSymbol( QgsSymbolLayerList() << fillSymbolLayer );
473
475 lineSymbolLayer->setColor( lineStrokeColor );
476 lineSymbolLayer->setWidth( lineStrokeWidth );
477 QgsLineSymbol *lineSymbol = new QgsLineSymbol( QgsSymbolLayerList() << lineSymbolLayer );
478
480 markerSymbolLayer->setFillColor( pointFillColor );
481 markerSymbolLayer->setStrokeColor( pointStrokeColor );
482 markerSymbolLayer->setSize( pointSize );
483 QgsMarkerSymbol *markerSymbol = new QgsMarkerSymbol( QgsSymbolLayerList() << markerSymbolLayer );
484
485 QgsVectorTileBasicRendererStyle st1( u"Polygons"_s, QString(), Qgis::GeometryType::Polygon );
486 st1.setFilterExpression( u"geometry_type(@geometry)='Polygon'"_s );
487 st1.setSymbol( fillSymbol );
488
489 QgsVectorTileBasicRendererStyle st2( u"Lines"_s, QString(), Qgis::GeometryType::Line );
490 st2.setFilterExpression( u"geometry_type(@geometry)='Line'"_s );
491 st2.setSymbol( lineSymbol );
492
493 QgsVectorTileBasicRendererStyle st3( u"Points"_s, QString(), Qgis::GeometryType::Point );
494 st3.setFilterExpression( u"geometry_type(@geometry)='Point'"_s );
495 st3.setSymbol( markerSymbol );
496
497 QList<QgsVectorTileBasicRendererStyle> lst;
498 lst << st1 << st2 << st3;
499 return lst;
500}
static const double DEFAULT_LINE_WIDTH
The default width (in millimeters) for line symbols.
Definition qgis.h:6555
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:365
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
static const double DEFAULT_POINT_SIZE
The default size (in millimeters) for point marker symbols.
Definition qgis.h:6552
static QgsColorSchemeRegistry * colorSchemeRegistry()
Returns the application's color scheme registry, used for managing color schemes.
QColor fetchRandomStyleColor() const
Returns a random color for use with a new symbol style (e.g.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
QVariant evaluate()
Evaluate the feature and return the result.
bool isValid() const
Checks if this expression is valid.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsFields fields
Definition qgsfeature.h:70
QgsGeometry geometry
Definition qgsfeature.h:71
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
Definition qgsfields.h:46
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
void renderPolygon(const QPolygonF &points, const QVector< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
Renders the symbol using the given render context.
A geometry is the spatial representation of a feature.
Qgis::WkbType wkbType() const
Returns type of the geometry as a WKB type (point / linestring / polygon etc.).
virtual void setWidth(double width)
Sets the width of the line symbol layer.
A line symbol type, for rendering LineString and MultiLineString geometries.
virtual void setSize(double size)
Sets the symbol size.
A marker symbol type, for rendering Point and MultiPoint geometries.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
QSize outputSize() const
Returns the size of the resulting rendered image, in pixels.
Renders polygons using a single fill and stroke color.
void setStrokeWidth(double strokeWidth)
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setStrokeColor(const QColor &strokeColor) override
Sets the stroke color for the symbol layer.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
Simple marker symbol layer, consisting of a rendered shape with solid fill color and a stroke.
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setStrokeColor(const QColor &color) override
Sets the marker's stroke color.
static QgsSymbolMap loadSymbols(QDomElement &element, const QgsReadWriteContext &context)
Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting ...
static QDomElement saveSymbols(QgsSymbolMap &symbols, const QString &tagName, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a collection of symbols to XML with specified tagName for the top-level element.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
void renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false, Qgis::VertexMarkerType currentVertexMarkerType=Qgis::VertexMarkerType::SemiTransparentCircle, double currentVertexMarkerSize=0.0)
Render a feature.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
A range of tiles in a tile matrix.
Definition qgstiles.h:118
Definition of map rendering of a subset of vector tile data.
QgsVectorTileBasicRendererStyle(const QString &stName=QString(), const QString &laName=QString(), Qgis::GeometryType geomType=Qgis::GeometryType::Unknown)
Constructs a style object.
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match).
void setSymbol(QgsSymbol *sym)
Sets symbol for rendering. Takes ownership of the symbol.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes object content to given DOM element.
QgsVectorTileBasicRendererStyle & operator=(const QgsVectorTileBasicRendererStyle &other)
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads object content from given DOM element.
void renderTile(const QgsVectorTileRendererData &tile, QgsRenderContext &context) override
Renders given vector tile. Must be called between startRender/stopRender.
QList< QgsVectorTileBasicRendererStyle > styles() const
Returns list of styles of the renderer.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &) override
Returns field names of sub-layers that will be used for rendering. Must be called between startRender...
QgsVectorTileBasicRenderer()
Constructs renderer with no styles.
void renderSelectedFeatures(const QList< QgsFeature > &selection, QgsRenderContext &context) override
Renders the specified features in a selected state.
void setStyles(const QList< QgsVectorTileBasicRendererStyle > &styles)
Sets list of styles of the renderer.
void startRender(QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange) override
Initializes rendering. It should be paired with a stopRender() call.
QString type() const override
Returns unique type name of the renderer implementation.
static QList< QgsVectorTileBasicRendererStyle > simpleStyle(const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth, const QColor &lineStrokeColor, double lineStrokeWidth, const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize)
Returns a list of styles to render all layers with the given fill/stroke colors, stroke widths and ma...
bool willRenderFeature(const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context) override
Returns true if the specified feature will be rendered in the given render context.
QgsVectorTileBasicRenderer * clone() const override
Returns a clone of the renderer.
static QList< QgsVectorTileBasicRendererStyle > simpleStyleWithRandomColors()
Returns a list of styles to render all layers, using random colors.
QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const override
Returns a list of the layers required for rendering.
void renderBackground(QgsRenderContext &context) override
Renders the background if defined.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
void stopRender(QgsRenderContext &context) override
Finishes rendering and cleans up any resources.
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
QMap< QString, QgsFields > fields() const
Returns per-layer fields.
QgsVectorTileFeatures features() const
Returns features of the tile grouped by sub-layer names.
int renderZoomLevel() const
Returns the zoom level corresponding to the target render.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:52
QList< QgsSymbolLayer * > QgsSymbolLayerList
Definition qgssymbol.h:30
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map).