30#include <QDomDocument>
110 mFeaturesCategories.clear();
111 mSymbolCategories.clear();
112 mFeatureDecorations.clear();
137 mContext.setExtent( context.
mapExtent() );
151 exteriorRing.reserve( 5 );
152 exteriorRing << outer.topLeft();
153 exteriorRing << outer.topRight();
154 exteriorRing << outer.bottomRight();
155 exteriorRing << outer.bottomLeft();
156 exteriorRing << outer.topLeft();
158 mExtentPolygon.clear();
159 mExtentPolygon.append( exteriorRing );
186 if ( selected || drawVertexMarker )
188 mFeatureDecorations.append( FeatureDecoration( feature, selected, drawVertexMarker, layer ) );
212 catId.append(
reinterpret_cast<const char *
>( &sym ),
sizeof( sym ) );
219 catId.append(
reinterpret_cast<const char *
>( &sym ),
sizeof( sym ) );
223 if ( catId.isEmpty() )
228 if ( ! mSymbolCategories.contains( catId ) )
230 CombinedFeature cFeat;
232 cFeat.feature = feature;
233 mSymbolCategories.insert( catId, mSymbolCategories.count() );
234 mFeaturesCategories.append( cFeat );
238 CombinedFeature &cFeat = mFeaturesCategories[ mSymbolCategories[catId] ];
271 geom = geom.
buffer( 0, 0 );
284 cFeat.geometries.append( geom );
311 for (
const CombinedFeature &cit : std::as_const( mFeaturesCategories ) )
313 finalMulti.resize( 0 );
351 finalMulti.append( mExtentPolygon );
352 for (
const QgsGeometry &geom : std::as_const( cit.geometries ) )
359 multi.append( geom.asPolygon() );
363 multi = geom.asMultiPolygon();
366 for (
int i = 0; i < multi.size(); i++ )
372 if ( exterior.count() < 4 || exterior[0] != exterior[exterior.count() - 1] )
374 finalMulti[0].append( exterior );
377 for (
int j = 1; j < multi[i].size(); j++ )
380 newPoly.append( multi[i][j] );
381 finalMulti.append( newPoly );
392 mContext.expressionContext().setFeature( feat );
395 mContext.vectorSimplifyMethod().setForceLocalOptimization(
false );
397 mContext.vectorSimplifyMethod().setForceLocalOptimization( prevSimplify );
411 if ( mFeaturesCategories.isEmpty() )
422 for ( FeatureDecoration deco : std::as_const( mFeatureDecorations ) )
424 mSubRenderer->renderFeature( deco.feature, mContext, deco.layer, deco.selected, deco.drawMarkers );
434 return QStringLiteral(
"MERGED FEATURES: NULL" );
436 return "MERGED FEATURES [" +
mSubRenderer->dump() +
']';
458 QDomElement embeddedRendererElem = element.firstChildElement( QStringLiteral(
"renderer-v2" ) );
459 if ( !embeddedRendererElem.isNull() )
472 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"mergedFeatureRenderer" ) );
476 QDomElement embeddedRendererElem =
mSubRenderer->save( doc, context );
477 rendererElem.appendChild( embeddedRendererElem );
491 return mSubRenderer->symbolForFeature( feature, context );
498 return mSubRenderer->originalSymbolForFeature( feature, context );
507 return mSubRenderer->symbolsForFeature( feature, context );
514 return mSubRenderer->originalSymbolsForFeature( feature, context );
520 return QSet<QString>();
521 return mSubRenderer->legendKeysForFeature( feature, context );
529 return mSubRenderer->legendKeyToExpression( key, layer, ok );
554 return QSet<QString>();
579 return mSubRenderer->willRenderFeature( feature, context );
584 if ( renderer->
type() == QLatin1String(
"mergedFeatureRenderer" ) )
589 if ( renderer->
type() == QLatin1String(
"singleSymbol" ) ||
590 renderer->
type() == QLatin1String(
"categorizedSymbol" ) ||
591 renderer->
type() == QLatin1String(
"graduatedSymbol" ) ||
592 renderer->
type() == QLatin1String(
"RuleRenderer" ) )
594 auto res = std::make_unique< QgsMergedFeatureRenderer >( renderer->
clone() );
596 return res.release();
598 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
602 return res.release();
QFlags< FeatureRendererFlag > FeatureRendererFlags
Flags controlling behavior of vector feature renderers.
WkbType
The WKB type describes the number of dimensions a geometry has.
@ MultiPolygon
MultiPolygon.
@ CurvePolygon
CurvePolygon.
@ MultiSurface
MultiSurface.
QgsFeatureRenderer(const QString &type)
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QFlags< Capability > Capabilities
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
QgsGeometry difference(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points making up this geometry that do not make up other.
QgsGeometry mergeLines(const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygonXY.
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygonXY.
QgsGeometry buffer(double distance, int segments) const
Returns a buffer region around this geometry having the given width and with a specified number of se...
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries, const QgsGeometryParameters ¶meters=QgsGeometryParameters())
Compute the unary union on a list of geometries.
Implementation of a geometry simplifier using the "MapToPixel" algorithm.
QgsGeometry simplify(const QgsGeometry &geometry) const override
Returns a simplified version the specified geometry.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
void stopRender(QgsRenderContext &context) override
The actual rendering will take place here.
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns list of symbols used for rendering the feature.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
QString legendKeyToExpression(const QString &key, QgsVectorLayer *layer, bool &ok) const override
Attempts to convert the specified legend rule key to a QGIS expression matching the features displaye...
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
QString dump() const override
Returns debug information about this renderer.
QgsMergedFeatureRenderer(QgsFeatureRenderer *embeddedRenderer)
Constructor for QgsMergedFeatureRenderer.
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Renders a given feature.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
@ Merge
Merge features (union/dissolve).
@ InvertOnly
Invert features only (polygons only).
@ MergeAndInvert
Merge and invert features (polygons only).
GeometryOperation mOperation
Operation to apply to collected geometries.
void checkLegendSymbolItem(const QString &key, bool state=true) override
Sets whether the legend symbology item with the specified ley should be checked.
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
bool legendSymbolItemChecked(const QString &key) override
Returns true if the legend symbology item with the specified key is checked.
void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer) override
Sets an embedded renderer (subrenderer) for this feature renderer.
std::unique_ptr< QgsFeatureRenderer > mSubRenderer
Embedded renderer.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.
bool legendSymbolItemsCheckable() const override
Returns true if symbology items in legend are checkable.
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
static QgsMergedFeatureRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsMergedFeatureRenderer by a conversion from an existing renderer.
Qgis::FeatureRendererFlags flags() const override
Returns flags associated with the renderer.
QgsMergedFeatureRenderer * clone() const override
Create a deep copy of this renderer.
A container for the context for various read/write operations on objects.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
Contains information about the context of a rendering operation.
QgsVectorSimplifyMethod & vectorSimplifyMethod()
Returns the simplification settings to use when rendering vector layers.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
An interface for classes which can visit style entity (e.g.
Abstract base class for all rendered symbols.
Represents a vector layer which manages a vector based dataset.
double tolerance() const
Gets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
Qgis::VectorRenderingSimplificationFlags simplifyHints() const
Gets the simplification hints of the vector layer managed.
Qgis::VectorSimplificationAlgorithm simplifyAlgorithm() const
Gets the local simplification algorithm of the vector layer managed.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
#define RENDERER_TAG_NAME
QList< QgsSymbol * > QgsSymbolList