QGIS API Documentation  3.17.0-Master (3b262f2a79)
Go to the documentation of this file.
1 /***************************************************************************
2  qgsinvertedpolygonrenderer.h
3  ---------------------
4  begin : April 2014
5  copyright : (C) 2014 Hugo Mercier / Oslandia
6  email : hugo dot mercier at oslandia 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  ***************************************************************************/
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgis.h"
21 #include "qgsrenderer.h"
22 #include "qgsexpression.h"
23 #include "qgsfeature.h"
24 #include "qgsgeometry.h"
42 {
43  public:
50  QgsInvertedPolygonRenderer( QgsFeatureRenderer *embeddedRenderer SIP_TRANSFER = nullptr );
55  QgsInvertedPolygonRenderer &operator=( const QgsInvertedPolygonRenderer & ) = delete;
58  void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
70  bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
76  void stopRender( QgsRenderContext &context ) override;
78  QString dump() const override;
79  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
80  bool filterNeedsGeometry() const override;
81  QgsFeatureRenderer::Capabilities capabilities() override;
82  QgsSymbolList symbols( QgsRenderContext &context ) const override;
83  QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
84  QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
85  QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
86  QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
87  QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
88  QgsLegendSymbolList legendSymbolItems() const override;
89  bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
92  static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
94  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
96  void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) override;
97  const QgsFeatureRenderer *embeddedRenderer() const override;
99  void setLegendSymbolItem( const QString &key, QgsSymbol *symbol ) override;
101  bool legendSymbolItemsCheckable() const override;
102  bool legendSymbolItemChecked( const QString &key ) override;
103  void checkLegendSymbolItem( const QString &key, bool state = true ) override;
104  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
107  bool preprocessingEnabled() const { return mPreprocessingEnabled; }
115  void setPreprocessingEnabled( bool enabled ) { mPreprocessingEnabled = enabled; }
122  static QgsInvertedPolygonRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
124  private:
127  std::unique_ptr<QgsFeatureRenderer> mSubRenderer;
130  struct CombinedFeature
131  {
132  QVector<QgsGeometry> geometries; //< list of geometries
133  QgsFeature feature; //< one feature (for attriute-based rendering)
134  };
135  typedef QVector<CombinedFeature> FeatureCategoryVector;
137  FeatureCategoryVector mFeaturesCategories;
140  QMap<QByteArray, int> mSymbolCategories;
143  QgsPolygonXY mExtentPolygon;
146  QgsRenderContext mContext;
149  QgsFields mFields;
155  struct FeatureDecoration
156  {
157  QgsFeature feature;
158  bool selected;
159  bool drawMarkers;
160  int layer;
161  FeatureDecoration( const QgsFeature &a_feature, bool a_selected, bool a_drawMarkers, int a_layer )
162  : feature( a_feature )
163  , selected( a_selected )
164  , drawMarkers( a_drawMarkers )
165  , layer( a_layer )
166  {}
167  };
168  QList<FeatureDecoration> mFeatureDecorations;
171  bool mPreprocessingEnabled = false;
172 };
The class is used as a container of context for various read/write operations on other objects...
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
store renderer info to XML element
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
Definition: qgsgeometry.h:75
Container of fields for a vector layer.
Definition: qgsfields.h:44
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
An interface for classes which can visit style entity (e.g.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:45
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted...
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
Definition: qgsrenderer.cpp:81
Definition: qgis_sip.h:36
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
Definition: qgis_sip.h:76
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
virtual bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) SIP_THROW(QgsCsException)
Render a feature using this renderer in the given context.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Contains information about the context of a rendering operation.
virtual QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns list of symbols used for rendering the feature.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:93
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
Definition: qgsrenderer.cpp:86
#define SIP_THROW(name)
Definition: qgis_sip.h:189
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
Definition: qgsrenderer.h:274
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
virtual QString dump() const
Returns debug information about this renderer.