QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
30 #include <QDomDocument>
31 #include <QDomElement>
50 mSubRenderer.reset( subRenderer );
54 mSubRenderer.reset(
nullptr );
60 return mSubRenderer.get();
68 mSubRenderer->setLegendSymbolItem( key, symbol );
76 return mSubRenderer->legendSymbolItemsCheckable();
84 return mSubRenderer->legendSymbolItemChecked( key );
92 mSubRenderer->checkLegendSymbolItem( key, state );
100 return mSubRenderer->accept( visitor );
113 mSubRenderer->startRender( context, fields );
115 mFeaturesCategories.clear();
116 mSymbolCategories.clear();
117 mFeatureDecorations.clear();
134 exteriorRing.reserve( 5 );
135 exteriorRing << outer.topLeft();
136 exteriorRing << outer.topRight();
137 exteriorRing << outer.bottomRight();
138 exteriorRing << outer.bottomLeft();
139 exteriorRing << outer.topLeft();
158 mExtentPolygon.clear();
159 mExtentPolygon.append( exteriorRing );
170 if ( selected || drawVertexMarker )
172 mFeatureDecorations.append( FeatureDecoration( feature, selected, drawVertexMarker, layer ) );
192 QgsSymbolList syms( mSubRenderer->symbolsForFeature( feature, context ) );
193 const auto constSyms = syms;
197 catId.append(
reinterpret_cast<const char *
>( &sym ),
sizeof( sym ) );
202 QgsSymbol *sym = mSubRenderer->symbolForFeature( feature, context );
205 catId.append(
reinterpret_cast<const char *
>( &sym ),
sizeof( sym ) );
209 if ( catId.isEmpty() )
214 if ( ! mSymbolCategories.contains( catId ) )
216 CombinedFeature cFeat;
218 cFeat.feature = feature;
219 mSymbolCategories.insert( catId, mSymbolCategories.count() );
220 mFeaturesCategories.append( cFeat );
224 CombinedFeature &cFeat = mFeaturesCategories[ mSymbolCategories[catId] ];
237 if ( mPreprocessingEnabled )
242 geom = geom.
buffer( 0, 0 );
250 cFeat.geometries.append( geom );
260 mSubRenderer->stopRender( mContext );
276 const auto constMFeaturesCategories = mFeaturesCategories;
277 for (
const CombinedFeature &cit : constMFeaturesCategories )
279 finalMulti.resize( 0 );
281 if ( mPreprocessingEnabled )
303 finalMulti.append( mExtentPolygon );
304 for (
const QgsGeometry &geom : qgis::as_const( cit.geometries ) )
311 multi.append( geom.asPolygon() );
315 multi = geom.asMultiPolygon();
318 for (
int i = 0; i < multi.size(); i++ )
324 if ( exterior.count() < 4 || exterior[0] != exterior[exterior.count() - 1] )
326 finalMulti[0].append( exterior );
329 for (
int j = 1; j < multi[i].size(); j++ )
332 newPoly.append( multi[i][j] );
333 finalMulti.append( newPoly );
342 mSubRenderer->renderFeature( feat, mContext );
350 if ( mFeaturesCategories.isEmpty() )
355 mSubRenderer->renderFeature( feat, mContext );
359 const auto constMFeatureDecorations = mFeatureDecorations;
360 for ( FeatureDecoration deco : constMFeatureDecorations )
362 mSubRenderer->renderFeature( deco.feature, mContext, deco.layer, deco.selected, deco.drawMarkers );
365 mSubRenderer->stopRender( mContext );
372 return QStringLiteral(
"INVERTED: NULL" );
374 return "INVERTED [" + mSubRenderer->dump() +
']';
397 QDomElement embeddedRendererElem = element.firstChildElement( QStringLiteral(
"renderer-v2" ) );
398 if ( !embeddedRendererElem.isNull() )
403 r->
setPreprocessingEnabled( element.attribute( QStringLiteral(
"preprocessing" ), QStringLiteral(
"0" ) ).toInt() == 1 );
412 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"invertedPolygonRenderer" ) );
413 rendererElem.setAttribute( QStringLiteral(
"preprocessing" ),
preprocessingEnabled() ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
414 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
418 QDomElement embeddedRendererElem = mSubRenderer->save( doc, context );
419 rendererElem.appendChild( embeddedRendererElem );
427 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
429 rendererElem.appendChild(
orderBy );
431 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
442 return mSubRenderer->symbolForFeature( feature, context );
449 return mSubRenderer->originalSymbolForFeature( feature, context );
458 return mSubRenderer->symbolsForFeature( feature, context );
465 return mSubRenderer->originalSymbolsForFeature( feature, context );
471 return QSet<QString>();
472 return mSubRenderer->legendKeysForFeature( feature, context );
481 return mSubRenderer->symbols( context );
488 return Capabilities();
490 return mSubRenderer->capabilities();
497 return QSet<QString>();
499 return mSubRenderer->usedAttributes( context );
504 return mSubRenderer ? mSubRenderer->filterNeedsGeometry() :
false;
513 return mSubRenderer->legendSymbolItems();
522 return mSubRenderer->willRenderFeature( feature, context );
527 if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
532 if ( renderer->
type() == QLatin1String(
"singleSymbol" ) ||
533 renderer->
type() == QLatin1String(
"categorizedSymbol" ) ||
534 renderer->
type() == QLatin1String(
"graduatedSymbol" ) ||
535 renderer->
type() == QLatin1String(
"RuleRenderer" ) )
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns list of symbols used for rendering the feature.
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
QgsPaintEffect * mPaintEffect
QgsExpressionContext & expressionContext()
Gets the expression context.
bool preprocessingEnabled() const
The class is used as a container of context for various read/write operations on other objects.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
static QgsInvertedPolygonRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsInvertedPolygonRenderer by a conversion from an existing renderer.
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
QgsInvertedPolygonRenderer(QgsFeatureRenderer *embeddedRenderer=nullptr)
Constructor.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Container of fields for a vector layer.
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.
An interface for classes which can visit style entity (e.g.
Type
The WKB type describes the number of dimensions a geometry has.
Abstract base class for all rendered symbols.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
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 bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override SIP_THROW(QgsCsException)
Renders a given feature.
QgsLegendSymbolList legendSymbolItems() const override
Returns a list of symbology items for the legend.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
QSet< QString > legendKeysForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns legend keys matching a specified feature.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
QString dump() const override
Returns debug information about this renderer.
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...
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.
QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
#define RENDERER_TAG_NAME
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
void checkLegendSymbolItem(const QString &key, bool state=true) override
item in symbology was checked
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
QgsFeatureRequest::OrderBy mOrderBy
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
void stopRender(QgsRenderContext &context) override
The actual rendering will take place here.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns symbol for feature.
QgsRectangle mapExtent() const
Returns the original extent of the map being rendered.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
A geometry is the spatial representation of a feature.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
bool filterNeedsGeometry() const override
Returns true if this renderer requires the geometry to apply the filter.
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
bool willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Returns whether the renderer will render a feature or not.
QgsInvertedPolygonRenderer * clone() const override
Create a deep copy of this renderer.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setPreprocessingEnabled(bool enabled)
bool isGeosValid(QgsGeometry::ValidityFlags flags=QgsGeometry::ValidityFlags()) const
Checks validity of the geometry using GEOS.
void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer) override
Sets an embedded renderer (subrenderer) for this feature renderer.
QPainter * painter()
Returns the destination QPainter for the render operation.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other.
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygon.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted,...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
QgsFeatureRenderer::Capabilities capabilities() override
Returns details about internals of this renderer.