QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsvectortilebasiclabeling.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortilebasiclabeling.h
3  --------------------------------------
4  Date : April 2020
5  Copyright : (C) 2020 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVECTORTILEBASICLABELING_H
17 #define QGSVECTORTILEBASICLABELING_H
18 
19 
20 #include "qgsvectortilelabeling.h"
21 
22 
24 
32 {
33  public:
34 
36  void setLabelSettings( const QgsPalLayerSettings &settings ) { mLabelSettings = settings; }
38  QgsPalLayerSettings labelSettings() const { return mLabelSettings; }
39 
41  void setStyleName( const QString &name ) { mStyleName = name; }
43  QString styleName() const { return mStyleName; }
44 
46  void setLayerName( const QString &name ) { mLayerName = name; }
48  QString layerName() const { return mLayerName; }
49 
51  void setGeometryType( QgsWkbTypes::GeometryType geomType ) { mGeometryType = geomType; }
53  QgsWkbTypes::GeometryType geometryType() const { return mGeometryType; }
54 
56  void setFilterExpression( const QString &expr ) { mExpression = expr; }
58  QString filterExpression() const { return mExpression; }
59 
61  void setEnabled( bool enabled ) { mEnabled = enabled; }
63  bool isEnabled() const { return mEnabled; }
64 
66  void setMinZoomLevel( int minZoom ) { mMinZoomLevel = minZoom; }
68  int minZoomLevel() const { return mMinZoomLevel; }
69 
71  void setMaxZoomLevel( int maxZoom ) { mMaxZoomLevel = maxZoom; }
73  int maxZoomLevel() const { return mMaxZoomLevel; }
74 
76  bool isActive( int zoomLevel ) const
77  {
78  return mEnabled && ( mMinZoomLevel == -1 || zoomLevel >= mMinZoomLevel ) && ( mMaxZoomLevel == -1 || zoomLevel <= mMaxZoomLevel );
79  }
80 
82  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
84  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
85 
86  private:
87  QString mStyleName;
88  QString mLayerName;
89  QgsWkbTypes::GeometryType mGeometryType;
90  bool mEnabled = true;
91  QString mExpression;
92  int mMinZoomLevel = -1;
93  int mMaxZoomLevel = -1;
94 
95  QgsPalLayerSettings mLabelSettings;
96 };
97 
98 
108 {
109  public:
111 
112  QString type() const override;
113  QgsVectorTileLabeling *clone() const override SIP_FACTORY;
115  void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
116  void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;
117 
119  void setStyles( const QList<QgsVectorTileBasicLabelingStyle> &styles ) { mStyles = styles; }
121  QList<QgsVectorTileBasicLabelingStyle> styles() const { return mStyles; }
123  void setStyle( int index, const QgsVectorTileBasicLabelingStyle &style ) { mStyles[index] = style; }
125  QgsVectorTileBasicLabelingStyle style( int index ) const { return mStyles[index]; }
126 
127  private:
129  QList<QgsVectorTileBasicLabelingStyle> mStyles;
130 };
131 
132 
133 #ifndef SIP_RUN
134 
142 {
143  public:
145  QgsVectorTileBasicLabelProvider( QgsVectorTileLayer *layer, const QList<QgsVectorTileBasicLabelingStyle> &styles );
146 
147  QList<QgsAbstractLabelProvider *> subProviders() override;
148  bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames ) override;
149 
150  // virtual functions from QgsVectorTileLabelProvider
151  void registerTileFeatures( const QgsVectorTileRendererData &tile, QgsRenderContext &context ) override;
152  QMap<QString, QSet<QString> > usedAttributes( const QgsRenderContext &context, int tileZoom ) const override;
153  void setFields( const QMap<QString, QgsFields> &perLayerFields ) override;
154 
155  private:
156  QList<QgsVectorTileBasicLabelingStyle> mStyles;
157 
159  QList<QgsVectorLayerLabelProvider *> mSubProviders;
160 
161  public:
163  QMap<QString, QgsFields> mPerLayerFields;
164 };
165 
167 #endif
168 
169 
170 #endif // QGSVECTORTILEBASICLABELING_H
QgsVectorTileBasicLabelingStyle::setGeometryType
void setGeometryType(QgsWkbTypes::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon)
Definition: qgsvectortilebasiclabeling.h:51
QgsVectorTileLayer
Definition: qgsvectortilelayer.h:83
QgsVectorTileBasicLabelingStyle::isActive
bool isActive(int zoomLevel) const
Returns whether the style is active at given zoom level (also checks "enabled" flag)
Definition: qgsvectortilebasiclabeling.h:76
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsVectorTileBasicLabelProvider::registerTileFeatures
void registerTileFeatures(const QgsVectorTileRendererData &tile, QgsRenderContext &context) override
Registers label features for given tile to the labeling engine.
Definition: qgsvectortilebasiclabeling.cpp:186
QgsVectorTileBasicLabelingStyle::setLabelSettings
void setLabelSettings(const QgsPalLayerSettings &settings)
Sets labeling configuration of this style.
Definition: qgsvectortilebasiclabeling.h:36
QgsPalLayerSettings
Definition: qgspallabeling.h:205
qgsvectortilelabeling.h
QgsVectorTileBasicLabelingStyle
Definition: qgsvectortilebasiclabeling.h:31
QgsVectorTileLabelProvider
Definition: qgsvectortilelabeling.h:33
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsVectorTileBasicLabeling
Definition: qgsvectortilebasiclabeling.h:107
QgsVectorTileBasicLabelingStyle::geometryType
QgsWkbTypes::GeometryType geometryType() const
Returns type of the geometry that will be used (point / line / polygon)
Definition: qgsvectortilebasiclabeling.h:53
QgsVectorTileRendererData
Definition: qgsvectortilerenderer.h:37
QgsVectorTileBasicLabelingStyle::setMaxZoomLevel
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit)
Definition: qgsvectortilebasiclabeling.h:71
QgsVectorTileBasicLabeling::setStyle
void setStyle(int index, const QgsVectorTileBasicLabelingStyle &style)
Updates style definition at the paricular index of the list (the index must be in interval [0,...
Definition: qgsvectortilebasiclabeling.h:123
QgsVectorTileBasicLabelingStyle::filterExpression
QString filterExpression() const
Returns filter expression (empty filter means that all features match)
Definition: qgsvectortilebasiclabeling.h:58
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsVectorTileLabeling::provider
virtual QgsVectorTileLabelProvider * provider(QgsVectorTileLayer *layer) const SIP_SKIP
Factory for label provider implementation.
Definition: qgsvectortilelabeling.h:85
QgsVectorTileBasicLabelProvider
Definition: qgsvectortilebasiclabeling.h:141
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsVectorTileBasicLabelingStyle::setEnabled
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering)
Definition: qgsvectortilebasiclabeling.h:61
QgsVectorTileBasicLabelingStyle::setLayerName
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match)
Definition: qgsvectortilebasiclabeling.h:46
QgsVectorTileBasicLabelingStyle::maxZoomLevel
int maxZoomLevel() const
Returns maxnimum zoom level index (negative number means no limit)
Definition: qgsvectortilebasiclabeling.h:73
QgsVectorTileBasicLabelingStyle::styleName
QString styleName() const
Returns human readable name of this style.
Definition: qgsvectortilebasiclabeling.h:43
QgsVectorTileBasicLabelProvider::subProviders
QList< QgsAbstractLabelProvider * > subProviders() override
Returns list of child providers - useful if the provider needs to put labels into more layers with di...
Definition: qgsvectortilebasiclabeling.cpp:151
QgsVectorTileBasicLabelProvider::QgsVectorTileBasicLabelProvider
QgsVectorTileBasicLabelProvider(QgsVectorTileLayer *layer, const QList< QgsVectorTileBasicLabelingStyle > &styles)
Constructs a label provider for the given vector tile layer and using styling from QgsVectorTileBasic...
Definition: qgsvectortilebasiclabeling.cpp:112
QgsVectorTileBasicLabelingStyle::isEnabled
bool isEnabled() const
Returns whether this style is enabled (used for rendering)
Definition: qgsvectortilebasiclabeling.h:63
QgsVectorTileBasicLabeling::style
QgsVectorTileBasicLabelingStyle style(int index) const
Returns style definition at the particular index.
Definition: qgsvectortilebasiclabeling.h:125
QgsVectorTileBasicLabelProvider::setFields
void setFields(const QMap< QString, QgsFields > &perLayerFields) override
Sets fields for each sub-layer.
Definition: qgsvectortilebasiclabeling.cpp:146
QgsVectorTileLabeling::clone
virtual QgsVectorTileLabeling * clone() const =0SIP_FACTORY
Returns a new copy of the object.
QgsVectorTileBasicLabelProvider::mPerLayerFields
QMap< QString, QgsFields > mPerLayerFields
Names of required fields for each sub-layer (only valid between startRender/stopRender calls)
Definition: qgsvectortilebasiclabeling.h:163
QgsVectorTileBasicLabelingStyle::setStyleName
void setStyleName(const QString &name)
Sets human readable name of this style.
Definition: qgsvectortilebasiclabeling.h:41
QgsVectorTileBasicLabelingStyle::setFilterExpression
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match)
Definition: qgsvectortilebasiclabeling.h:56
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
QgsVectorTileLabeling::type
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
QgsAbstractLabelProvider::layer
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
Definition: qgslabelingengine.h:130
QgsVectorTileBasicLabeling::styles
QList< QgsVectorTileBasicLabelingStyle > styles() const
Returns list of styles of the renderer.
Definition: qgsvectortilebasiclabeling.h:121
QgsVectorTileLabeling
Definition: qgsvectortilelabeling.h:57
QgsVectorTileBasicLabelingStyle::labelSettings
QgsPalLayerSettings labelSettings() const
Returns labeling configuration of this style.
Definition: qgsvectortilebasiclabeling.h:38
QgsVectorTileBasicLabelProvider::usedAttributes
QMap< QString, QSet< QString > > usedAttributes(const QgsRenderContext &context, int tileZoom) const override
Returns field names for each sub-layer that are required for labeling.
Definition: qgsvectortilebasiclabeling.cpp:127
QgsVectorTileBasicLabelingStyle::setMinZoomLevel
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit)
Definition: qgsvectortilebasiclabeling.h:66
QgsVectorTileBasicLabelProvider::prepare
bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames) override
Prepare for registration of features.
Definition: qgsvectortilebasiclabeling.cpp:162
QgsVectorTileLabeling::readXml
virtual void readXml(const QDomElement &elem, const QgsReadWriteContext &context)=0
Reads labeling properties from given XML element.
QgsVectorTileBasicLabelingStyle::minZoomLevel
int minZoomLevel() const
Returns minimum zoom level index (negative number means no limit)
Definition: qgsvectortilebasiclabeling.h:68
QgsVectorTileBasicLabelingStyle::layerName
QString layerName() const
Returns name of the sub-layer to render (empty layer means that all layers match)
Definition: qgsvectortilebasiclabeling.h:48
QgsVectorTileLabeling::writeXml
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes labeling properties to given XML element.
QgsVectorTileBasicLabeling::setStyles
void setStyles(const QList< QgsVectorTileBasicLabelingStyle > &styles)
Sets list of styles of the renderer.
Definition: qgsvectortilebasiclabeling.h:119