Skip to content

Commit

Permalink
Add API to determine if feature renderer affects labeling results
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 14, 2024
1 parent beda21c commit c50c923
Show file tree
Hide file tree
Showing 46 changed files with 288 additions and 4 deletions.
24 changes: 24 additions & 0 deletions python/PyQt6/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1435,12 +1435,31 @@
# --
Qgis.SymbolRotationMode.baseClass = Qgis
# monkey patching scoped based enum
Qgis.FeatureRendererFlag.AffectsLabeling.__doc__ = "If present, indicates that the renderer will participate in the map labeling problem"
Qgis.FeatureRendererFlag.__doc__ = """Flags controlling behavior of vector feature renderers.

.. versionadded:: 3.40

* ``AffectsLabeling``: If present, indicates that the renderer will participate in the map labeling problem

"""
# --
Qgis.FeatureRendererFlag.baseClass = Qgis
Qgis.FeatureRendererFlags = lambda flags=0: Qgis.FeatureRendererFlag(flags)
Qgis.FeatureRendererFlags.baseClass = Qgis
FeatureRendererFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.SymbolFlag.RendererShouldUseSymbolLevels.__doc__ = "If present, indicates that a QgsFeatureRenderer using the symbol should use symbol levels for best results"
Qgis.SymbolFlag.AffectsLabeling.__doc__ = "If present, indicates that the symbol will participate in the map labeling problem \n.. versionadded:: 3.40"
Qgis.SymbolFlag.__doc__ = """Flags controlling behavior of symbols

.. versionadded:: 3.20

* ``RendererShouldUseSymbolLevels``: If present, indicates that a QgsFeatureRenderer using the symbol should use symbol levels for best results
* ``AffectsLabeling``: If present, indicates that the symbol will participate in the map labeling problem

.. versionadded:: 3.40


"""
# --
Expand Down Expand Up @@ -1469,6 +1488,7 @@
# monkey patching scoped based enum
Qgis.SymbolLayerFlag.DisableFeatureClipping.__doc__ = "If present, indicates that features should never be clipped to the map extent during rendering"
Qgis.SymbolLayerFlag.CanCalculateMaskGeometryPerFeature.__doc__ = "If present, indicates that mask geometry can safely be calculated per feature for the symbol layer. This avoids using the entire symbol layer's mask geometry for every feature rendered, considerably simplifying vector exports and resulting in much smaller file sizes. \n.. versionadded:: 3.38"
Qgis.SymbolLayerFlag.AffectsLabeling.__doc__ = "If present, indicates that the symbol layer will participate in the map labeling problem \n.. versionadded:: 3.40"
Qgis.SymbolLayerFlag.__doc__ = """Flags controlling behavior of symbol layers

.. note::
Expand All @@ -1484,6 +1504,10 @@

.. versionadded:: 3.38

* ``AffectsLabeling``: If present, indicates that the symbol layer will participate in the map labeling problem

.. versionadded:: 3.40


"""
# --
Expand Down
12 changes: 12 additions & 0 deletions python/PyQt6/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,18 @@ The development version
IgnoreMapRotation,
};

enum class FeatureRendererFlag /BaseType=IntFlag/
{
AffectsLabeling,
};

typedef QFlags<Qgis::FeatureRendererFlag> FeatureRendererFlags;


enum class SymbolFlag /BaseType=IntFlag/
{
RendererShouldUseSymbolLevels,
AffectsLabeling,
};
typedef QFlags<Qgis::SymbolFlag> SymbolFlags;

Expand All @@ -501,6 +510,7 @@ The development version
{
DisableFeatureClipping,
CanCalculateMaskGeometryPerFeature,
AffectsLabeling,
};
typedef QFlags<Qgis::SymbolLayerFlag> SymbolLayerFlags;

