QGIS API Documentation  3.0.2-Girona (307d082)
qgsinvertedpolygonrenderer.h
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  ***************************************************************************/
15 #ifndef QGSINVERTEDPOLYGONRENDERER_H
16 #define QGSINVERTEDPOLYGONRENDERER_H
17 
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"
25 
42 {
43  public:
44 
50  QgsInvertedPolygonRenderer( QgsFeatureRenderer *embeddedRenderer SIP_TRANSFER = nullptr );
51 
55  QgsInvertedPolygonRenderer &operator=( const QgsInvertedPolygonRenderer & ) = delete;
56 
58  void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
59 
70  bool renderFeature( QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override;
71 
76  void stopRender( QgsRenderContext &context ) override;
77 
78  QString dump() const override;
79 
81  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
83  QgsFeatureRenderer::Capabilities capabilities() override;
84 
88  QgsSymbolList symbols( QgsRenderContext &context ) override;
89 
93  QgsSymbol *symbolForFeature( QgsFeature &feature, QgsRenderContext &context ) override;
94 
99 
103  QgsSymbolList symbolsForFeature( QgsFeature &feat, QgsRenderContext &context ) override;
104 
109 
113  QgsLegendSymbolList legendSymbolItems() const override;
114 
118  bool willRenderFeature( QgsFeature &feat, QgsRenderContext &context ) override;
119 
121  static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
122 
123  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
124 
125  void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) override;
126  const QgsFeatureRenderer *embeddedRenderer() const override;
127 
128  void setLegendSymbolItem( const QString &key, QgsSymbol *symbol ) override;
129 
130  bool legendSymbolItemsCheckable() const override;
131  bool legendSymbolItemChecked( const QString &key ) override;
132  void checkLegendSymbolItem( const QString &key, bool state = true ) override;
133 
135  bool preprocessingEnabled() const { return mPreprocessingEnabled; }
136 
143  void setPreprocessingEnabled( bool enabled ) { mPreprocessingEnabled = enabled; }
144 
150  static QgsInvertedPolygonRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
151 
152  private:
153 
155  std::unique_ptr<QgsFeatureRenderer> mSubRenderer;
156 
158  struct CombinedFeature
159  {
160  QVector<QgsGeometry> geometries; //< list of geometries
161  QgsFeature feature; //< one feature (for attriute-based rendering)
162  };
163  typedef QVector<CombinedFeature> FeatureCategoryVector;
165  FeatureCategoryVector mFeaturesCategories;
166 
168  QMap<QByteArray, int> mSymbolCategories;
169 
171  QgsPolygonXY mExtentPolygon;
172 
174  QgsRenderContext mContext;
175 
177  QgsFields mFields;
178 
183  struct FeatureDecoration
184  {
185  QgsFeature feature;
186  bool selected;
187  bool drawMarkers;
188  int layer;
189  FeatureDecoration( QgsFeature &a_feature, bool a_selected, bool a_drawMarkers, int a_layer )
190  : feature( a_feature )
191  , selected( a_selected )
192  , drawMarkers( a_drawMarkers )
193  , layer( a_layer )
194  {}
195  };
196  QList<FeatureDecoration> mFeatureDecorations;
197 
199  bool mPreprocessingEnabled = false;
200 };
201 
202 
203 #endif // QGSMASKRENDERERV2_H
virtual bool willRenderFeature(QgsFeature &feat, QgsRenderContext &context)
Returns whether the renderer will render a feature or not.
The class is used as a container of context for various read/write operations on other objects...
virtual QgsSymbolList originalSymbolsForFeature(QgsFeature &feat, QgsRenderContext &context)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
store renderer info to XML element
virtual QgsSymbol * originalSymbolForFeature(QgsFeature &feature, QgsRenderContext &context)
Return symbol for feature.
Definition: qgsrenderer.cpp:80
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
Definition: qgsgeometry.h:73
Container of fields for a vector layer.
Definition: qgsfields.h:42
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Return a list of attributes required by this renderer.
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:43
virtual QgsSymbolList symbolsForFeature(QgsFeature &feat, QgsRenderContext &context)
Returns list of symbols used for rendering the feature.
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
#define SIP_FACTORY
Definition: qgis_sip.h:69
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 void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.h:449
virtual QgsSymbolList symbols(QgsRenderContext &context)
Returns list of symbols used by the renderer.
Definition: qgsrenderer.h:266
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.h:457
virtual QgsSymbol * symbolForFeature(QgsFeature &feature, QgsRenderContext &context)=0
To be overridden.
Contains information about the context of a rendering operation.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:92
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
Definition: qgsrenderer.h:259
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
virtual QString dump() const
Returns debug information about this renderer.