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