28 elem.setAttribute( QStringLiteral(
"name" ), mStyleName );
29 elem.setAttribute( QStringLiteral(
"layer" ), mLayerName );
30 elem.setAttribute( QStringLiteral(
"geometry" ), mGeometryType );
31 elem.setAttribute( QStringLiteral(
"enabled" ), mEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
32 elem.setAttribute( QStringLiteral(
"expression" ), mExpression );
33 elem.setAttribute( QStringLiteral(
"min-zoom" ), mMinZoomLevel );
34 elem.setAttribute( QStringLiteral(
"max-zoom" ), mMaxZoomLevel );
36 QDomDocument doc = elem.ownerDocument();
37 QDomElement elemLabelSettings = mLabelSettings.
writeXml( doc, context );
38 elem.appendChild( elemLabelSettings );
43 mStyleName = elem.attribute( QStringLiteral(
"name" ) );
44 mLayerName = elem.attribute( QStringLiteral(
"layer" ) );
46 mEnabled = elem.attribute( QStringLiteral(
"enabled" ) ).toInt();
47 mExpression = elem.attribute( QStringLiteral(
"expression" ) );
48 mMinZoomLevel = elem.attribute( QStringLiteral(
"min-zoom" ) ).toInt();
49 mMaxZoomLevel = elem.attribute( QStringLiteral(
"max-zoom" ) ).toInt();
51 QDomElement elemLabelSettings = elem.firstChildElement( QStringLiteral(
"settings" ) );
52 mLabelSettings.
readXml( elemLabelSettings, context );
65 return QStringLiteral(
"basic" );
82 QDomDocument doc = elem.ownerDocument();
83 QDomElement elemStyles = doc.createElement( QStringLiteral(
"styles" ) );
86 QDomElement elemStyle = doc.createElement( QStringLiteral(
"style" ) );
87 layerStyle.writeXml( elemStyle, context );
88 elemStyles.appendChild( elemStyle );
90 elem.appendChild( elemStyles );
97 QDomElement elemStyles = elem.firstChildElement( QStringLiteral(
"styles" ) );
98 QDomElement elemStyle = elemStyles.firstChildElement( QStringLiteral(
"style" ) );
99 while ( !elemStyle.isNull() )
102 layerStyle.
readXml( elemStyle, context );
103 mStyles.append( layerStyle );
104 elemStyle = elemStyle.nextSiblingElement( QStringLiteral(
"style" ) );
117 for (
int i = 0; i < mStyles.count(); ++i )
129 QMap<QString, QSet<QString> > requiredFields;
132 if ( !layerStyle.isActive( tileZoom ) )
135 if ( !layerStyle.filterExpression().isEmpty() )
141 requiredFields[layerStyle.layerName()].unite( layerStyle.labelSettings().referencedFields( context ) );
143 return requiredFields;
151 if ( layerStyle.isActive( tileZoom ) )
153 res.insert( layerStyle.layerName() );
166 QList<QgsAbstractLabelProvider *> lst;
178 provider->setEngine(
mEngine );
181 for (
int i = 0; i < mSubProviders.count(); ++i )
189 mSubProviders[i]->setFields( fields );
190 if ( !mSubProviders[i]->
prepare( context, attributeNames ) )
192 QgsDebugMsg( QStringLiteral(
"Failed to prepare labeling for style index" ) + QString::number( i ) );
193 mSubProviders[i] =
nullptr;
204 for (
int i = 0; i < mStyles.count(); ++i )
207 if ( !layerStyle.
isActive( zoomLevel ) )
226 for ( QString layerName : tileData.keys() )
228 for (
const QgsFeature &f : tileData[layerName] )
239 else if ( tileData.contains( layerStyle.
layerName() ) )
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
const QgsLabelingEngine * mEngine
Associated labeling engine.
QString providerId() const
Returns provider ID - useful in case there is more than one label provider within a layer (e....
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...
Container of fields for a vector layer.
QgsCoordinateReferenceSystem crs
Contains settings for how a map layer will be labeled.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
The class is used as a container of context for various read/write operations on other objects.
Contains information about the context of a rendering operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
int zoomLevel() const
Returns tile's zoom level (Z)
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
QgsVectorLayerLabelProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings, const QString &layerName=QString())
Convenience constructor to initialize the provider from given vector layer.
virtual void registerFeature(const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
Implementation class for QgsVectorTileBasicLabeling.
QMap< QString, QgsFields > mPerLayerFields
Names of required fields for each sub-layer (only valid between startRender/stopRender calls)
bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames) override
Prepare for registration of features.
void setFields(const QMap< QString, QgsFields > &perLayerFields) override
Sets fields for each sub-layer.
QgsVectorTileBasicLabelProvider(QgsVectorTileLayer *layer, const QList< QgsVectorTileBasicLabelingStyle > &styles)
Constructs a label provider for the given vector tile layer and using styling from QgsVectorTileBasic...
void registerTileFeatures(const QgsVectorTileRendererData &tile, QgsRenderContext &context) override
Registers label features for given tile to the labeling engine.
QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &context, int tileZoom) const override
Returns field names for each sub-layer that are required for labeling.
QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const override
Returns a list of the layers required for labeling.
QList< QgsAbstractLabelProvider * > subProviders() override
Returns list of child providers - useful if the provider needs to put labels into more layers with di...
Configuration of a single style within QgsVectorTileBasicLabeling.
QgsPalLayerSettings labelSettings() const
Returns labeling configuration of this style.
QString layerName() const
Returns name of the sub-layer to render (empty layer means that all layers match)
QString filterExpression() const
Returns filter expression (empty filter means that all features match)
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes object content to given DOM element.
QgsWkbTypes::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads object content from given DOM element.
bool isActive(int zoomLevel) const
Returns whether the style is active at given zoom level (also checks "enabled" flag)
Basic labeling configuration for vector tile layers.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads labeling properties from given XML element.
QgsVectorTileLabelProvider * provider(QgsVectorTileLayer *layer) const override SIP_SKIP
Factory for label provider implementation.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes labeling properties to given XML element.
QgsVectorTileLabeling * clone() const override SIP_FACTORY
Returns a new copy of the object.
QString type() const override
Unique type string of the labeling configuration implementation.
QgsVectorTileBasicLabeling()
Internal base class for implementation of label providers for vector tile labeling.
Base class for labeling configuration classes for vector tile layers.
Implements a map layer that is dedicated to rendering of vector tiles.
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
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) SIP_HOLDGIL
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.
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map)