QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
37{
38 operator=( other );
39}
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
104{
105}
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 const QgsVectorTileFeatures tileData = tile.features();
168 int zoomLevel = tile.id().zoomLevel();
169
170 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
171 {
172 if ( !layerStyle.isActive( zoomLevel ) || !layerStyle.symbol() )
173 continue;
174
175 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
176 scope->setFields( tile.fields()[layerStyle.layerName()] );
177 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
178
179 QgsExpression filterExpression( layerStyle.filterExpression() );
180 filterExpression.prepare( &context.expressionContext() );
181
182 QgsSymbol *sym = layerStyle.symbol();
183 sym->startRender( context, QgsFields() );
184 if ( layerStyle.layerName() == QLatin1String( "background" ) )
185 {
186 QgsFillSymbol *fillSym = dynamic_cast<QgsFillSymbol *>( sym );
187 if ( fillSym )
188 fillSym->renderPolygon( tile.tilePolygon(), nullptr, nullptr, context );
189 }
190 else if ( layerStyle.layerName().isEmpty() )
191 {
192 // matching all layers
193 for ( const auto &features : tileData )
194 {
195 for ( const QgsFeature &f : features )
196 {
197 scope->setFeature( f );
198 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
199 continue;
200
201 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
202 if ( featureType == layerStyle.geometryType() )
203 {
204 sym->renderFeature( f, context );
205 }
206 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
207 {
208 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
209 // to render the polygon borders only
210 QgsFeature exterior = f;
211 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
212 sym->renderFeature( exterior, context );
213 }
214 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
215 {
216 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
217 // to render the polygon center
219 const QgsRectangle boundingBox = f.geometry().boundingBox();
220 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
221 sym->renderFeature( centroid, context );
222 }
223 }
224 }
225 }
226 else if ( tileData.contains( layerStyle.layerName() ) )
227 {
228 // matching one particular layer
229 for ( const QgsFeature &f : tileData[layerStyle.layerName()] )
230 {
231 scope->setFeature( f );
232 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
233 continue;
234
235 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( f.geometry().wkbType() );
236 if ( featureType == layerStyle.geometryType() )
237 {
238 sym->renderFeature( f, context );
239 }
240 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
241 {
242 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
243 // to render the polygon borders only
244 QgsFeature exterior = f;
245 exterior.setGeometry( QgsGeometry( f.geometry().constGet()->boundary() ) );
246 sym->renderFeature( exterior, context );
247 }
248 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
249 {
250 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
251 // to render the polygon center
253 const QgsRectangle boundingBox = f.geometry().boundingBox();
254 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
255 sym->renderFeature( centroid, context );
256 }
257 }
258 }
259 sym->stopRender( context );
260 }
261}
262
263void QgsVectorTileBasicRenderer::renderSelectedFeatures( const QList<QgsFeature> &selection, QgsRenderContext &context )
264{
265 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
266 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
267
268 for ( const QgsFeature &feature : selection )
269 {
270 bool ok = false;
271 int featureTileZoom = feature.attribute( QStringLiteral( "tile_zoom" ) ).toInt( &ok );
272 if ( !ok )
273 featureTileZoom = -1;
274 const QString featureTileLayer = feature.attribute( QStringLiteral( "tile_layer" ) ).toString();
275
276 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
277 {
278 if ( ( featureTileZoom >= 0 && !layerStyle.isActive( featureTileZoom ) )
279 || !layerStyle.symbol() || layerStyle.layerName() == QLatin1String( "background" ) )
280 continue;
281
282 if ( !layerStyle.layerName().isEmpty() && !featureTileLayer.isEmpty() && layerStyle.layerName() != featureTileLayer )
283 continue;
284
285 scope->setFields( feature.fields() );
286
287 QgsExpression filterExpression( layerStyle.filterExpression() );
288 filterExpression.prepare( &context.expressionContext() );
289
290 scope->setFeature( feature );
291 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
292 continue;
293
294 QgsSymbol *sym = layerStyle.symbol();
295 sym->startRender( context, feature.fields() );
296
297 const Qgis::GeometryType featureType = feature.geometry().type();
298 bool renderedFeature = false;
299 if ( featureType == layerStyle.geometryType() )
300 {
301 sym->renderFeature( feature, context, -1, true );
302 renderedFeature = true;
303 }
304 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
305 {
306 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
307 // to render the polygon borders only
308 QgsFeature exterior = feature;
309 exterior.setGeometry( QgsGeometry( feature.geometry().constGet()->boundary() ) );
310 sym->renderFeature( exterior, context, -1, true );
311 renderedFeature = true;
312 }
313 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
314 {
315 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
316 // to render the polygon center
317 QgsFeature centroid = feature;
318 const QgsRectangle boundingBox = feature.geometry().boundingBox();
319 centroid.setGeometry( feature.geometry().poleOfInaccessibility( std::min( boundingBox.width(), boundingBox.height() ) / 20 ) );
320 sym->renderFeature( centroid, context, -1, true );
321 renderedFeature = true;
322 }
323 sym->stopRender( context );
324
325 if ( renderedFeature )
326 break;
327 }
328 }
329}
330
331bool QgsVectorTileBasicRenderer::willRenderFeature( const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context )
332{
333 QgsExpressionContextScope *scope = new QgsExpressionContextScope( QObject::tr( "Layer" ) ); // will be deleted by popper
334 scope->setFields( feature.fields() );
335 scope->setFeature( feature );
336 QgsExpressionContextScopePopper popper( context.expressionContext(), scope );
337
338 for ( const QgsVectorTileBasicRendererStyle &layerStyle : std::as_const( mStyles ) )
339 {
340 if ( !layerStyle.isActive( tileZoom ) || !layerStyle.symbol() )
341 continue;
342
343 if ( layerStyle.layerName() == QLatin1String( "background" ) )
344 continue;
345
346 if ( !layerStyle.layerName().isEmpty() && layerStyle.layerName() != layerName )
347 continue;
348
349 QgsExpression filterExpression( layerStyle.filterExpression() );
350 filterExpression.prepare( &context.expressionContext() );
351
352 if ( filterExpression.isValid() && !filterExpression.evaluate( &context.expressionContext() ).toBool() )
353 continue;
354
355 const Qgis::GeometryType featureType = QgsWkbTypes::geometryType( feature.geometry().wkbType() );
356 if ( featureType == layerStyle.geometryType() )
357 {
358 return true;
359 }
360 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Line )
361 {
362 // be tolerant and permit rendering polygons with a line layer style, as some style definitions use this approach
363 // to render the polygon borders only
364 return true;
365 }
366 else if ( featureType == Qgis::GeometryType::Polygon && layerStyle.geometryType() == Qgis::GeometryType::Point )
367 {
368 // be tolerant and permit rendering polygons with a point layer style, as some style definitions use this approach
369 // to render the polygon center
370 return true;
371 }
372 }
373 return false;
374}
375
376void QgsVectorTileBasicRenderer::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
377{
378 QDomDocument doc = elem.ownerDocument();
379 QDomElement elemStyles = doc.createElement( QStringLiteral( "styles" ) );
380 for ( const QgsVectorTileBasicRendererStyle &layerStyle : mStyles )
381 {
382 QDomElement elemStyle = doc.createElement( QStringLiteral( "style" ) );
383 layerStyle.writeXml( elemStyle, context );
384 elemStyles.appendChild( elemStyle );
385 }
386 elem.appendChild( elemStyles );
387}
388
389void QgsVectorTileBasicRenderer::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
390{
391 mStyles.clear();
392
393 QDomElement elemStyles = elem.firstChildElement( QStringLiteral( "styles" ) );
394 QDomElement elemStyle = elemStyles.firstChildElement( QStringLiteral( "style" ) );
395 while ( !elemStyle.isNull() )
396 {
398 layerStyle.readXml( elemStyle, context );
399 mStyles.append( layerStyle );
400 elemStyle = elemStyle.nextSiblingElement( QStringLiteral( "style" ) );
401 }
402}
403
404void QgsVectorTileBasicRenderer::setStyles( const QList<QgsVectorTileBasicRendererStyle> &styles )
405{
406 mStyles = styles;
407}
408
409QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::styles() const
410{
411 return mStyles;
412}
413
414QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyleWithRandomColors()
415{
416 QColor polygonFillColor = QgsApplication::colorSchemeRegistry()->fetchRandomStyleColor();
417 QColor polygonStrokeColor = polygonFillColor;
418 polygonFillColor.setAlpha( 100 );
419 double polygonStrokeWidth = DEFAULT_LINE_WIDTH;
420
422 double lineStrokeWidth = DEFAULT_LINE_WIDTH;
423
425 QColor pointStrokeColor = pointFillColor;
426 pointFillColor.setAlpha( 100 );
427 double pointSize = DEFAULT_POINT_SIZE;
428
429 return simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
430 lineStrokeColor, lineStrokeWidth,
431 pointFillColor, pointStrokeColor, pointSize );
432}
433
434QList<QgsVectorTileBasicRendererStyle> QgsVectorTileBasicRenderer::simpleStyle(
435 const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth,
436 const QColor &lineStrokeColor, double lineStrokeWidth,
437 const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize )
438{
439 QgsSimpleFillSymbolLayer *fillSymbolLayer = new QgsSimpleFillSymbolLayer();
440 fillSymbolLayer->setFillColor( polygonFillColor );
441 fillSymbolLayer->setStrokeColor( polygonStrokeColor );
442 fillSymbolLayer->setStrokeWidth( polygonStrokeWidth );
443 QgsFillSymbol *fillSymbol = new QgsFillSymbol( QgsSymbolLayerList() << fillSymbolLayer );
444
446 lineSymbolLayer->setColor( lineStrokeColor );
447 lineSymbolLayer->setWidth( lineStrokeWidth );
448 QgsLineSymbol *lineSymbol = new QgsLineSymbol( QgsSymbolLayerList() << lineSymbolLayer );
449
451 markerSymbolLayer->setFillColor( pointFillColor );
452 markerSymbolLayer->setStrokeColor( pointStrokeColor );
453 markerSymbolLayer->setSize( pointSize );
454 QgsMarkerSymbol *markerSymbol = new QgsMarkerSymbol( QgsSymbolLayerList() << markerSymbolLayer );
455
456 QgsVectorTileBasicRendererStyle st1( QStringLiteral( "Polygons" ), QString(), Qgis::GeometryType::Polygon );
457 st1.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Polygon'" ) );
458 st1.setSymbol( fillSymbol );
459
460 QgsVectorTileBasicRendererStyle st2( QStringLiteral( "Lines" ), QString(), Qgis::GeometryType::Line );
461 st2.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Line'" ) );
462 st2.setSymbol( lineSymbol );
463
464 QgsVectorTileBasicRendererStyle st3( QStringLiteral( "Points" ), QString(), Qgis::GeometryType::Point );
465 st3.setFilterExpression( QStringLiteral( "geometry_type($geometry)='Point'" ) );
466 st3.setSymbol( markerSymbol );
467
468 QList<QgsVectorTileBasicRendererStyle> lst;
469 lst << st1 << st2 << st3;
470 return lst;
471}
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition: qgis.h:228
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.
Definition: qgsfeature.cpp:170
Container of fields for a vector layer.
Definition: qgsfields.h:45
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Definition: qgsfillsymbol.h:30
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.
Definition: qgsgeometry.h:164
Qgis::WkbType wkbType() const SIP_HOLDGIL
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.
Definition: qgslinesymbol.h:30
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.
Definition: qgsrectangle.h:42
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:230
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
Contains information about the context of a rendering operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
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 stopRender(QgsRenderContext &context)
Ends the rendering process.
Definition: qgssymbol.cpp:873
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) SIP_THROW(QgsCsException)
Render a feature.
Definition: qgssymbol.cpp:1284
void startRender(QgsRenderContext &context, const QgsFields &fields=QgsFields())
Begins the rendering process for the symbol.
Definition: qgssymbol.cpp:825
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.
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 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.
QPolygon tilePolygon() const
Returns polygon (made out of four corners of the tile) in screen coordinates calculated from render c...
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 Qgis::GeometryType geometryType(Qgis::WkbType type) SIP_HOLDGIL
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:865
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
const double DEFAULT_LINE_WIDTH
Definition: qgis.h:4049
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
Definition: qgis.h:4048
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)