Skip to content

Commit

Permalink
Add support for labeling of vector tile layers
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk authored and nyalldawson committed Apr 14, 2020
1 parent b40b3fe commit f8a6b9f
Show file tree
Hide file tree
Showing 26 changed files with 998 additions and 14 deletions.
7 changes: 7 additions & 0 deletions python/core/auto_generated/labeling/qgspallabeling.sip.in
Expand Up @@ -319,6 +319,13 @@ The parameter ``attributeNames`` should be updated to contain all the field
names which the labeling requires for the rendering.

.. versionadded:: 3.8
%End

QSet<QString> referencedFields() const;
%Docstring
Returns all field names referenced by the configuration (e.g. field name or expression, data defined properties).

.. versionadded:: 3.14
%End

void startRender( QgsRenderContext &context );
Expand Down
8 changes: 7 additions & 1 deletion python/core/auto_generated/qgsproperty.sip.in
Expand Up @@ -307,10 +307,16 @@ property multiple times allows precalculation of expensive setup tasks such as p
Returns ``True`` if preparation was successful.
%End

QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext() ) const;
QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext(), bool ignoreContext = false ) const;
%Docstring
Returns the set of any fields referenced by the property for a specified
expression context.

.. note::

The optional argument ignoreContext has been added in QGIS 3.14. When set to true,
even fields not set in context's fields() will be reported - this is useful e.g. with vector tiles
where the actual available field names may not be known beforehand.
%End

bool isProjectColor() const;
Expand Down
12 changes: 9 additions & 3 deletions python/core/auto_generated/qgspropertycollection.sip.in
Expand Up @@ -233,11 +233,17 @@ collection's properties multiple times allows precalculation of expensive setup
Returns ``True`` if preparation was successful.
%End

virtual QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext() ) const = 0;
virtual QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext(), bool ignoreContext = false ) const = 0;
%Docstring
Returns the set of any fields referenced by the active properties from the collection.

:param context: expression context the properties will be evaluated against.

.. note::

The optional argument ignoreContext has been added in QGIS 3.14. When set to true,
even fields not set in context's fields() will be reported - this is useful e.g. with vector tiles
where the actual available field names may not be known beforehand.
%End

virtual bool isActive( int key ) const = 0;
Expand Down Expand Up @@ -376,7 +382,7 @@ Returns a reference to a matching property from the collection, if one exists.

virtual bool prepare( const QgsExpressionContext &context = QgsExpressionContext() ) const;

virtual QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext() ) const;
virtual QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext(), bool ignoreContext = false ) const;

virtual bool isActive( int key ) const;

Expand Down Expand Up @@ -538,7 +544,7 @@ Returns the calculated value of the highest priority property with the specified
:return: calculated property value, or default value if property could not be evaluated
%End

virtual QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext() ) const;
virtual QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext(), bool ignoreContext = false ) const;

%Docstring
Returns the set of any fields referenced by the active properties from the stack.
Expand Down
@@ -0,0 +1,161 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/vectortile/qgsvectortilebasiclabeling.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsVectorTileBasicLabelingStyle
{
%Docstring
Configuration of a single style within QgsVectorTileBasicLabeling

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsvectortilebasiclabeling.h"
%End
public:

void setLabelSettings( const QgsPalLayerSettings &settings );
%Docstring
Sets labeling configuration of this style
%End
QgsPalLayerSettings labelSettings() const;
%Docstring
Returns labeling configuration of this style
%End

void setStyleName( const QString &name );
%Docstring
Sets human readable name of this style
%End
QString styleName() const;
%Docstring
Returns human readable name of this style
%End

void setLayerName( const QString &name );
%Docstring
Sets name of the sub-layer to render (empty layer means that all layers match)
%End
QString layerName() const;
%Docstring
Returns name of the sub-layer to render (empty layer means that all layers match)
%End

void setGeometryType( QgsWkbTypes::GeometryType geomType );
%Docstring
Sets type of the geometry that will be used (point / line / polygon)
%End
QgsWkbTypes::GeometryType geometryType() const;
%Docstring
Returns type of the geometry that will be used (point / line / polygon)
%End

void setFilterExpression( const QString &expr );
%Docstring
Sets filter expression (empty filter means that all features match)
%End
QString filterExpression() const;
%Docstring
Returns filter expression (empty filter means that all features match)
%End

void setEnabled( bool enabled );
%Docstring
Sets whether this style is enabled (used for rendering)
%End
bool isEnabled() const;
%Docstring
Returns whether this style is enabled (used for rendering)
%End

void setMinZoomLevel( int minZoom );
%Docstring
Sets minimum zoom level index (negative number means no limit)
%End
int minZoomLevel() const;
%Docstring
Returns minimum zoom level index (negative number means no limit)
%End

void setMaxZoomLevel( int maxZoom );
%Docstring
Sets maximum zoom level index (negative number means no limit)
%End
int maxZoomLevel() const;
%Docstring
Returns maxnimum zoom level index (negative number means no limit)
%End

bool isActive( int zoomLevel ) const;
%Docstring
Returns whether the style is active at given zoom level (also checks "enabled" flag)
%End

void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;
%Docstring
Writes object content to given DOM element
%End
void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
%Docstring
Reads object content from given DOM element
%End

};


class QgsVectorTileBasicLabeling : QgsVectorTileLabeling
{
%Docstring
Basic labeling configuration for vector tile layers. It contains a definition
of a list of labeling styles, where each labeling style is a combination of
sub-layer name, geometry type, filter expression, zoom range and label settings.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsvectortilebasiclabeling.h"
%End
public:
QgsVectorTileBasicLabeling();

virtual QString type() const;

virtual QgsVectorTileLabeling *clone() const;

virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const;

virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context );


