38 #include "qgssettingsregistrycore.h"
51 , mFields( layer->fields() )
55 mSource = std::make_unique< QgsVectorLayerFeatureSource >( layer );
57 std::unique_ptr< QgsFeatureRenderer > mainRenderer( layer->
renderer() ? layer->
renderer()->
clone() :
nullptr );
65 return g1->level() < g2->level();
68 bool insertedMainRenderer =
false;
69 double prevLevel = std::numeric_limits< double >::lowest();
73 if ( generator->level() >= 0 && prevLevel < 0 && !insertedMainRenderer )
76 mRenderers.emplace_back( std::move( mainRenderer ) );
77 insertedMainRenderer =
true;
79 mRenderers.emplace_back( generator->createRenderer() );
80 prevLevel = generator->level();
86 mRenderers.emplace_back( std::move( mainRenderer ) );
120 QString markerTypeString = QgsSettingsRegistryCore::settingsDigitizingMarkerStyle.value();
121 if ( markerTypeString == QLatin1String(
"Cross" ) )
125 else if ( markerTypeString == QLatin1String(
"SemiTransparentCircle" ) )
134 mVertexMarkerSize = QgsSettingsRegistryCore::settingsDigitizingMarkerSizeMm.value();
145 for (
const std::unique_ptr< QgsFeatureRenderer > &renderer :
mRenderers )
147 mAttrNames.unite( renderer->usedAttributes( context ) );
153 mAttrNames.unite( handler->usedAttributes( layer, context ) );
162 for (
const std::unique_ptr< QgsFeatureRenderer > &renderer :
mRenderers )
164 if ( renderer->forceRasterRender() )
173 ( ( layer->
blendMode() != QPainter::CompositionMode_SourceOver )
212 mErrors.append( QObject::tr(
"No renderer for drawing." ) );
225 for (
const std::unique_ptr< QgsFeatureRenderer > &renderer :
mRenderers )
227 res = renderInternal( renderer.get() ) && res;
236 const bool isMainRenderer = renderer ==
mRenderer;
238 if ( renderer->
type() == QLatin1String(
"nullSymbol" ) )
242 if ( !isMainRenderer ||
252 mInterruptionChecker = std::make_unique< QgsVectorLayerRendererInterruptionChecker >( context );
253 bool usingEffect =
false;
280 bool needsPainterClipPath =
false;
282 if ( needsPainterClipPath )
283 context.
painter()->setClipPath( path, Qt::IntersectClip );
302 if ( featureFilterProvider )
306 if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String(
"TRUE" ) )
324 bool validTransform =
true;
351 double sourceHypothenuse = std::sqrt( minimumSrcPoint.sqrDist( maximumSrcPoint ) );
352 double targetHypothenuse = std::sqrt( minimumDstPoint.sqrDist( maximumDstPoint ) );
354 QgsDebugMsgLevel( QStringLiteral(
"Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
355 QgsDebugMsgLevel( QStringLiteral(
"Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
358 map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
364 validTransform =
false;
368 if ( validTransform )
403 drawRendererLevels( renderer, fit );
405 drawRenderer( renderer, fit );
409 mErrors.append( QStringLiteral(
"Data source invalid" ) );
424 const bool isMainRenderer = renderer ==
mRenderer;
430 std::unique_ptr< QgsGeometryEngine > clipEngine;
434 clipEngine->prepareGeometry();
463 bool rendered = renderer->
renderFeature( fet, context, -1, sel, drawMarker );
487 if ( !symbols.isEmpty() )
489 symbol = symbols.at( 0 );
513 QgsDebugMsg( QStringLiteral(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
514 .arg( fet.
id() ).arg( cse.
what() ) );
520 stopRenderer( renderer,
nullptr );
525 const bool isMainRenderer = renderer ==
mRenderer;
527 QHash< QgsSymbol *, QList<QgsFeature> > features;
540 std::unique_ptr< QgsExpressionContextScopePopper > scopePopper = std::make_unique< QgsExpressionContextScopePopper >( context.
expressionContext(), symbolScope );
543 std::unique_ptr< QgsGeometryEngine > clipEngine;
547 clipEngine->prepareGeometry();
559 qDebug(
"rendering stop!" );
560 stopRenderer( renderer, selRenderer );
577 if ( !features.contains( sym ) )
579 features.insert( sym, QList<QgsFeature>() );
581 features[sym].append( fet );
594 if ( !symbols.isEmpty() )
596 symbol = symbols.at( 0 );
616 if ( features.empty() )
619 stopRenderer( renderer, selRenderer );
626 for (
int i = 0; i < symbols.count(); i++ )
632 if ( level < 0 || level >= 1000 )
635 while ( level >= levels.count() )
637 levels[level].append( item );
645 for (
int l = 0; l < levels.count(); l++ )
648 for (
int i = 0; i < level.count(); i++ )
651 if ( !features.contains( item.
symbol() ) )
653 QgsDebugMsg( QStringLiteral(
"level item's symbol not found!" ) );
656 int layer = item.
layer();
657 QList<QgsFeature> &lst = features[item.
symbol()];
658 QList<QgsFeature>::iterator fit;
659 for ( fit = lst.begin(); fit != lst.end(); ++fit )
663 stopRenderer( renderer, selRenderer );
675 renderer->
renderFeature( *fit, context, layer, sel, drawMarker );
688 QgsDebugMsg( QStringLiteral(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
689 .arg( fet.
id() ).arg( cse.
what() ) );
695 stopRenderer( renderer, selRenderer );
709 void QgsVectorLayerRenderer::prepareLabeling(
QgsVectorLayer *layer, QSet<QString> &attributeNames )
734 if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
737 .setFilterRect( mContext.extent() )
742 int nFeatsToLabel = 0;
751 if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
753 emit labelingFontNotFound(
this, palyr.mTextFontFamily );
754 mLabelFontNotFoundNotified =
true;
759 void QgsVectorLayerRenderer::prepareDiagrams(
QgsVectorLayer *layer, QSet<QString> &attributeNames )
784 : mContext( context )
785 , mTimer( new QTimer( this ) )
787 connect( mTimer, &QTimer::timeout,
this, [ = ]
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const
Factory for label provider implementation.
Custom exception class for Coordinate Reference System related exceptions.
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Abstract interface for use by classes that filter the features or attributes of a layer.
virtual void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &featureRequest) const =0
Add additional filters to the feature request to further restrict the features returned by the reques...
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
void setInterruptionChecker(QgsFeedback *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped.
bool isValid() const
Will return if this iterator is valid.
An interface for objects which generate feature renderers for vector layers.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
virtual QString filter(const QgsFields &fields=QgsFields())
If a renderer does not require all the features this method may be overridden and return an expressio...
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
virtual bool usesEmbeddedSymbols() const
Returns true if the renderer uses embedded symbols for features.
void setVertexMarkerAppearance(int type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
bool usingSymbolLevels() const
virtual QString dump() const
Returns debug information about this renderer.
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
@ SymbolLevels
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
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.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
@ EmbeddedSymbols
Retrieve any embedded feature symbology (since QGIS 3.20)
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
const Flags & flags() const
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
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.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsWkbTypes::GeometryType type
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
The QgsLabelingEngine class provides map labeling functionality.
static QList< QgsMapClippingRegion > collectClippingRegionsForLayer(const QgsRenderContext &context, const QgsMapLayer *layer)
Collects the list of map clipping regions from a context which apply to a map layer.
static QPainterPath calculatePainterClipRegion(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, QgsMapLayerType layerType, bool &shouldClip)
Returns a QPainterPath representing the intersection of clipping regions from context which should be...
static QgsGeometry calculateLabelIntersectionGeometry(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, bool &shouldClip)
Returns the geometry representing the intersection of clipping regions from context which should be u...
static QgsGeometry calculateFeatureIntersectionGeometry(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, bool &shouldClip)
Returns the geometry representing the intersection of clipping regions from context which should be u...
static QgsGeometry calculateFeatureRequestGeometry(const QList< QgsMapClippingRegion > ®ions, const QgsRenderContext &context, bool &shouldFilter)
Returns the geometry representing the intersection of clipping regions from context.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
bool mReadyToCompose
The flag must be set to false in renderer's constructor if wants to use the smarter map redraws funct...
static constexpr int MAX_TIME_TO_USE_CACHED_PREVIEW_IMAGE
Maximum time (in ms) to allow display of a previously cached preview image while rendering layers,...
QString layerId() const
Gets access to the ID of the layer rendered by this class.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Perform transforms between map coordinates and device coordinates.
double mapUnitsPerPixel() const
Returns current map units per pixel.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
bool enabled() const
Returns whether the effect is enabled.
Contains settings for how a map layer will be labeled.
A class to represent a 2D point.
A rectangle specified with double values.
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
bool isEmpty() const
Returns true if the rectangle is empty.
QgsRectangle intersect(const QgsRectangle &rect) const
Returns the intersection with the given rectangle.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Contains information about the context of a rendering operation.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
void setFeatureClipGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features at render time.
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
QColor selectionColor() const
Returns the color to use when rendering selected features.
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr)
@ UseAdvancedEffects
Enable layer opacity and blending effects.
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
bool renderingStopped() const
Returns true if the rendering operation has been stopped and any ongoing rendering should be canceled...
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
An interface for classes which provider custom handlers for features rendered as part of a map render...
Scoped object for saving and restoring a QPainter object's state.
This class contains information about how to simplify geometries fetched from a QgsFeatureIterator.
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
void setThreshold(float threshold)
Sets the simplification threshold in pixels. Represents the maximum distance in pixels between two co...
void setForceLocalOptimization(bool localOptimization)
Sets whether the simplification executes after fetch the geometries from provider,...
void setMethodType(MethodType methodType)
Sets the simplification type.
@ OptimizeForRendering
Simplify using the map2pixel data to optimize the rendering of geometries.
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
int layer() const
The layer of this symbol level.
QgsSymbol * symbol() const
The symbol of this symbol level.
Abstract base class for all rendered symbols.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
void setColor(const QColor &color)
Sets the color for the symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures.
void setClipFeatureGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features to when registering them as diagrams.
virtual bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
static QgsGeometry getPointObstacleGeometry(QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols)
Returns the geometry for a point feature which should be used as an obstacle for labels.
virtual void registerFeature(const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
QgsVectorLayerRendererInterruptionChecker(const QgsRenderContext &context)
Constructor.
std::vector< std::unique_ptr< QgsFeatureRenderer > > mRenderers
QgsGeometry mLabelClipFeatureGeom
QElapsedTimer mElapsedTimer
QgsVectorLayerLabelProvider * mLabelProvider
used with new labeling engine (QgsLabelingEngine): provider for labels.
bool forceRasterRender() const override
Returns true if the renderer must be rendered to a raster paint device (e.g.
QgsVectorSimplifyMethod mSimplifyMethod
QgsGeometry mClipFeatureGeom
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
QPainter::CompositionMode mFeatureBlendMode
~QgsVectorLayerRenderer() override
bool mApplyClipGeometries
QgsVectorLayer * mLayer
The rendered layer.
QgsWkbTypes::GeometryType mGeometryType
bool mVertexMarkerOnlyForSelection
void setLayerRenderingTimeHint(int time) override
Sets approximate render time (in ms) for the layer to render.
bool render() override
Do the rendering (based on data stored in the class).
QgsFeatureRenderer * mRenderer
QgsGeometry mClipFilterGeom
QgsFeatureIds mSelectedFeatureIds
QSet< QString > mAttrNames
QList< QgsMapClippingRegion > mClippingRegions
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
std::unique_ptr< QgsVectorLayerRendererInterruptionChecker > mInterruptionChecker
bool mApplyLabelClipGeometries
std::unique_ptr< QgsVectorLayerFeatureSource > mSource
QgsVectorLayerDiagramProvider * mDiagramProvider
used with new labeling engine (QgsLabelingEngine): provider for diagrams.
Encapsulates the context in which a QgsVectorLayer's temporal capabilities will be applied.
void setLayer(QgsVectorLayer *layer)
Sets the associated layer.
Represents a vector layer which manages a vector based data sets.
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns temporal properties associated with the vector layer.
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
Q_INVOKABLE const QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
QList< const QgsFeatureRendererGenerator * > featureRendererGenerators() const
Returns a list of the feature renderer generators owned by the layer.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
This class contains information how to simplify geometries fetched from a vector layer.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
float threshold() const
Gets the simplification threshold of the vector layer managed.
@ GeometrySimplification
The geometries can be simplified using the current map2pixel context state.
@ FullSimplification
All simplification hints can be applied ( Geometry + AA-disabling )
@ NoSimplification
No simplification can be applied.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugMsgLevel(str, level)
QList< QgsSymbolLevel > QgsSymbolLevelOrder
QList< QgsSymbolLevelItem > QgsSymbolLevel
QList< QgsSymbol * > QgsSymbolList