31using namespace Qt::StringLiterals;
34 : mStyleName( stName )
35 , mLayerName( laName )
36 , mGeometryType( geomType )
50 mStyleName = other.mStyleName;
51 mLayerName = other.mLayerName;
52 mGeometryType = other.mGeometryType;
53 mSymbol.reset( other.mSymbol ? other.mSymbol->clone() :
nullptr );
54 mEnabled = other.mEnabled;
55 mExpression = other.mExpression;
56 mMinZoomLevel = other.mMinZoomLevel;
57 mMaxZoomLevel = other.mMaxZoomLevel;
70 elem.setAttribute( u
"name"_s, mStyleName );
71 elem.setAttribute( u
"layer"_s, mLayerName );
72 elem.setAttribute( u
"geometry"_s,
static_cast<int>( mGeometryType ) );
73 elem.setAttribute( u
"enabled"_s, mEnabled ? u
"1"_s : u
"0"_s );
74 elem.setAttribute( u
"expression"_s, mExpression );
75 elem.setAttribute( u
"min-zoom"_s, mMinZoomLevel );
76 elem.setAttribute( u
"max-zoom"_s, mMaxZoomLevel );
78 QDomDocument doc = elem.ownerDocument();
80 symbols[u
"0"_s] = mSymbol.get();
82 elem.appendChild( symbolsElem );
87 mStyleName = elem.attribute( u
"name"_s );
88 mLayerName = elem.attribute( u
"layer"_s );
89 mGeometryType =
static_cast<Qgis::GeometryType>( elem.attribute( u
"geometry"_s ).toInt() );
90 mEnabled = elem.attribute( u
"enabled"_s ).toInt();
91 mExpression = elem.attribute( u
"expression"_s );
92 mMinZoomLevel = elem.attribute( u
"min-zoom"_s ).toInt();
93 mMaxZoomLevel = elem.attribute( u
"max-zoom"_s ).toInt();
96 QDomElement symbolsElem = elem.firstChildElement( u
"symbols"_s );
97 if ( !symbolsElem.isNull() )
100 if ( symbolMap.contains( u
"0"_s ) )
102 mSymbol.reset( symbolMap.take( u
"0"_s ) );
122 r->mStyles = mStyles;
130 Q_UNUSED( tileRange )
134 if ( layerStyle.isActive( tileZoom ) )
136 if ( !layerStyle.filterExpression().isEmpty() )
141 if (
auto *lSymbol = layerStyle.symbol() )
143 mRequiredFields[layerStyle.layerName()].unite( lSymbol->usedAttributes( context ) );
151 return mRequiredFields;
159 if ( layerStyle.isActive( tileZoom ) )
161 res.insert( layerStyle.layerName() );
176 if ( !layerStyle.symbol() || layerStyle.layerName() !=
"background"_L1 )
179 if ( layerStyle.isEnabled() )
188 polygon << QPoint( 0, 0 );
189 polygon << QPoint( 0, context.
outputSize().height() );
191 polygon << QPoint( context.
outputSize().width(), 0 );
192 fillSym->
renderPolygon( polygon,
nullptr,
nullptr, context );
207 if ( !layerStyle.isActive( zoomLevel ) || !layerStyle.symbol() || layerStyle.layerName() ==
"background"_L1 )
214 QgsExpression filterExpression( layerStyle.filterExpression() );
219 if ( layerStyle.layerName().isEmpty() )
222 for (
const auto &features : tileData )
231 if ( featureType == layerStyle.geometryType() )
248 const QgsRectangle boundingBox = f.geometry().boundingBox();
249 centroid.
setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
255 else if ( tileData.contains( layerStyle.layerName() ) )
258 for (
const QgsFeature &f : tileData[layerStyle.layerName()] )
265 if ( featureType == layerStyle.geometryType() )
282 const QgsRectangle boundingBox = f.geometry().boundingBox();
283 centroid.
setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
300 int featureTileZoom = feature.attribute( u
"tile_zoom"_s ).toInt( &ok );
302 featureTileZoom = -1;
303 const QString featureTileLayer = feature.attribute( u
"tile_layer"_s ).toString();
307 if ( ( featureTileZoom >= 0 && !layerStyle.isActive( featureTileZoom ) )
308 || !layerStyle.symbol() || layerStyle.layerName() ==
"background"_L1 )
311 if ( !layerStyle.layerName().isEmpty() && !featureTileLayer.isEmpty() && layerStyle.layerName() != featureTileLayer )
316 QgsExpression filterExpression( layerStyle.filterExpression() );
327 bool renderedFeature =
false;
328 if ( featureType == layerStyle.geometryType() )
331 renderedFeature =
true;
340 renderedFeature =
true;
347 const QgsRectangle boundingBox = feature.geometry().boundingBox();
348 centroid.
setGeometry( feature.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
350 renderedFeature =
true;
354 if ( renderedFeature )
369 if ( !layerStyle.isActive( tileZoom ) || !layerStyle.symbol() )
372 if ( layerStyle.layerName() ==
"background"_L1 )
375 if ( !layerStyle.layerName().isEmpty() && layerStyle.layerName() != layerName )
378 QgsExpression filterExpression( layerStyle.filterExpression() );
385 if ( featureType == layerStyle.geometryType() )
407 QDomDocument doc = elem.ownerDocument();
408 QDomElement elemStyles = doc.createElement( u
"styles"_s );
411 QDomElement elemStyle = doc.createElement( u
"style"_s );
412 layerStyle.writeXml( elemStyle, context );
413 elemStyles.appendChild( elemStyle );
415 elem.appendChild( elemStyles );
422 QDomElement elemStyles = elem.firstChildElement( u
"styles"_s );
423 QDomElement elemStyle = elemStyles.firstChildElement( u
"style"_s );
424 while ( !elemStyle.isNull() )
427 layerStyle.
readXml( elemStyle, context );
428 mStyles.append( layerStyle );
429 elemStyle = elemStyle.nextSiblingElement( u
"style"_s );
446 QColor polygonStrokeColor = polygonFillColor;
447 polygonFillColor.setAlpha( 100 );
454 QColor pointStrokeColor = pointFillColor;
455 pointFillColor.setAlpha( 100 );
458 return simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
459 lineStrokeColor, lineStrokeWidth,
460 pointFillColor, pointStrokeColor, pointSize );
464 const QColor &polygonFillColor,
const QColor &polygonStrokeColor,
double polygonStrokeWidth,
465 const QColor &lineStrokeColor,
double lineStrokeWidth,
466 const QColor &pointFillColor,
const QColor &pointStrokeColor,
double pointSize )
475 lineSymbolLayer->
setColor( lineStrokeColor );
476 lineSymbolLayer->
setWidth( lineStrokeWidth );
482 markerSymbolLayer->
setSize( pointSize );
497 QList<QgsVectorTileBasicRendererStyle> lst;
498 lst << st1 << st2 << st3;
static const double DEFAULT_LINE_WIDTH
The default width (in millimeters) for line symbols.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
static const double DEFAULT_POINT_SIZE
The default size (in millimeters) for point marker symbols.
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...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
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.
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 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.
~QgsVectorTileBasicRendererStyle()
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
QList< QgsSymbolLayer * > QgsSymbolLayerList
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map).