Skip to content

Commit

Permalink
Merge pull request #6813 from m-kuhn/constrenderers
Browse files Browse the repository at this point in the history
Const correctness for feature renderers
  • Loading branch information
m-kuhn committed Apr 20, 2018
2 parents 7d78798 + f2de572 commit eb7f755
Show file tree
Hide file tree
Showing 33 changed files with 294 additions and 251 deletions.
4 changes: 2 additions & 2 deletions python/core/symbology/qgs25drenderer.sip.in
Expand Up @@ -37,9 +37,9 @@ Create a new 2.5D renderer from XML
virtual QgsFeatureRenderer *clone() const /Factory/;


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

virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;


QColor roofColor() const;
Expand Down
12 changes: 6 additions & 6 deletions python/core/symbology/qgscategorizedsymbolrenderer.sip.in
Expand Up @@ -83,9 +83,9 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer

QgsCategorizedSymbolRenderer( const QString &attrName = QString(), const QgsCategoryList &categories = QgsCategoryList() );

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

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

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

Expand All @@ -102,7 +102,7 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer
virtual QgsFeatureRenderer::Capabilities capabilities();
virtual QString filter( const QgsFields &fields = QgsFields() );

virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;


void updateSymbols( QgsSymbol *sym );
Expand Down Expand Up @@ -163,7 +163,7 @@ create renderer from XML element

virtual QgsLegendSymbolList legendSymbolItems() const;

virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;


QgsSymbol *sourceSymbol();
Expand Down Expand Up @@ -273,15 +273,15 @@ hashtable for faster access to symbols
.. deprecated:: No longer used, will be removed in QGIS 4.0
%End

QgsSymbol *symbolForValue( const QVariant &value ) /Deprecated/;
QgsSymbol *symbolForValue( const QVariant &value ) const /Deprecated/;
%Docstring
Returns the matching symbol corresponding to an attribute ``value``.

.. deprecated:: use variant which takes a second bool argument instead.
%End


QgsSymbol *symbolForValue( const QVariant &value, bool &foundMatchingSymbol /Out/ ) /PyName=symbolForValue2/;
QgsSymbol *symbolForValue( const QVariant &value, bool &foundMatchingSymbol /Out/ ) const /PyName=symbolForValue2/;
%Docstring
Returns the matching symbol corresponding to an attribute ``value``.

Expand Down
12 changes: 6 additions & 6 deletions python/core/symbology/qgsgraduatedsymbolrenderer.sip.in
Expand Up @@ -120,9 +120,9 @@ class QgsGraduatedSymbolRenderer : QgsFeatureRenderer

~QgsGraduatedSymbolRenderer();

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

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

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

Expand All @@ -137,7 +137,7 @@ class QgsGraduatedSymbolRenderer : QgsFeatureRenderer
virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const;

virtual QgsFeatureRenderer::Capabilities capabilities();
virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;


QString classAttribute() const;
Expand Down Expand Up @@ -292,7 +292,7 @@ create renderer from XML element

virtual QgsLegendSymbolList legendSymbolItems() const;

virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;


QgsSymbol *sourceSymbol();
Expand Down Expand Up @@ -440,9 +440,9 @@ Will return null if the functionality is disabled.



QgsSymbol *symbolForValue( double value );
QgsSymbol *symbolForValue( double value ) const;
%Docstring
attribute index (derived from attribute name in startRender)
Get the symbol which is used to represent ``value``.
%End

QString legendKeyForValue( double value ) const;
Expand Down
6 changes: 3 additions & 3 deletions python/core/symbology/qgsheatmaprenderer.sip.in
Expand Up @@ -29,19 +29,19 @@ class QgsHeatmapRenderer : QgsFeatureRenderer

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

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

virtual void stopRender( QgsRenderContext &context );

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

%Docstring

.. note::

symbolForFeature2 in Python bindings
%End
virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;

%Docstring

