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