void setStyles( const QList<QgsVectorTileBasicLabelingStyle> &styles );
%Docstring
Sets list of styles of the renderer
%End
QList<QgsVectorTileBasicLabelingStyle> styles() const;
%Docstring
Returns list of styles of the renderer
%End

};




/************************************************************************
* This file has been generated automatically from *
* *
* src/core/vectortile/qgsvectortilebasiclabeling.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
69 changes: 69 additions & 0 deletions python/core/auto_generated/vectortile/qgsvectortilelabeling.sip.in
@@ -0,0 +1,69 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/vectortile/qgsvectortilelabeling.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsVectorTileLabeling
{
%Docstring
Base class for labeling configuration classes for vector tile layers.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsvectortilelabeling.h"
%End
%ConvertToSubClassCode

const QString type = sipCpp->type();

if ( type == QStringLiteral( "basic" ) )
sipType = sipType_QgsVectorTileBasicLabeling;
else
sipType = 0;
%End
public:
virtual ~QgsVectorTileLabeling();

virtual QString type() const = 0;
%Docstring
Unique type string of the labeling configuration implementation
%End

virtual QgsVectorTileLabeling *clone() const = 0 /Factory/;
%Docstring
Returns a new copy of the object
%End


virtual void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const = 0;
%Docstring
Writes labeling properties to given XML element
%End
virtual void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) = 0;
%Docstring
Reads labeling properties from given XML element
%End
virtual void resolveReferences( const QgsProject &project );
%Docstring
Resolves references to other objects - second phase of loading - after readXml()
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/vectortile/qgsvectortilelabeling.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
13 changes: 13 additions & 0 deletions python/core/auto_generated/vectortile/qgsvectortilelayer.sip.in
Expand Up @@ -123,6 +123,19 @@ Sets renderer for the map layer.
QgsVectorTileRenderer *renderer() const;
%Docstring
Returns currently assigned renderer
%End

void setLabeling( QgsVectorTileLabeling *labeling /Transfer/ );
%Docstring
Sets labeling for the map layer.

.. note::

Takes ownership of the passed labeling
%End
QgsVectorTileLabeling *labeling() const;
%Docstring
Returns currently assigned labeling
%End

void setTileBorderRenderingEnabled( bool enabled );
Expand Down
2 changes: 2 additions & 0 deletions python/core/core_auto.sip
Expand Up @@ -542,7 +542,9 @@
%Include auto_generated/validity/qgsabstractvaliditycheck.sip
%Include auto_generated/validity/qgsvaliditycheckcontext.sip
%Include auto_generated/validity/qgsvaliditycheckregistry.sip
%Include auto_generated/vectortile/qgsvectortilebasiclabeling.sip
%Include auto_generated/vectortile/qgsvectortilebasicrenderer.sip
%Include auto_generated/vectortile/qgsvectortilelabeling.sip
%Include auto_generated/vectortile/qgsvectortilelayer.sip
%Include auto_generated/vectortile/qgsvectortilerenderer.sip
%Include auto_generated/gps/qgsqtlocationconnection.sip
Expand Down
4 changes: 4 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -648,9 +648,11 @@ SET(QGIS_CORE_SRCS
validity/qgsvaliditycheckcontext.cpp
validity/qgsvaliditycheckregistry.cpp

vectortile/qgsvectortilebasiclabeling.cpp
vectortile/qgsvectortilebasicrenderer.cpp
vectortile/qgsvectortileconnection.cpp
vectortile/qgsvectortiledataitems.cpp
vectortile/qgsvectortilelabeling.cpp
vectortile/qgsvectortilelayer.cpp
vectortile/qgsvectortilelayerrenderer.cpp
vectortile/qgsvectortileloader.cpp
Expand Down Expand Up @@ -1357,9 +1359,11 @@ SET(QGIS_CORE_HDRS
validity/qgsvaliditycheckcontext.h
validity/qgsvaliditycheckregistry.h

vectortile/qgsvectortilebasiclabeling.h
vectortile/qgsvectortilebasicrenderer.h
vectortile/qgsvectortileconnection.h
vectortile/qgsvectortiledataitems.h
vectortile/qgsvectortilelabeling.h
vectortile/qgsvectortilelayer.h
vectortile/qgsvectortilelayerrenderer.h
vectortile/qgsvectortileloader.h
Expand Down
19 changes: 19 additions & 0 deletions src/core/labeling/qgspallabeling.cpp
Expand Up @@ -483,6 +483,25 @@ bool QgsPalLayerSettings::prepare( QgsRenderContext &context, QSet<QString> &att
return true;
}

QSet<QString> QgsPalLayerSettings::referencedFields() const
{
QSet<QString> referenced;
if ( drawLabels )
{
if ( isExpression )
{
referenced.unite( QgsExpression( fieldName ).referencedColumns() );
}
else
{
referenced.insert( fieldName );
}
}

referenced.unite( mDataDefinedProperties.referencedFields( QgsExpressionContext(), true ) );
return referenced;
}

void QgsPalLayerSettings::startRender( QgsRenderContext &context )
{
if ( mRenderStarted )
Expand Down
6 changes: 6 additions & 0 deletions src/core/labeling/qgspallabeling.h
Expand Up @@ -475,6 +475,12 @@ class CORE_EXPORT QgsPalLayerSettings
*/
bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames SIP_INOUT, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs );

/**
* Returns all field names referenced by the configuration (e.g. field name or expression, data defined properties).
* \since QGIS 3.14
*/
QSet<QString> referencedFields() const;

/**
* Prepares the label settings for rendering.
*
Expand Down

0 comments on commit f8a6b9f

Please sign in to comment.