Expand Down
14 changes: 7 additions & 7 deletions python/core/symbology/qgsinvertedpolygonrenderer.sip.in
Expand Up @@ -46,7 +46,7 @@ Direct copies are forbidden. Use clone() instead.
virtual void startRender( QgsRenderContext &context, const QgsFields &fields );


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

%Docstring
Renders a given feature.
Expand Down Expand Up @@ -82,31 +82,31 @@ Proxy that will call this method on the embedded renderer.
Proxy that will call this method on the embedded renderer.
%End

virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;

%Docstring
Proxy that will call this method on the embedded renderer.
%End

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

%Docstring
Proxy that will call this method on the embedded renderer.
%End

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

%Docstring
Proxy that will call this method on the embedded renderer.
%End

virtual QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

%Docstring
Proxy that will call this method on the embedded renderer.
%End

virtual QgsSymbolList originalSymbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

%Docstring
Proxy that will call this method on the embedded renderer.
Expand All @@ -118,7 +118,7 @@ Proxy that will call this method on the embedded renderer.
Proxy that will call this method on the embedded renderer.
%End

virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

%Docstring
Proxy that will call this method on the embedded renderer.
Expand Down
10 changes: 5 additions & 5 deletions python/core/symbology/qgsnullsymbolrenderer.sip.in
Expand Up @@ -24,16 +24,16 @@ and diagrams for the layer. Selected features will also be drawn with a default

QgsNullSymbolRenderer();

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

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


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

virtual void stopRender( QgsRenderContext &context );

virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;


virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const;
Expand All @@ -42,7 +42,7 @@ and diagrams for the layer. Selected features will also be drawn with a default

virtual QgsFeatureRenderer *clone() const /Factory/;

virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;


static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) /Factory/;
Expand Down
16 changes: 8 additions & 8 deletions python/core/symbology/qgspointdistancerenderer.sip.in
Expand Up @@ -65,25 +65,25 @@ Constructor for QgsPointDistanceRenderer.

virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props = QgsStringMap() ) const;

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

virtual QSet<QString> usedAttributes( const QgsRenderContext &context ) const;

virtual QgsFeatureRenderer::Capabilities capabilities();

virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;

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

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

virtual QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QgsSymbolList originalSymbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;

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

Expand Down
47 changes: 28 additions & 19 deletions python/core/symbology/qgsrenderer.sip.in
Expand Up @@ -43,25 +43,28 @@ class QgsFeatureRenderer
#include "qgsrenderer.h"
%End
%ConvertToSubClassCode
if ( sipCpp->type() == "singleSymbol" )

const QString type = sipCpp->type();

if ( type == QStringLiteral( "singleSymbol" ) )
sipType = sipType_QgsSingleSymbolRenderer;
else if ( sipCpp->type() == "categorizedSymbol" )
else if ( type == QStringLiteral( "categorizedSymbol" ) )
sipType = sipType_QgsCategorizedSymbolRenderer;
else if ( sipCpp->type() == "graduatedSymbol" )
else if ( type == QStringLiteral( "graduatedSymbol" ) )
sipType = sipType_QgsGraduatedSymbolRenderer;
else if ( sipCpp->type() == "RuleRenderer" )
else if ( type == QStringLiteral( "RuleRenderer" ) )
sipType = sipType_QgsRuleBasedRenderer;
else if ( sipCpp->type() == "heatmapRenderer" )
else if ( type == QStringLiteral( "heatmapRenderer" ) )
sipType = sipType_QgsHeatmapRenderer;
else if ( sipCpp->type() == "invertedPolygonRenderer" )
else if ( type == QStringLiteral( "invertedPolygonRenderer" ) )
sipType = sipType_QgsInvertedPolygonRenderer;
else if ( sipCpp->type() == "pointCluster" )
else if ( type == QStringLiteral( "pointCluster" ) )
sipType = sipType_QgsPointClusterRenderer;
else if ( sipCpp->type() == "pointDisplacement" )
else if ( type == QStringLiteral( "pointDisplacement" ) )
sipType = sipType_QgsPointDisplacementRenderer;
else if ( sipCpp->type() == "25dRenderer" )
else if ( type == QStringLiteral( "25dRenderer" ) )
sipType = sipType_Qgs25DRenderer;
else if ( sipCpp->type() == "nullSymbol" )
else if ( type == QStringLiteral( "nullSymbol" ) )
sipType = sipType_QgsNullSymbolRenderer;
else
sipType = 0;
Expand All @@ -75,7 +78,7 @@ return a new renderer - used by default in vector layers

