QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
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;
153 QList<QgsAbstractLabelProvider *> lst;
165 provider->setEngine(
mEngine );
168 for (
int i = 0; i < mSubProviders.count(); ++i )
176 mSubProviders[i]->setFields( fields );
177 if ( !mSubProviders[i]->
prepare( context, attributeNames ) )
179 QgsDebugMsg( QStringLiteral(
"Failed to prepare labeling for style index" ) + QString::number( i ) );
180 mSubProviders[i] =
nullptr;
191 for (
int i = 0; i < mStyles.count(); ++i )
194 if ( !layerStyle.
isActive( zoomLevel ) )
213 for ( QString layerName : tileData.keys() )
215 for (
const QgsFeature &f : tileData[layerName] )
226 else if ( tileData.contains( layerStyle.
layerName() ) )
QgsCoordinateReferenceSystem crs
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the scope.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QgsExpressionContext & expressionContext()
Gets the expression context.
bool isActive(int zoomLevel) const
Returns whether the style is active at given zoom level (also checks "enabled" flag)
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
void registerTileFeatures(const QgsVectorTileRendererData &tile, QgsRenderContext &context) override
Registers label features for given tile to the labeling engine.
QgsVectorTileBasicLabeling()
bool isValid() const
Checks if this expression is valid.
QString type() const override
Unique type string of the labeling configuration implementation.
QgsWkbTypes::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the scope.
The QgsVectorLayerLabelProvider class implements a label provider for vector layers....
QString filterExpression() const
Returns filter expression (empty filter means that all features match)
QgsTileXYZ id() const
Returns coordinates of the tile.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads labeling properties from given XML element.
QList< QgsAbstractLabelProvider * > subProviders() override
Returns list of child providers - useful if the provider needs to put labels into more layers with di...
QgsVectorTileBasicLabelProvider(QgsVectorTileLayer *layer, const QList< QgsVectorTileBasicLabelingStyle > &styles)
Constructs a label provider for the given vector tile layer and using styling from QgsVectorTileBasic...
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Reads object content from given DOM element.
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
void setFields(const QMap< QString, QgsFields > &perLayerFields) override
Sets fields for each sub-layer.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
int zoomLevel() const
Returns tile's zoom level (Z)
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....
QVariant evaluate()
Evaluate the feature and return the result.
QMap< QString, QgsFields > mPerLayerFields
Names of required fields for each sub-layer (only valid between startRender/stopRender calls)
Single scope for storing variables and functions for use within a QgsExpressionContext....
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QgsVectorTileLabelProvider * provider(QgsVectorTileLayer *layer) const override SIP_SKIP
Factory for label provider implementation.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes labeling properties to given XML element.
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.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const
Writes object content to given DOM element.
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
QgsPalLayerSettings labelSettings() const
Returns labeling configuration of this style.
QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &context, int tileZoom) const override
Returns field names for each sub-layer that are required for labeling.
QgsVectorTileFeatures features() const
Returns features of the tile grouped by sub-layer names.
QMap< QString, QVector< QgsFeature > > QgsVectorTileFeatures
Features of a vector tile, grouped by sub-layer names (key of the map)
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.
QgsVectorTileLabeling * clone() const override SIP_FACTORY
Returns a new copy of the object.
bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames) override
Prepare for registration of features.
QString layerName() const
Returns name of the sub-layer to render (empty layer means that all layers match)