Skip to content
Permalink
Browse files

Merge pull request #6813 from m-kuhn/constrenderers

Const correctness for feature renderers
  • Loading branch information
m-kuhn committed Apr 20, 2018
2 parents 7d78798 + f2de572 commit eb7f755429ff0ea23fa4ecc57e162120c5cde3a1
Showing with 294 additions and 251 deletions.
  1. +2 −2 python/core/symbology/qgs25drenderer.sip.in
  2. +6 −6 python/core/symbology/qgscategorizedsymbolrenderer.sip.in
  3. +6 −6 python/core/symbology/qgsgraduatedsymbolrenderer.sip.in
  4. +3 −3 python/core/symbology/qgsheatmaprenderer.sip.in
  5. +7 −7 python/core/symbology/qgsinvertedpolygonrenderer.sip.in
  6. +5 −5 python/core/symbology/qgsnullsymbolrenderer.sip.in
  7. +8 −8 python/core/symbology/qgspointdistancerenderer.sip.in
  8. +28 −19 python/core/symbology/qgsrenderer.sip.in
  9. +15 −15 python/core/symbology/qgsrulebasedrenderer.sip.in
  10. +4 −4 python/core/symbology/qgssinglesymbolrenderer.sip.in
  11. +2 −2 src/core/symbology/qgs25drenderer.cpp
  12. +2 −2 src/core/symbology/qgs25drenderer.h
  13. +7 −7 src/core/symbology/qgscategorizedsymbolrenderer.cpp
  14. +7 −7 src/core/symbology/qgscategorizedsymbolrenderer.h
  15. +6 −6 src/core/symbology/qgsgraduatedsymbolrenderer.cpp
  16. +9 −6 src/core/symbology/qgsgraduatedsymbolrenderer.h
  17. +3 −3 src/core/symbology/qgsheatmaprenderer.cpp
  18. +3 −3 src/core/symbology/qgsheatmaprenderer.h
  19. +10 −10 src/core/symbology/qgsinvertedpolygonrenderer.cpp
  20. +8 −8 src/core/symbology/qgsinvertedpolygonrenderer.h
  21. +5 −5 src/core/symbology/qgsnullsymbolrenderer.cpp
  22. +5 −5 src/core/symbology/qgsnullsymbolrenderer.h
  23. +13 −13 src/core/symbology/qgspointdistancerenderer.cpp
  24. +9 −9 src/core/symbology/qgspointdistancerenderer.h
  25. +32 −10 src/core/symbology/qgsrenderer.cpp
  26. +31 −22 src/core/symbology/qgsrenderer.h
  27. +27 −27 src/core/symbology/qgsrulebasedrenderer.cpp
  28. +15 −15 src/core/symbology/qgsrulebasedrenderer.h
  29. +4 −4 src/core/symbology/qgssinglesymbolrenderer.cpp
  30. +4 −4 src/core/symbology/qgssinglesymbolrenderer.h
  31. +4 −4 src/gui/symbology/qgsrulebasedrendererwidget.cpp
  32. +2 −2 src/plugins/grass/qgsgrasseditrenderer.cpp
  33. +2 −2 src/plugins/grass/qgsgrasseditrenderer.h
@@ -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;
@@ -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 );

@@ -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 );
@@ -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();
@@ -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``.

@@ -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 );

@@ -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;
@@ -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();
@@ -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;
@@ -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

@@ -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.
@@ -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.
@@ -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.
@@ -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;
@@ -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/;
@@ -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 );

@@ -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;
@@ -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

@@ -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
@@ -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.

@@ -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.
@@ -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.

@@ -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.
@@ -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
@@ -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()
@@ -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

0 comments on commit eb7f755

Please sign in to comment.
You can’t perform that action at this time.