27 elem.setAttribute( QStringLiteral(
"name" ), mStyleName );
28 elem.setAttribute( QStringLiteral(
"layer" ), mLayerName );
29 elem.setAttribute( QStringLiteral(
"geometry" ),
static_cast<int>( mGeometryType ) );
30 elem.setAttribute( QStringLiteral(
"enabled" ), mEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
31 elem.setAttribute( QStringLiteral(
"expression" ), mExpression );
32 elem.setAttribute( QStringLiteral(
"min-zoom" ), mMinZoomLevel );
33 elem.setAttribute( QStringLiteral(
"max-zoom" ), mMaxZoomLevel );
35 QDomDocument doc = elem.ownerDocument();
36 QDomElement elemLabelSettings = mLabelSettings.
writeXml( doc, context );
37 elem.appendChild( elemLabelSettings );
42 mStyleName = elem.attribute( QStringLiteral(
"name" ) );
43 mLayerName = elem.attribute( QStringLiteral(
"layer" ) );
44 mGeometryType =
static_cast<Qgis::GeometryType>( elem.attribute( QStringLiteral(
"geometry" ) ).toInt() );
45 mEnabled = elem.attribute( QStringLiteral(
"enabled" ) ).toInt();
46 mExpression = elem.attribute( QStringLiteral(
"expression" ) );
47 mMinZoomLevel = elem.attribute( QStringLiteral(
"min-zoom" ) ).toInt();
48 mMaxZoomLevel = elem.attribute( QStringLiteral(
"max-zoom" ) ).toInt();
50 QDomElement elemLabelSettings = elem.firstChildElement( QStringLiteral(
"settings" ) );
51 mLabelSettings.
readXml( elemLabelSettings, context );
64 return QStringLiteral(
"basic" );
81 QDomDocument doc = elem.ownerDocument();
82 QDomElement elemStyles = doc.createElement( QStringLiteral(
"styles" ) );
85 QDomElement elemStyle = doc.createElement( QStringLiteral(
"style" ) );
86 layerStyle.writeXml( elemStyle, context );
87 elemStyles.appendChild( elemStyle );
89 elem.appendChild( elemStyles );
96 QDomElement elemStyles = elem.firstChildElement( QStringLiteral(
"styles" ) );
97 QDomElement elemStyle = elemStyles.firstChildElement( QStringLiteral(
"style" ) );
98 while ( !elemStyle.isNull() )
101 layerStyle.
readXml( elemStyle, context );
102 mStyles.append( layerStyle );
103 elemStyle = elemStyle.nextSiblingElement( QStringLiteral(
"style" ) );
116 for (
int i = 0; i < mStyles.count(); ++i )
128 QMap<QString, QSet<QString> > requiredFields;
131 if ( !layerStyle.isActive( tileZoom ) )
134 if ( !layerStyle.filterExpression().isEmpty() )
140 requiredFields[layerStyle.layerName()].unite( layerStyle.labelSettings().referencedFields( context ) );
142 return requiredFields;
150 if ( layerStyle.isActive( tileZoom ) )
152 res.insert( layerStyle.layerName() );
165 QList<QgsAbstractLabelProvider *> lst;
177 provider->setEngine(
mEngine );
180 for (
int i = 0; i < mSubProviders.count(); ++i )
188 mSubProviders[i]->setFields( fields );
191 if ( !mSubProviders[i]->
prepare( context, attributeNames ) )
193 QgsDebugError( QStringLiteral(
"Failed to prepare labeling for style index" ) + QString::number( i ) );
194 mSubProviders[i] =
nullptr;
205 for (
int i = 0; i < mStyles.count(); ++i )
208 if ( !layerStyle.
isActive( zoomLevel ) )
227 for (
const auto &features : tileData )
245 const QgsRectangle boundingBox = f.geometry().boundingBox();
246 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
252 else if ( tileData.contains( layerStyle.
layerName() ) )
271 const QgsRectangle boundingBox = f.geometry().boundingBox();
272 centroid.setGeometry( f.geometry().poleOfInaccessibility( std::min( boundingBox.
width(), boundingBox.
height() ) / 20 ) );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
const QgsLabelingEngine * mEngine
Associated labeling engine.
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
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.
QStringList names() const
Returns a list with field names.
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.
QString fieldName
Name of field (or an expression) to use for label text.
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.
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
QgsPalLayerSettings mSettings
Layer's labeling configuration.
friend class QgsVectorTileBasicLabelProvider
virtual QList< QgsLabelFeature * > 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.
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.
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)
Qgis::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
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.
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...
#define QgsDebugError(str)
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map)