29 #include <QDomDocument> 30 #include <QDomElement> 49 mSubRenderer.reset( subRenderer );
53 mSubRenderer.reset(
nullptr );
59 return mSubRenderer.get();
67 mSubRenderer->setLegendSymbolItem( key, symbol );
75 return mSubRenderer->legendSymbolItemsCheckable();
83 return mSubRenderer->legendSymbolItemChecked( key );
91 mSubRenderer->checkLegendSymbolItem( key, state );
104 mSubRenderer->startRender( context, fields );
106 mFeaturesCategories.clear();
107 mSymbolCategories.clear();
108 mFeatureDecorations.clear();
122 QRect e( context.
painter()->viewport() );
124 e.adjust( -e.width() * 5, -e.height() * 5, e.width() * 5, e.height() * 5 );
127 exteriorRing << mtp.toMapCoordinates( e.topRight() );
128 exteriorRing << mtp.toMapCoordinates( e.bottomRight() );
129 exteriorRing << mtp.toMapCoordinates( e.bottomLeft() );
130 exteriorRing << mtp.toMapCoordinates( e.topLeft() );
145 QRect v( context.
painter()->viewport() );
146 mContext.
setExtent(
QgsRectangle( mtp.toMapCoordinates( v.topLeft() ), mtp.toMapCoordinates( v.bottomRight() ) ) );
150 mExtentPolygon.clear();
151 mExtentPolygon.append( exteriorRing );
162 if ( selected || drawVertexMarker )
164 mFeatureDecorations.append( FeatureDecoration( feature, selected, drawVertexMarker, layer ) );
184 QgsSymbolList syms( mSubRenderer->symbolsForFeature( feature, context ) );
188 catId.append( reinterpret_cast<const char *>( &sym ),
sizeof( sym ) );
193 QgsSymbol *sym = mSubRenderer->symbolForFeature( feature, context );
196 catId.append( reinterpret_cast<const char *>( &sym ),
sizeof( sym ) );
200 if ( catId.isEmpty() )
205 if ( ! mSymbolCategories.contains( catId ) )
207 CombinedFeature cFeat;
209 cFeat.feature = feature;
210 mSymbolCategories.insert( catId, mSymbolCategories.count() );
211 mFeaturesCategories.append( cFeat );
215 CombinedFeature &cFeat = mFeaturesCategories[ mSymbolCategories[catId] ];
228 if ( mPreprocessingEnabled )
233 geom = geom.
buffer( 0, 0 );
241 cFeat.geometries.append( geom );
262 Q_FOREACH (
const CombinedFeature &cit, mFeaturesCategories )
264 finalMulti.resize( 0 );
266 if ( mPreprocessingEnabled )
288 finalMulti.append( mExtentPolygon );
289 Q_FOREACH (
const QgsGeometry &geom, cit.geometries )
303 for (
int i = 0; i < multi.size(); i++ )
309 if ( exterior.count() < 4 || exterior[0] != exterior[exterior.count() - 1] )
311 finalMulti[0].append( exterior );
314 for (
int j = 1; j < multi[i].size(); j++ )
317 newPoly.append( multi[i][j] );
318 finalMulti.append( newPoly );
327 mSubRenderer->renderFeature( feat, mContext );
335 if ( mFeaturesCategories.isEmpty() )
340 mSubRenderer->renderFeature( feat, mContext );
344 Q_FOREACH ( FeatureDecoration deco, mFeatureDecorations )
346 mSubRenderer->renderFeature( deco.feature, mContext, deco.layer, deco.selected, deco.drawMarkers );
349 mSubRenderer->stopRender( mContext );
356 return QStringLiteral(
"INVERTED: NULL" );
358 return "INVERTED [" + mSubRenderer->dump() +
']';
381 QDomElement embeddedRendererElem = element.firstChildElement( QStringLiteral(
"renderer-v2" ) );
382 if ( !embeddedRendererElem.isNull() )
387 r->
setPreprocessingEnabled( element.attribute( QStringLiteral(
"preprocessing" ), QStringLiteral(
"0" ) ).toInt() == 1 );
396 rendererElem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"invertedPolygonRenderer" ) );
397 rendererElem.setAttribute( QStringLiteral(
"preprocessing" ),
preprocessingEnabled() ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
398 rendererElem.setAttribute( QStringLiteral(
"forceraster" ), (
mForceRaster ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
402 QDomElement embeddedRendererElem = mSubRenderer->save( doc, context );
403 rendererElem.appendChild( embeddedRendererElem );
411 QDomElement
orderBy = doc.createElement( QStringLiteral(
"orderby" ) );
413 rendererElem.appendChild( orderBy );
415 rendererElem.setAttribute( QStringLiteral(
"enableorderby" ), (
mOrderByEnabled ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) ) );
426 return mSubRenderer->symbolForFeature( feature, context );
433 return mSubRenderer->originalSymbolForFeature( feature, context );
442 return mSubRenderer->symbolsForFeature( feature, context );
449 return mSubRenderer->originalSymbolsForFeature( feature, context );
458 return mSubRenderer->symbols( context );
467 return mSubRenderer->capabilities();
474 return QSet<QString>();
476 return mSubRenderer->usedAttributes( context );
485 return mSubRenderer->legendSymbolItems();
494 return mSubRenderer->willRenderFeature( feature, context );
499 if ( renderer->
type() == QLatin1String(
"invertedPolygonRenderer" ) )
504 if ( renderer->
type() == QLatin1String(
"singleSymbol" ) ||
505 renderer->
type() == QLatin1String(
"categorizedSymbol" ) ||
506 renderer->
type() == QLatin1String(
"graduatedSymbol" ) ||
507 renderer->
type() == QLatin1String(
"RuleRenderer" ) )
static QgsGeometry fromMultiPolygonXY(const QgsMultiPolygonXY &multipoly)
Creates a new geometry from a QgsMultiPolygon.
The class is used as a container of context for various read/write operations on other objects...
QgsFeatureRenderer::Capabilities capabilities() override
Proxy that will call this method on the embedded renderer.
May use more than one symbol to render a feature: symbolsForFeature() will return them...
A rectangle specified with double values.
bool legendSymbolItemChecked(const QString &key) override
items of symbology items in legend is checked
QList< QgsLegendSymbolItem > QgsLegendSymbolList
QgsFeatureRequest::OrderBy mOrderBy
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
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.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets coordinate transformation.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Proxy that will call this method on the embedded renderer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
QVector< QgsPolylineXY > QgsPolygonXY
Polygon: first item of the list is outer ring, inner rings (if any) start from second item...
QgsInvertedPolygonRenderer * clone() const override
Create a deep copy of this renderer.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
#define RENDERER_TAG_NAME
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 willRenderFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Proxy that will call this method on the embedded renderer.
QgsPaintEffect * mPaintEffect
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString dump() const override
Returns debug information about this renderer.
static QgsInvertedPolygonRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsInvertedPolygonRenderer by a conversion from an existing renderer.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setExtent(const QgsRectangle &extent)
QVector< QgsPolygonXY > QgsMultiPolygonXY
A collection of QgsPolygons that share a common collection of attributes.
bool isGeosValid() const
Checks validity of the geometry using GEOS.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
Perform transforms between map coordinates and device coordinates.
Type
The WKB type describes the number of dimensions a geometry has.
QList< QgsSymbol * > QgsSymbolList
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Proxy that will call this method on the embedded renderer.
void checkLegendSymbolItem(const QString &key, bool state=true) override
item in symbology was checked
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
QgsInvertedPolygonRenderer is a polygon-only feature renderer used to display features inverted...
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Proxy that will call this method on the embedded renderer.
bool preprocessingEnabled() const
QgsPolygonXY asPolygon() const
Returns contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
QgsLegendSymbolList legendSymbolItems() const override
Proxy that will call this method on the embedded renderer.
void setPreprocessingEnabled(bool enabled)
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context, or an invalid transform is no coordinate tr...
QgsGeometry geometry() const
Returns the geometry associated with this feature.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsSymbol * originalSymbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Proxy that will call this method on the embedded renderer.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsSymbolList symbols(QgsRenderContext &context) const override
Proxy that will call this method on the embedded renderer.
QgsExpressionContext & expressionContext()
Gets the expression context.
static QgsGeometry fromPolygonXY(const QgsPolygonXY &polygon)
Creates a new geometry from a QgsPolygon.
QVector< QgsPointXY > QgsPolylineXY
Polyline as represented as a vector of two-dimensional points.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
QgsInvertedPolygonRenderer(QgsFeatureRenderer *embeddedRenderer=nullptr)
Constructor.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
void setLegendSymbolItem(const QString &key, QgsSymbol *symbol) override
Sets the symbol to be used for a legend symbol item.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
bool legendSymbolItemsCheckable() const override
items of symbology items in legend should be checkable
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Renders a given feature.
void stopRender(QgsRenderContext &context) override
The actual rendering will take place here.
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
static QgsFeatureRenderer * defaultRenderer(QgsWkbTypes::GeometryType geomType)
Returns a new renderer - used by default in vector layers.
static Type flatType(Type type)
Returns the flat type for a WKB type.
static QgsGeometry unaryUnion(const QVector< QgsGeometry > &geometries)
Compute the unary union on a list of geometries.
QgsMultiPolygonXY asMultiPolygon() const
Returns contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty list.
QgsPointXY toMapCoordinates(int x, int y) const
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsSymbolList symbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
Proxy that will call this method on the embedded renderer.
void setEmbeddedRenderer(QgsFeatureRenderer *subRenderer) override
Sets an embedded renderer (subrenderer) for this feature renderer.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.
QgsGeometry difference(const QgsGeometry &geometry) const
Returns a geometry representing the points making up this geometry that do not make up other...