QString type() const;

virtual QgsSymbol *symbolForFeature( QgsFeature &feature, QgsRenderContext &context ) = 0;
virtual QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const = 0;
%Docstring
To be overridden

Expand All @@ -89,7 +92,7 @@ Must be called between startRender() and stopRender() calls.
.. versionadded:: 2.12
%End

virtual QgsSymbol *originalSymbolForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
%Docstring
Return symbol for feature. The difference compared to symbolForFeature() is that it returns original
symbol which can be used as an identifier for renderer's rule - the former may return a temporary replacement
Expand All @@ -98,7 +101,7 @@ of a symbol for use in rendering.
.. versionadded:: 2.12
%End

virtual QSet< QString > legendKeysForFeature( QgsFeature &feature, QgsRenderContext &context );
virtual QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
%Docstring
Return legend keys matching a specified feature.

Expand Down Expand Up @@ -172,7 +175,7 @@ and generate a proper subclass.
:return: A copy of this renderer
%End

virtual bool renderFeature( QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
virtual bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
%Docstring
Render a feature using this renderer in the given context.
Must be called between startRender() and stopRender() calls.
Expand Down Expand Up @@ -218,7 +221,7 @@ E.g. if you only want to deal with visible features:
skip_the_curren_feature()
%End

virtual QgsSymbolList symbols( QgsRenderContext &context );
virtual QgsSymbolList symbols( QgsRenderContext &context ) const;
%Docstring
Returns list of symbols used by the renderer.

Expand Down Expand Up @@ -317,7 +320,7 @@ If supported by the renderer, return classification attribute for the use in leg
set type and size of editing vertex markers for subsequent rendering
%End

virtual bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context );
virtual bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
%Docstring
Returns whether the renderer will render a feature or not.
Must be called between startRender() and stopRender() calls.
Expand All @@ -326,7 +329,7 @@ Default implementation uses symbolForFeature().
.. versionadded:: 2.12
%End

virtual QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
virtual QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
%Docstring
Returns list of symbols used for rendering the feature.
For renderers that do not support MoreSymbolsPerFeature it is more efficient
Expand All @@ -335,7 +338,7 @@ to use symbolForFeature()
.. versionadded:: 2.12
%End

virtual QgsSymbolList originalSymbolsForFeature( QgsFeature &feat, QgsRenderContext &context );
virtual QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const;
%Docstring
Equivalent of originalSymbolsForFeature() call
extended to support renderers that may use more symbols per feature - similar to symbolsForFeature()
Expand Down Expand Up @@ -473,12 +476,18 @@ implementation does not use subrenderers and will always return null.
protected:
QgsFeatureRenderer( const QString &type );

void renderFeatureWithSymbol( QgsFeature &feature,
void renderFeatureWithSymbol( const QgsFeature &feature,
QgsSymbol *symbol,
QgsRenderContext &context,
int layer,
bool selected,
bool drawVertexMarker );
%Docstring
Render the ``feature`` with the ``symbol`` using ``context``.
Use ``layer`` to specify the symbol layer, ``selected`` to
specify if it should be rendered as selected and ``drawVertexMarker``
to specify if vertex markers should be rendered.
%End

void renderVertexMarker( QPointF pt, QgsRenderContext &context );
%Docstring
Expand Down

0 comments on commit eb7f755

Please sign in to comment.