Expand Down Expand Up @@ -3227,6 +3237,8 @@ QFlags<Qgis::SublayerFlag> operator|(Qgis::SublayerFlag f1, QFlags<Qgis::Sublaye

QFlags<Qgis::SublayerQueryFlag> operator|(Qgis::SublayerQueryFlag f1, QFlags<Qgis::SublayerQueryFlag> f2);

QFlags<Qgis::FeatureRendererFlag> operator|(Qgis::FeatureRendererFlag f1, QFlags<Qgis::FeatureRendererFlag> f2);

QFlags<Qgis::SymbolFlag> operator|(Qgis::SymbolFlag f1, QFlags<Qgis::SymbolFlag> f2);

QFlags<Qgis::SymbolLayerFlag> operator|(Qgis::SymbolLayerFlag f1, QFlags<Qgis::SymbolLayerFlag> f2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Create a new 2.5D renderer from XML
%End
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );

virtual Qgis::FeatureRendererFlags flags() const;

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ can be added later by calling :py:func:`~QgsCategorizedSymbolRenderer.addCategor
%End
~QgsCategorizedSymbolRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ A vector feature renderer which uses numeric attributes to classify features int

~QgsGraduatedSymbolRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Creates a renderer out of an XML, for loading

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );

virtual Qgis::FeatureRendererFlags flags() const;


virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) throw( QgsCsException );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ A renderer that automatically clusters points with the same geographic position.

QgsPointClusterRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsPointClusterRenderer *clone() const /Factory/;

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Constructor for QgsPointDisplacementRenderer.
:param labelAttributeName: optional attribute name for labeling points
%End

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsPointDisplacementRenderer *clone() const /Factory/;

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
Expand Down
7 changes: 7 additions & 0 deletions python/PyQt6/core/auto_generated/symbology/qgsrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ E.g. if you only want to deal with visible features:
skip_the_curren_feature()
%End

virtual Qgis::FeatureRendererFlags flags() const;
%Docstring
Returns flags associated with the renderer.

.. versionadded:: 3.40
%End

virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
%Docstring
Returns list of symbols used by the renderer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ Constructor for convenience. Creates a root rule and adds a default rule with sy
Returns symbol for current feature. Should not be used individually: there could be more symbols for a feature
%End

virtual Qgis::FeatureRendererFlags flags() const;

virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) throw( QgsCsException );


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ of ``symbol`` is transferred to the renderer.
%End
~QgsSingleSymbolRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
Expand Down
23 changes: 23 additions & 0 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,12 +1418,30 @@
# --
Qgis.SymbolRotationMode.baseClass = Qgis
# monkey patching scoped based enum
Qgis.FeatureRendererFlag.AffectsLabeling.__doc__ = "If present, indicates that the renderer will participate in the map labeling problem"
Qgis.FeatureRendererFlag.__doc__ = """Flags controlling behavior of vector feature renderers.

.. versionadded:: 3.40

* ``AffectsLabeling``: If present, indicates that the renderer will participate in the map labeling problem

"""
# --
Qgis.FeatureRendererFlag.baseClass = Qgis
Qgis.FeatureRendererFlags.baseClass = Qgis
FeatureRendererFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.SymbolFlag.RendererShouldUseSymbolLevels.__doc__ = "If present, indicates that a QgsFeatureRenderer using the symbol should use symbol levels for best results"
Qgis.SymbolFlag.AffectsLabeling.__doc__ = "If present, indicates that the symbol will participate in the map labeling problem \n.. versionadded:: 3.40"
Qgis.SymbolFlag.__doc__ = """Flags controlling behavior of symbols

.. versionadded:: 3.20

* ``RendererShouldUseSymbolLevels``: If present, indicates that a QgsFeatureRenderer using the symbol should use symbol levels for best results
* ``AffectsLabeling``: If present, indicates that the symbol will participate in the map labeling problem

.. versionadded:: 3.40


"""
# --
Expand All @@ -1450,6 +1468,7 @@
# monkey patching scoped based enum
Qgis.SymbolLayerFlag.DisableFeatureClipping.__doc__ = "If present, indicates that features should never be clipped to the map extent during rendering"
Qgis.SymbolLayerFlag.CanCalculateMaskGeometryPerFeature.__doc__ = "If present, indicates that mask geometry can safely be calculated per feature for the symbol layer. This avoids using the entire symbol layer's mask geometry for every feature rendered, considerably simplifying vector exports and resulting in much smaller file sizes. \n.. versionadded:: 3.38"
Qgis.SymbolLayerFlag.AffectsLabeling.__doc__ = "If present, indicates that the symbol layer will participate in the map labeling problem \n.. versionadded:: 3.40"
Qgis.SymbolLayerFlag.__doc__ = """Flags controlling behavior of symbol layers

.. note::
Expand All @@ -1465,6 +1484,10 @@

.. versionadded:: 3.38

* ``AffectsLabeling``: If present, indicates that the symbol layer will participate in the map labeling problem

.. versionadded:: 3.40


"""
# --
Expand Down
12 changes: 12 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,18 @@ The development version
IgnoreMapRotation,
};

enum class FeatureRendererFlag
{
AffectsLabeling,
};

typedef QFlags<Qgis::FeatureRendererFlag> FeatureRendererFlags;


enum class SymbolFlag
{
RendererShouldUseSymbolLevels,
AffectsLabeling,
};
typedef QFlags<Qgis::SymbolFlag> SymbolFlags;

Expand All @@ -501,6 +510,7 @@ The development version
{
DisableFeatureClipping,
CanCalculateMaskGeometryPerFeature,
AffectsLabeling,
};
typedef QFlags<Qgis::SymbolLayerFlag> SymbolLayerFlags;

Expand Down Expand Up @@ -3227,6 +3237,8 @@ QFlags<Qgis::SublayerFlag> operator|(Qgis::SublayerFlag f1, QFlags<Qgis::Sublaye

QFlags<Qgis::SublayerQueryFlag> operator|(Qgis::SublayerQueryFlag f1, QFlags<Qgis::SublayerQueryFlag> f2);

QFlags<Qgis::FeatureRendererFlag> operator|(Qgis::FeatureRendererFlag f1, QFlags<Qgis::FeatureRendererFlag> f2);

QFlags<Qgis::SymbolFlag> operator|(Qgis::SymbolFlag f1, QFlags<Qgis::SymbolFlag> f2);

QFlags<Qgis::SymbolLayerFlag> operator|(Qgis::SymbolLayerFlag f1, QFlags<Qgis::SymbolLayerFlag> f2);
Expand Down
1 change: 1 addition & 0 deletions python/core/auto_generated/symbology/qgs25drenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Create a new 2.5D renderer from XML
%End
virtual QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context );

virtual Qgis::FeatureRendererFlags flags() const;

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ can be added later by calling :py:func:`~QgsCategorizedSymbolRenderer.addCategor
%End
~QgsCategorizedSymbolRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ A vector feature renderer which uses numeric attributes to classify features int

~QgsGraduatedSymbolRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Creates a renderer out of an XML, for loading

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );

