QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
30 #include <QDomDocument>
31 #include <QDomElement>
110 mFeaturesCategories.clear();
111 mSymbolCategories.clear();
112 mFeatureDecorations.clear();
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 );
176 if ( selected || drawVertexMarker )
178 mFeatureDecorations.append( FeatureDecoration( feature, selected, drawVertexMarker, layer ) );
202 catId.append(
reinterpret_cast<const char *
>( &sym ),
sizeof( sym ) );
209 catId.append(
reinterpret_cast<const char *
>( &sym ),
sizeof( sym ) );
213 if ( catId.isEmpty() )
218 if ( ! mSymbolCategories.contains( catId ) )
220 CombinedFeature cFeat;
222 cFeat.feature = feature;
223 mSymbolCategories.insert( catId, mSymbolCategories.count() );
224 mFeaturesCategories.append( cFeat );
228 CombinedFeature &cFeat = mFeaturesCategories[ mSymbolCategories[catId] ];
247 geom = geom.
buffer( 0, 0 );
260 cFeat.geometries.append( geom );
287 for (
const CombinedFeature &cit : std::as_const( mFeaturesCategories ) )
289 finalMulti.resize( 0 );
327 finalMulti.append( mExtentPolygon );
328 for (
const QgsGeometry &geom : std::as_const( cit.geometries ) )
335 multi.append( geom.asPolygon() );
339 multi = geom.asMultiPolygon();
342 for (
int i = 0; i < multi.size(); i++ )
348 if ( exterior.count() < 4 || exterior[0] != exterior[exterior.count() - 1] )
350 finalMulti[0].append( exterior );
353 for (
int j = 1; j < multi[i].size(); j++ )
356 newPoly.append( multi[i][j] );
357 finalMulti.append( newPoly );
383 if ( mFeaturesCategories.isEmpty() )
394 for ( FeatureDecoration deco : std::as_const( mFeatureDecorations ) )
396 mSubRenderer->renderFeature( deco.feature, mContext, deco.layer, deco.selected, deco.drawMarkers );
406 return QStringLiteral(
"MERGED FEATURES: NULL" );
408 return "MERGED FEATURES [" +
mSubRenderer->dump() +
']';
430 QDomElement embeddedRendererElem = element.firstChildElement( QStringLiteral(
"renderer-v2" ) );
431 if ( !embeddedRendererElem.isNull() )
444 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"mergedFeatureRenderer" ) );
448 QDomElement embeddedRendererElem =
mSubRenderer->save( doc, context );
449 rendererElem.appendChild( embeddedRendererElem );
463 return mSubRenderer->symbolForFeature( feature, context );
470 return mSubRenderer->originalSymbolForFeature( feature, context );
479 return mSubRenderer->symbolsForFeature( feature, context );
486 return mSubRenderer->originalSymbolsForFeature( feature, context );
492 return QSet<QString>();
493 return mSubRenderer->legendKeysForFeature( feature, context );
501 return mSubRenderer->legendKeyToExpression( key, layer, ok );
517 return Capabilities();
526 return QSet<QString>();
551 return mSubRenderer->willRenderFeature( feature, context );
556 if ( renderer->
type() == QLatin1String(
"mergedFeatureRenderer" ) )
561 if ( renderer->
type() == QLatin1String(
"singleSymbol" ) ||
562 renderer->
type() == QLatin1String(
"categorizedSymbol" ) ||
563 renderer->
type() == QLatin1String(
"graduatedSymbol" ) ||
564 renderer->
type() == QLatin1String(
"RuleRenderer" ) )
566 std::unique_ptr< QgsMergedFeatureRenderer > res = std::make_unique< QgsMergedFeatureRenderer >( renderer->
clone() );
568 return res.release();
570 else if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
574 return res.release();
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
void checkLegendSymbolItem(const QString &key, bool state=true) override
item in symbology was checked
QString dump() const override
Returns debug information about this renderer.
QgsExpressionContext & expressionContext()
Gets the expression context.
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
The class is used as a container of context for various read/write operations on other objects.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
GeometryOperation mOperation
Operation to apply to collected geometries.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Container of fields for a vector layer.
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
QRectF toRectF() const
Returns a QRectF with same coordinates as the rectangle.
Contains information about the context of a rendering operation.
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Type
The WKB type describes the number of dimensions a geometry has.
QgsMergedFeatureRenderer(QgsFeatureRenderer *embeddedRenderer)
Constructor for QgsMergedFeatureRenderer.
Abstract base class for all rendered symbols.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
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...
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
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.
@ MergeAndInvert
Merge and invert features (polygons only)
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QList< QgsSymbol * > QgsSymbolList
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void saveRendererData(QDomDocument &doc, QDomElement &element, const QgsReadWriteContext &context)
Saves generic renderer data into the specified element.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
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...
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
#define RENDERER_TAG_NAME
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer) override
Sets an embedded renderer (subrenderer) for this feature renderer.
void stopRender(QgsRenderContext &context) override
The actual rendering will take place here.
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override SIP_THROW(QgsCsException)
Renders a given feature.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
static QgsMergedFeatureRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsMergedFeatureRenderer by a conversion from an existing renderer.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygonXY.
A geometry is the spatial representation of a feature.
Represents a vector layer which manages a vector based data sets.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
@ Merge
Merge features (union/dissolve)
@ InvertOnly
Invert features only (polygons only)
QgsMergedFeatureRenderer is a polygon or line-only feature renderer used to renderer a set of feature...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
QPainter * painter()
Returns the destination QPainter for the render operation.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
QgsWkbTypes::GeometryType type
std::unique_ptr< QgsFeatureRenderer > mSubRenderer
Embedded renderer.
QgsMergedFeatureRenderer * clone() const override
Create a deep copy of this renderer.
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
virtual const QgsFeatureRenderer * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns list of symbols used for rendering the feature.
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygonXY.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
bool isGeosValid(Qgis::GeometryValidityFlags flags=Qgis::GeometryValidityFlags()) const
Checks validity of the geometry using GEOS.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...