QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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 "qgsfillsymbollayer.h"
22#include "qgslinesymbollayer.h"
24#include "qgssymbollayerutils.h"
25#include "qgsfillsymbol.h"
26#include "qgslinesymbol.h"
27#include "qgsmarkersymbol.h"
28
29QgsVectorTileBasicRendererStyle::QgsVectorTileBasicRendererStyle( const QString &stName, const QString &laName, Qgis::GeometryType geomType )
30 : mStyleName( stName )
31 , mLayerName( laName )
32 , mGeometryType( geomType )
33{
34}
35
40
42{
43 mStyleName = other.mStyleName;
44 mLayerName = other.mLayerName;
45 mGeometryType = other.mGeometryType;
46 mSymbol.reset( other.mSymbol ? other.mSymbol->clone() : nullptr );
47 mEnabled = other.mEnabled;
48 mExpression = other.mExpression;
49 mMinZoomLevel = other.mMinZoomLevel;
50 mMaxZoomLevel = other.mMaxZoomLevel;
51 return *this;
52}
53
55
57{
58 mSymbol.reset( sym );
59}
60
61void QgsVectorTileBasicRendererStyle::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
62{
63 elem.setAttribute( QStringLiteral( "name" ), mStyleName );
64 elem.setAttribute( QStringLiteral( "layer" ), mLayerName );
65 elem.setAttribute( QStringLiteral( "geometry" ), static_cast<int>( mGeometryType ) );
66 elem.setAttribute( QStringLiteral( "enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
67 elem.setAttribute( QStringLiteral( "expression" ), mExpression );
68 elem.setAttribute( QStringLiteral( "min-zoom" ), mMinZoomLevel );
69 elem.setAttribute( QStringLiteral( "max-zoom" ), mMaxZoomLevel );
70
71 QDomDocument doc = elem.ownerDocument();
72 QgsSymbolMap symbols;
73 symbols[QStringLiteral( "0" )] = mSymbol.get();
74 QDomElement symbolsElem = QgsSymbolLayerUtils::saveSymbols( symbols, QStringLiteral( "symbols" ), doc, context );
75 elem.appendChild( symbolsElem );
76}
77
78void QgsVectorTileBasicRendererStyle::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
79{
80 mStyleName = elem.attribute( QStringLiteral( "name" ) );
81 mLayerName = elem.attribute( QStringLiteral( "layer" ) );
82 mGeometryType = static_cast<Qgis::GeometryType>( elem.attribute( QStringLiteral( "geometry" ) ).toInt() );
83 mEnabled = elem.attribute( QStringLiteral( "enabled" ) ).toInt();
84 mExpression = elem.attribute( QStringLiteral( "expression" ) );
85 mMinZoomLevel = elem.attribute( QStringLiteral( "min-zoom" ) ).toInt();
86 mMaxZoomLevel = elem.attribute( QStringLiteral( "max-zoom" ) ).toInt();
87
88 mSymbol.reset();
89 QDomElement symbolsElem = elem.firstChildElement( QStringLiteral( "symbols" ) );
90 if ( !symbolsElem.isNull() )
91 {
92 QgsSymbolMap symbolMap = QgsSymbolLayerUtils::loadSymbols( symbolsElem, context );
93 if ( symbolMap.contains( QStringLiteral( "0" ) ) )
94 {
95 mSymbol.reset( symbolMap.take( QStringLiteral( "0" ) ) );
96 }
97 }
98}
99
101
102
106
108{
109 return QStringLiteral( "basic" );
110}
111
113{
115 r->mStyles = mStyles;
116 r->mStyles.detach(); // make a deep copy to make sure symbols get cloned
117 return r;
118}
119
120void QgsVectorTileBasicRenderer::startRender( QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange )
121{
122 Q_UNUSED( context )
123 Q_UNUSED( tileRange )
124 // figure out required fields for different layers
125 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
126 {
127 if ( layerStyle.isActive( tileZoom ) )
128 {
129 if ( !layerStyle.filterExpression().isEmpty() )
130 {
131 QgsExpression expr( layerStyle.filterExpression() );
132 mRequiredFields[layerStyle.layerName()].unite( expr.referencedColumns() );
133 }
134 if ( auto *lSymbol = layerStyle.symbol() )
135 {
136 mRequiredFields[layerStyle.layerName()].unite( lSymbol->usedAttributes( context ) );
137 }
138 }
139 }
140}
141
142QMap<QString, QSet<QString> > QgsVectorTileBasicRenderer::usedAttributes( const QgsRenderContext & )
143{
144 return mRequiredFields;
145}
146
148{
149 QSet< QString > res;
150 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
151 {
152 if ( layerStyle.isActive( tileZoom ) )
153 {
154 res.insert( layerStyle.layerName() );
155 }
156 }
157 return res;
158}
159
161{
162 Q_UNUSED( context )
163}
164
166{
167 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
168 {
169 if ( !layerStyle.symbol() || layerStyle.layerName() != QLatin1String( "background" ) )
170 continue;
171
172 if ( layerStyle.isEnabled() )
173 {
174 QgsSymbol *sym = layerStyle.symbol();
175 sym->startRender( context, QgsFields() );
176
177 QgsFillSymbol *fillSym = dynamic_cast<QgsFillSymbol *>( sym );
178 if ( fillSym )
179 {
180 QPolygon polygon;
181 polygon << QPoint( 0, 0 );
182 polygon << QPoint( 0, context.outputSize().height() );
183 polygon << QPoint( context.outputSize().width(), context.outputSize().height() );
184 polygon << QPoint( context.outputSize().width(), 0 );
185 fillSym->renderPolygon( polygon, nullptr, nullptr, context );
186 }
187 sym->stopRender( context );
188 }
189 break;
190 }
191}
192
194{
195 const QgsVectorTileFeatures tileData = tile.features();
196 const int zoomLevel = tile.renderZoomLevel();
197
198 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
199 {
200 if ( !layerStyle.isActive( zoomLevel ) || !layerStyle.symbol() || layerStyle.layerName() == QLatin1String( "background" ) )
201 continue;
202
203 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
204 scope->setFields( tile.fields()[layerStyle.layerName()] );
205 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
206
207 QgsExpression filterExpression( layerStyle.filterExpression() );
208 filterExpression.prepare( &context.expressionContext() );
209
210 QgsSymbol *sym = layerStyle.symbol();
211 sym->startRender( context, QgsFields() );
212 if ( layerStyle.layerName().isEmpty() )
213 {
214 // matching all layers
215 for ( const auto &features : tileData )
216 {
217 for ( const QgsFeature &f : features )
218 {
219 scope->setFeature( f );
220 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
221 continue;
222
223 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
224 if ( featureType == layerStyle.geometryType() )
225 {
226 sym->renderFeature( f, context );
227 }
228 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
229 {
230 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
231 // to render the polygon borders only
232 QgsFeature exterior = f;
233 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
234 sym->renderFeature( exterior, context );
235 }
236 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
237 {
238 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
239 // to render the polygon center
240 QgsFeature centroid = f;
241 const QgsRectangle boundingBox = f.geometry().boundingBox();
242 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
243 sym->renderFeature( centroid, context );
244 }
245 }
246 }
247 }
248 else if ( tileData.contains( layerStyle.layerName() ) )
249 {
250 // matching one particular layer
251 for ( const QgsFeature &f : tileData[layerStyle.layerName()] )
252 {
253 scope->setFeature( f );
254 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
255 continue;
256
257 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
258 if ( featureType == layerStyle.geometryType() )
259 {
260 sym->renderFeature( f, context );
261 }
262 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
263 {
264 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
265 // to render the polygon borders only
266 QgsFeature exterior = f;
267 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
268 sym->renderFeature( exterior, context );
269 }
270 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
271 {
272 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
273 // to render the polygon center
274 QgsFeature centroid = f;
275 const QgsRectangle boundingBox = f.geometry().boundingBox();
276 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
277 sym->renderFeature( centroid, context );
278 }
279 }
280 }
281 sym->stopRender( context );
282 }
283}
284
285void QgsVectorTileBasicRenderer::renderSelectedFeatures( const QList<QgsFeature> &selection, QgsRenderContext &context )
286{
287 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
288 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
289
290 for ( const QgsFeature &feature : selection )
291 {
292 bool ok = false;
293 int featureTileZoom = feature.attribute( QStringLiteral( "tile_zoom" ) ).toInt( &ok );
294 if ( !ok )
295 featureTileZoom = -1;
296 const QString featureTileLayer = feature.attribute( QStringLiteral( "tile_layer" ) ).toString();
297
298 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
299 {
300 if ( ( featureTileZoom >= 0 && !layerStyle.isActive( featureTileZoom ) )
301 || !layerStyle.symbol() || layerStyle.layerName() == QLatin1String( "background" ) )
302 continue;
303
304 if ( !layerStyle.layerName().isEmpty() && !featureTileLayer.isEmpty() && layerStyle.layerName() != featureTileLayer )
305 continue;
306
307 scope->setFields( feature.fields() );
308
309 QgsExpression filterExpression( layerStyle.filterExpression() );
310 filterExpression.prepare( &context.expressionContext() );
311
312 scope->setFeature( feature );
313 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
314 continue;
315
316 QgsSymbol *sym = layerStyle.symbol();
317 sym->startRender( context, feature.fields() );
318
319 const Qgis::GeometryType featureType = feature.geometry().type();
320 bool renderedFeature = false;
321 if ( featureType == layerStyle.geometryType() )
322 {
323 sym->renderFeature( feature, context, -1, true );
324 renderedFeature = true;
325 }
326 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
327 {
328 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
329 // to render the polygon borders only
330 QgsFeature exterior = feature;
331 exterior.setGeometry( QgsGeometry( feature.geometry().constGet()->boundary() ) );
332 sym->renderFeature( exterior, context, -1, true );
333 renderedFeature = true;
334 }
335 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
336 {
337 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
338 // to render the polygon center
339 QgsFeature centroid = feature;
340 const QgsRectangle boundingBox = feature.geometry().boundingBox();
341 centroid.setGeometry( feature.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
342 sym->renderFeature( centroid, context, -1, true );
343 renderedFeature = true;
344 }
345 sym->stopRender( context );
346
347 if ( renderedFeature )
348 break;
349 }
350 }
351}
352
353bool QgsVectorTileBasicRenderer::willRenderFeature( const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context )
354{
355 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
356 scope->setFields( feature.fields() );
357 scope->setFeature( feature );
358 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
359
360 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
361 {
362 if ( !layerStyle.isActive( tileZoom ) || !layerStyle.symbol() )
363 continue;
364
365 if ( layerStyle.layerName() == QLatin1String( "background" ) )
366 continue;
367
368 if ( !layerStyle.layerName().isEmpty() && layerStyle.layerName() != layerName )
369 continue;
370
371 QgsExpression filterExpression( layerStyle.filterExpression() );
372 filterExpression.prepare( &context.expressionContext() );
373
374 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
375 continue;
376
377 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( feature.geometry().wkbType() );
378 if ( featureType == layerStyle.geometryType() )
379 {
380 return true;
381 }
382 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
383 {
384 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
385 // to render the polygon borders only
386 return true;
387 }
388 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
389 {
390 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
391 // to render the polygon center
392 return true;
393 }
394 }
395 return false;
396}
397
398void QgsVectorTileBasicRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
399{
400 QDomDocument doc = elem.ownerDocument();
401 QDomElement elemStyles = doc.createElement( QStringLiteral( "styles" ) );
402 for ( const QgsVectorTileBasicRendererStyle &layerStyle : mStyles )
403 {
404 QDomElement elemStyle = doc.createElement( QStringLiteral( "style" ) );
405 layerStyle.writeXml( elemStyle, context );
406 elemStyles.appendChild( elemStyle );
407 }
408 elem.appendChild( elemStyles );
409}
410
411void QgsVectorTileBasicRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
412{
413 mStyles.clear();
414
415 QDomElement elemStyles = elem.firstChildElement( QStringLiteral( "styles" ) );
416 QDomElement elemStyle = elemStyles.firstChildElement( QStringLiteral( "style" ) );
417 while ( !elemStyle.isNull() )
418 {
420 layerStyle.readXml( elemStyle, context );
421 mStyles.append( layerStyle );
422 elemStyle = elemStyle.nextSiblingElement( QStringLiteral( "style" ) );
423 }
424}
425
426void QgsVectorTileBasicRenderer::setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles )
427{
428 mStyles = styles;
429}
430
431QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::styles() const
432{
433 return mStyles;
434}
435
436QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyleWithRandomColors()
437{
438 QColor polygonFillColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
439 QColor polygonStrokeColor = polygonFillColor;
440 polygonFillColor.setAlpha( 100 );
441 double polygonStrokeWidth = DEFAULT_LINE_WIDTH;
442
444 double lineStrokeWidth = DEFAULT_LINE_WIDTH;
445
447 QColor pointStrokeColor = pointFillColor;
448 pointFillColor.setAlpha( 100 );
449 double pointSize = DEFAULT_POINT_SIZE;
450
451 return simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
452 lineStrokeColor, lineStrokeWidth,
453 pointFillColor, pointStrokeColor, pointSize );
454}
455
456QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyle(
457 const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
458 const QColor &lineStrokeColor, double lineStrokeWidth,
459 const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize )
460{
461 QgsSimpleFillSymbolLayer *fillSymbolLayer = new QgsSimpleFillSymbolLayer();
462 fillSymbolLayer->setFillColor( polygonFillColor );
463 fillSymbolLayer->setStrokeColor( polygonStrokeColor );
464 fillSymbolLayer->setStrokeWidth( polygonStrokeWidth );
465 QgsFillSymbol *fillSymbol = new QgsFillSymbol( QgsSymbolLayerList() << fillSymbolLayer );
466
468 lineSymbolLayer->setColor( lineStrokeColor );
469 lineSymbolLayer->setWidth( lineStrokeWidth );
470 QgsLineSymbol *lineSymbol = new QgsLineSymbol( QgsSymbolLayerList() << lineSymbolLayer );
471
473 markerSymbolLayer->setFillColor( pointFillColor );
474 markerSymbolLayer->setStrokeColor( pointStrokeColor );
475 markerSymbolLayer->setSize( pointSize );
476 QgsMarkerSymbol *markerSymbol = new QgsMarkerSymbol( QgsSymbolLayerList() << markerSymbolLayer );
477
478 QgsVectorTileBasicRendererStyle st1( QStringLiteral( "Polygons" ), QString(), Qgis::GeometryType::Polygon );
479 st1.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Polygon'" ) );
480 st1.setSymbol( fillSymbol );
481
482 QgsVectorTileBasicRendererStyle st2( QStringLiteral( "Lines" ), QString(), Qgis::GeometryType::Line );
483 st2.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Line'" ) );
484 st2.setSymbol( lineSymbol );
485
486 QgsVectorTileBasicRendererStyle st3( QStringLiteral( "Points" ), QString(), Qgis::GeometryType::Point );
487 st3.setFilterExpression( QStringLiteral( "geometry_type(@geometry)='Point'" ) );
488 st3.setSymbol( markerSymbol );
489
490 QList<QgsVectorTileBasicRendererStyle> lst;
491 lst << st1 << st2 << st3;
492 return lst;
493}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Polygon
Polygons.
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.
Class for 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:58
QgsFields fields
Definition qgsfeature.h:68
QgsGeometry geometry
Definition qgsfeature.h:69
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.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
double width() const
Returns the width of the rectangle.
double height() const
Returns the height of the rectangle.
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 an 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.
Range of tiles in a tile matrix to be rendered.
Definition qgstiles.h:99
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.
The default vector tile renderer implementation.
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...
const double DEFAULT_LINE_WIDTH
Definition qgis.h:6450
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition qgis.h:6449
QMap< QString, QgsSymbol * > QgsSymbolMap
Definition qgsrenderer.h:48
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)