virtual Qgis::FeatureRendererFlags flags() const;


virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) throw( QgsCsException );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ A renderer that automatically clusters points with the same geographic position.

QgsPointClusterRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsPointClusterRenderer *clone() const /Factory/;

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Constructor for QgsPointDisplacementRenderer.
:param labelAttributeName: optional attribute name for labeling points
%End

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsPointDisplacementRenderer *clone() const /Factory/;

virtual void startRender( QgsRenderContext &context, const QgsFields &fields );
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/symbology/qgsrenderer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ E.g. if you only want to deal with visible features:
skip_the_curren_feature()
%End

virtual Qgis::FeatureRendererFlags flags() const;
%Docstring
Returns flags associated with the renderer.

.. versionadded:: 3.40
%End

virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
%Docstring
Returns list of symbols used by the renderer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ Constructor for convenience. Creates a root rule and adds a default rule with sy
Returns symbol for current feature. Should not be used individually: there could be more symbols for a feature
%End

virtual Qgis::FeatureRendererFlags flags() const;

virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) throw( QgsCsException );


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ of ``symbol`` is transferred to the renderer.
%End
~QgsSingleSymbolRenderer();

virtual Qgis::FeatureRendererFlags flags() const;

virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
Expand Down
22 changes: 22 additions & 0 deletions src/core/qgis.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,25 @@ class CORE_EXPORT Qgis
};
Q_ENUM( SymbolRotationMode )

/**
* \brief Flags controlling behavior of vector feature renderers.
*
* \since QGIS 3.40
*/
enum class FeatureRendererFlag : int SIP_ENUM_BASETYPE( IntFlag )
{
AffectsLabeling = 1 << 0, //!< If present, indicates that the renderer will participate in the map labeling problem
};
Q_ENUM( FeatureRendererFlag )

/**
* \brief Flags controlling behavior of vector feature renderers.
*
* \since QGIS 3.40
*/
Q_DECLARE_FLAGS( FeatureRendererFlags, FeatureRendererFlag )
Q_FLAG( FeatureRendererFlags )

/**
* \brief Flags controlling behavior of symbols
*
Expand All @@ -761,6 +780,7 @@ class CORE_EXPORT Qgis
enum class SymbolFlag : int SIP_ENUM_BASETYPE( IntFlag )
{
RendererShouldUseSymbolLevels = 1 << 0, //!< If present, indicates that a QgsFeatureRenderer using the symbol should use symbol levels for best results
AffectsLabeling = 1 << 1, //!< If present, indicates that the symbol will participate in the map labeling problem \since QGIS 3.40
};
Q_ENUM( SymbolFlag )
//! Symbol flags
Expand Down Expand Up @@ -794,6 +814,7 @@ class CORE_EXPORT Qgis
{
DisableFeatureClipping = 1 << 0, //!< If present, indicates that features should never be clipped to the map extent during rendering
CanCalculateMaskGeometryPerFeature = 1 << 1, //!< If present, indicates that mask geometry can safely be calculated per feature for the symbol layer. This avoids using the entire symbol layer's mask geometry for every feature rendered, considerably simplifying vector exports and resulting in much smaller file sizes. \since QGIS 3.38
AffectsLabeling = 1 << 2, //!< If present, indicates that the symbol layer will participate in the map labeling problem \since QGIS 3.40
};
Q_ENUM( SymbolLayerFlag )
//! Symbol layer flags
Expand Down Expand Up @@ -5603,6 +5624,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SnappingTypes )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SqlLayerDefinitionCapabilities )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SublayerFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SublayerQueryFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::FeatureRendererFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SymbolFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SymbolLayerFlags )
Q_DECLARE_OPERATORS_FOR_FLAGS( Qgis::SymbolLayerUserFlags )
Expand Down
Loading

0 comments on commit c50c923

Please sign in to comment.