QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsmergedfeaturerenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmergedfeaturerenderer.h
3  ---------------------
4  begin : December 2020
5  copyright : (C) 2020 by Nyall Dawson
6  email : nyall dot dawson at gmail 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 QGSMERGEDFEATURERENDERER_H
16 #define QGSMERGEDFEATURERENDERER_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 #include "qgsrendercontext.h"
26 
40 class CORE_EXPORT QgsMergedFeatureRenderer : public QgsFeatureRenderer
41 {
42  public:
43 
49 
53  QgsMergedFeatureRenderer &operator=( const QgsMergedFeatureRenderer & ) = delete;
54 
56  static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
57 
58  QgsMergedFeatureRenderer *clone() const override SIP_FACTORY;
59  void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
60 
71  bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
72 
77  void stopRender( QgsRenderContext &context ) override;
78 
79  QString dump() const override;
80  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
81  bool filterNeedsGeometry() const override;
82  QgsFeatureRenderer::Capabilities capabilities() override;
83  QgsSymbolList symbols( QgsRenderContext &context ) const override;
84  QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
85  QgsSymbol *originalSymbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
86  QgsSymbolList symbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
87  QgsSymbolList originalSymbolsForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
88  QSet< QString > legendKeysForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
89  QString legendKeyToExpression( const QString &key, QgsVectorLayer *layer, bool &ok ) const override;
90  QgsLegendSymbolList legendSymbolItems() const override;
91  bool willRenderFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
92  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
93  void setEmbeddedRenderer( QgsFeatureRenderer *subRenderer SIP_TRANSFER ) override;
94  const QgsFeatureRenderer *embeddedRenderer() const override;
95  void setLegendSymbolItem( const QString &key, QgsSymbol *symbol ) override;
96  bool legendSymbolItemsCheckable() const override;
97  bool legendSymbolItemChecked( const QString &key ) override;
98  void checkLegendSymbolItem( const QString &key, bool state = true ) override;
99  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
100 
105  static QgsMergedFeatureRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
106 
107  protected:
108 
114  QgsMergedFeatureRenderer( const QString &type, QgsFeatureRenderer *embeddedRenderer SIP_TRANSFER );
115 
119  enum GeometryOperation
120  {
121  Merge,
122  InvertOnly,
123  MergeAndInvert,
124  };
125 
127  GeometryOperation mOperation = Merge;
128 
130  std::unique_ptr<QgsFeatureRenderer> mSubRenderer;
131 
132  private:
133 
135  struct CombinedFeature
136  {
137  QVector<QgsGeometry> geometries; //< list of geometries
138  QgsFeature feature; //< one feature (for attriute-based rendering)
139  };
140  typedef QVector<CombinedFeature> FeatureCategoryVector;
142  FeatureCategoryVector mFeaturesCategories;
143 
145  QMap<QByteArray, int> mSymbolCategories;
146 
148  QgsPolygonXY mExtentPolygon;
149 
151  QgsRenderContext mContext;
152 
154  QgsFields mFields;
155 
160  struct FeatureDecoration
161  {
162  QgsFeature feature;
163  bool selected;
164  bool drawMarkers;
165  int layer;
166  FeatureDecoration( const QgsFeature &a_feature, bool a_selected, bool a_drawMarkers, int a_layer )
167  : feature( a_feature )
168  , selected( a_selected )
169  , drawMarkers( a_drawMarkers )
170  , layer( a_layer )
171  {}
172  };
173  QList<FeatureDecoration> mFeatureDecorations;
174 
175 };
176 
177 
178 #endif // QGSMERGEDFEATURERENDERER_H
QgsFeatureRenderer::setLegendSymbolItem
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
Definition: qgsrenderer.cpp:365
QgsFeatureRenderer::originalSymbolForFeature
virtual QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns symbol for feature.
Definition: qgsrenderer.cpp:84
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsPolygonXY
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Definition: qgsgeometry.h:76
qgsexpression.h
QgsFeatureRenderer::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
Definition: qgsrenderer.cpp:489
QgsFeatureRenderer::capabilities
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
Definition: qgsrenderer.h:283
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
qgsfeature.h
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsFeatureRenderer::usedAttributes
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsFeatureRenderer::legendSymbolItems
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
Definition: qgsrenderer.cpp:377
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:92
QgsFeatureRenderer::setEmbeddedRenderer
virtual void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.cpp:479
QgsFeatureRenderer::stopRender
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
Definition: qgsrenderer.cpp:110
QgsFeatureRenderer::willRenderFeature
virtual bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns whether the renderer will render a feature or not.
Definition: qgsrenderer.cpp:388
QgsFeatureRenderer::legendSymbolItemChecked
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
Definition: qgsrenderer.cpp:353
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsFeatureRenderer::legendSymbolItemsCheckable
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
Definition: qgsrenderer.cpp:348
QgsFeatureRenderer::save
virtual QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context)
Stores renderer properties to an XML element.
Definition: qgsrenderer.cpp:193
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
QgsFeatureRenderer::filterNeedsGeometry
virtual bool filterNeedsGeometry() const
Returns true if this renderer requires the geometry to apply the filter.
Definition: qgsrenderer.cpp:122
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:198
QgsFeatureRenderer::checkLegendSymbolItem
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
Definition: qgsrenderer.cpp:359
QgsSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44
QgsFeatureRenderer::clone
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsFeatureRenderer::originalSymbolsForFeature
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
Definition: qgsrenderer.cpp:440
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
qgsrendercontext.h
QgsFeatureRenderer::symbols
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
Definition: qgsrenderer.cpp:151
QgsFeatureRenderer::symbolForFeature
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
qgsrenderer.h
QgsFeatureRenderer::legendKeyToExpression
virtual QString legendKeyToExpression(const QString &key, QgsVectorLayer *layer, bool &ok) const
Attempts to convert the specified legend rule key to a QGIS expression matching the features displaye...
Definition: qgsrenderer.cpp:371
qgsgeometry.h
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeatureRenderer::renderFeature
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.
Definition: qgsrenderer.cpp:127
QgsFeatureRenderer::dump
virtual QString dump() const
Returns debug information about this renderer.
Definition: qgsrenderer.cpp:146
QgsMergedFeatureRenderer
QgsMergedFeatureRenderer is a polygon or line-only feature renderer used to renderer a set of feature...
Definition: qgsmergedfeaturerenderer.h:40
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsMergedFeatureRenderer::GeometryOperation
GeometryOperation
Operations to apply to collected geometries prior to rendering.
Definition: qgsmergedfeaturerenderer.h:132
QgsLegendSymbolList
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Definition: qgslegendsymbolitem.h:144
QgsFeatureRenderer::startRender
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Definition: qgsrenderer.cpp:96
QgsFeatureRenderer::symbolsForFeature
virtual QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns list of symbols used for rendering the feature.
Definition: qgsrenderer.cpp:426
QgsFeatureRenderer::embeddedRenderer
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
Definition: qgsrenderer.cpp:484
QgsFeatureRenderer::legendKeysForFeature
virtual QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Returns legend keys matching a specified feature.
Definition: qgsrenderer.cpp:89