QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
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;
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() ) )
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.
RAII class to pop scope from an expression context on destruction.
Implements a map layer that is dedicated to rendering of vector tiles.
QSet< QString > requiredLayers(QgsRenderContext &context, int tileZoom) const override
Returns a list of the layers required for labeling.
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)
The class is used as a container of context for various read/write operations on other objects.
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()
Configuration of a single style within QgsVectorTileBasicLabeling.
Container of fields for a vector layer.
Internal base class for implementation of label providers for vector tile labeling.
bool isValid() const
Checks if this expression is valid.
QString type() const override
Unique type string of the labeling configuration implementation.
Contains information about the context of a rendering operation.
Basic labeling configuration for vector tile layers.
QgsWkbTypes::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
Contains decoded features of a single vector tile and any other data necessary for rendering of it.
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.
Implementation class for QgsVectorTileBasicLabeling.
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.
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.
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...
Base class for labeling configuration classes for vector tile layers.
QgsPalLayerSettings labelSettings() const
Returns labeling configuration of this style.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
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.
Class for parsing and evaluation of expressions (formerly called "search strings").
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)