30 : mStyleName( stName )
31 , mLayerName( laName )
32 , mGeometryType( geomType )
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;
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 );
71 QDomDocument doc = elem.ownerDocument();
73 symbols[QStringLiteral(
"0" )] = mSymbol.get();
75 elem.appendChild( symbolsElem );
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();
89 QDomElement symbolsElem = elem.firstChildElement( QStringLiteral(
"symbols" ) );
90 if ( !symbolsElem.isNull() )
93 if ( symbolMap.contains( QStringLiteral(
"0" ) ) )
95 mSymbol.reset( symbolMap.take( QStringLiteral(
"0" ) ) );
109 return QStringLiteral(
"basic" );
115 r->mStyles = mStyles;
123 Q_UNUSED( tileRange )
127 if ( layerStyle.isActive( tileZoom ) )
129 if ( !layerStyle.filterExpression().isEmpty() )
134 if (
auto *lSymbol = layerStyle.symbol() )
136 mRequiredFields[layerStyle.layerName()].unite( lSymbol->usedAttributes( context ) );
144 return mRequiredFields;
152 if ( layerStyle.isActive( tileZoom ) )
154 res.insert( layerStyle.layerName() );
169 if ( !layerStyle.symbol() || layerStyle.layerName() != QLatin1String(
"background" ) )
172 if ( layerStyle.isEnabled() )
181 polygon << QPoint( 0, 0 );
182 polygon << QPoint( 0, context.
outputSize().height() );
184 polygon << QPoint( context.
outputSize().width(), 0 );
185 fillSym->
renderPolygon( polygon,
nullptr,
nullptr, context );
200 if ( !layerStyle.isActive( zoomLevel ) || !layerStyle.symbol() || layerStyle.layerName() == QLatin1String(
"background" ) )
207 QgsExpression filterExpression( layerStyle.filterExpression() );
212 if ( layerStyle.layerName().isEmpty() )
215 for (
const auto &features : tileData )
224 if ( featureType == layerStyle.geometryType() )
241 const QgsRectangle boundingBox = f.geometry().boundingBox();
242 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
248 else if ( tileData.contains( layerStyle.layerName() ) )
251 for (
const QgsFeature &f : tileData[layerStyle.layerName()] )
258 if ( featureType == layerStyle.geometryType() )
275 const QgsRectangle boundingBox = f.geometry().boundingBox();
276 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
293 int featureTileZoom = feature.attribute( QStringLiteral(
"tile_zoom" ) ).toInt( &ok );
295 featureTileZoom = -1;
296 const QString featureTileLayer = feature.attribute( QStringLiteral(
"tile_layer" ) ).toString();
300 if ( ( featureTileZoom >= 0 && !layerStyle.isActive( featureTileZoom ) )
301 || !layerStyle.symbol() || layerStyle.layerName() == QLatin1String(
"background" ) )
304 if ( !layerStyle.layerName().isEmpty() && !featureTileLayer.isEmpty() && layerStyle.layerName() != featureTileLayer )
309 QgsExpression filterExpression( layerStyle.filterExpression() );
320 bool renderedFeature =
false;
321 if ( featureType == layerStyle.geometryType() )
324 renderedFeature =
true;
333 renderedFeature =
true;
340 const QgsRectangle boundingBox = feature.geometry().boundingBox();
341 centroid.setGeometry( feature.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
343 renderedFeature =
true;
347 if ( renderedFeature )
362 if ( !layerStyle.isActive( tileZoom ) || !layerStyle.symbol() )
365 if ( layerStyle.layerName() == QLatin1String(
"background" ) )
368 if ( !layerStyle.layerName().isEmpty() && layerStyle.layerName() != layerName )
371 QgsExpression filterExpression( layerStyle.filterExpression() );
378 if ( featureType == layerStyle.geometryType() )
400 QDomDocument doc = elem.ownerDocument();
401 QDomElement elemStyles = doc.createElement( QStringLiteral(
"styles" ) );
404 QDomElement elemStyle = doc.createElement( QStringLiteral(
"style" ) );
405 layerStyle.writeXml( elemStyle, context );
406 elemStyles.appendChild( elemStyle );
408 elem.appendChild( elemStyles );
415 QDomElement elemStyles = elem.firstChildElement( QStringLiteral(
"styles" ) );
416 QDomElement elemStyle = elemStyles.firstChildElement( QStringLiteral(
"style" ) );
417 while ( !elemStyle.isNull() )
420 layerStyle.
readXml( elemStyle, context );
421 mStyles.append( layerStyle );
422 elemStyle = elemStyle.nextSiblingElement( QStringLiteral(
"style" ) );
439 QColor polygonStrokeColor = polygonFillColor;
440 polygonFillColor.setAlpha( 100 );
447 QColor pointStrokeColor = pointFillColor;
448 pointFillColor.setAlpha( 100 );
451 return simpleStyle( polygonFillColor, polygonStrokeColor, polygonStrokeWidth,
452 lineStrokeColor, lineStrokeWidth,
453 pointFillColor, pointStrokeColor, pointSize );
457 const QColor &polygonFillColor,
const QColor &polygonStrokeColor,
double polygonStrokeWidth,
458 const QColor &lineStrokeColor,
double lineStrokeWidth,
459 const QColor &pointFillColor,
const QColor &pointStrokeColor,
double pointSize )
468 lineSymbolLayer->
setColor( lineStrokeColor );
469 lineSymbolLayer->
setWidth( lineStrokeWidth );
475 markerSymbolLayer->
setSize( pointSize );
490 QList<QgsVectorTileBasicRendererStyle> lst;
491 lst << st1 << st2 << st3;
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
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...
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.
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.
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 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.
The default vector tile renderer implementation.
void renderTile(const QgsVectorTileRendererData &tile, QgsRenderContext &context) override
Renders given vector tile. Must be called between startRender/stopRender.
QList< QgsVectorTileBasicRendererStyle > styles() const
Returns list of styles of the renderer.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads renderer's properties from given XML element.
QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &) override
Returns field names of sub-layers that will be used for rendering. Must be called between startRender...
QgsVectorTileBasicRenderer()
Constructs renderer with no styles.
void renderSelectedFeatures(const QList< QgsFeature > &selection, QgsRenderContext &context) override
Renders the specified features in a selected state.
void setStyles(const QList< QgsVectorTileBasicRendererStyle > &styles)
Sets list of styles of the renderer.
void startRender(QgsRenderContext &context, int tileZoom, const QgsTileRange &tileRange) override
Initializes rendering. It should be paired with a stopRender() call.
QString type() const override
Returns unique type name of the renderer implementation.
static QList< QgsVectorTileBasicRendererStyle > simpleStyle(const QColor &polygonFillColor, const QColor &polygonStrokeColor, double polygonStrokeWidth, const QColor &lineStrokeColor, double lineStrokeWidth, const QColor &pointFillColor, const QColor &pointStrokeColor, double pointSize)
Returns a list of styles to render all layers with the given fill/stroke colors, stroke widths and ma...
bool willRenderFeature(const QgsFeature &feature, int tileZoom, const QString &layerName, QgsRenderContext &context) override
Returns true if the specified feature will be rendered in the given render context.
QgsVectorTileBasicRenderer * clone() const override
Returns a clone of the renderer.
static QList< QgsVectorTileBasicRendererStyle > simpleStyleWithRandomColors()
Returns a list of styles to render all layers, using random colors.
QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const override
Returns a list of the layers required for rendering.
void renderBackground(QgsRenderContext &context) override
Renders the background if defined.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes renderer's properties to given XML element.
void stopRender(QgsRenderContext &context) override
Finishes rendering and cleans up any resources.
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
QMap< QString, QgsFields > fields() const
Returns per-layer fields.
QgsVectorTileFeatures features() const
Returns features of the tile grouped by sub-layer names.
int renderZoomLevel() const
Returns the zoom level corresponding to the target render.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
const double DEFAULT_LINE_WIDTH
const double DEFAULT_POINT_SIZE
Magic number that determines the default point size for point symbols.
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)