QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
49 , mFields( layer->fields() )
88 QString markerTypeString = settings.
value( QStringLiteral(
"qgis/digitizing/marker_style" ),
"Cross" ).toString();
89 if ( markerTypeString == QLatin1String(
"Cross" ) )
93 else if ( markerTypeString == QLatin1String(
"SemiTransparentCircle" ) )
121 mAttrNames.unite( handler->usedAttributes( layer, context ) );
148 mErrors.append( QObject::tr(
"No renderer for drawing." ) );
163 mInterruptionChecker = qgis::make_unique< QgsVectorLayerRendererInterruptionChecker >( context );
164 bool usingEffect =
false;
196 if ( featureFilterProvider )
200 if ( !rendererFilter.isEmpty() && rendererFilter != QLatin1String(
"TRUE" ) )
213 bool validTransform =
true;
240 double sourceHypothenuse = std::sqrt( minimumSrcPoint.
sqrDist( maximumSrcPoint ) );
241 double targetHypothenuse = std::sqrt( minimumDstPoint.
sqrDist( maximumDstPoint ) );
243 QgsDebugMsgLevel( QStringLiteral(
"Simplify - SourceHypothenuse=%1" ).arg( sourceHypothenuse ), 4 );
244 QgsDebugMsgLevel( QStringLiteral(
"Simplify - TargetHypothenuse=%1" ).arg( targetHypothenuse ), 4 );
247 map2pixelTol *= ( sourceHypothenuse / targetHypothenuse );
253 validTransform =
false;
257 if ( validTransform )
292 drawRendererLevels( fit );
298 mErrors.append( QStringLiteral(
"Data source invalid" ) );
353 if ( !symbols.isEmpty() )
355 symbol = symbols.at( 0 );
373 QgsDebugMsg( QStringLiteral(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
374 .arg( fet.
id() ).arg( cse.
what() ) );
380 stopRenderer(
nullptr );
385 QHash< QgsSymbol *, QList<QgsFeature> > features;
398 std::unique_ptr< QgsExpressionContextScopePopper > scopePopper = qgis::make_unique< QgsExpressionContextScopePopper >( context.
expressionContext(), symbolScope );
406 qDebug(
"rendering stop!" );
407 stopRenderer( selRenderer );
421 if ( !features.contains( sym ) )
423 features.insert( sym, QList<QgsFeature>() );
425 features[sym].append( fet );
438 if ( !symbols.isEmpty() )
440 symbol = symbols.at( 0 );
457 if ( features.empty() )
460 stopRenderer( selRenderer );
467 for (
int i = 0; i < symbols.count(); i++ )
473 if ( level < 0 || level >= 1000 )
476 while ( level >= levels.count() )
478 levels[level].append( item );
483 for (
int l = 0; l < levels.count(); l++ )
486 for (
int i = 0; i < level.count(); i++ )
489 if ( !features.contains( item.
symbol() ) )
491 QgsDebugMsg( QStringLiteral(
"level item's symbol not found!" ) );
494 int layer = item.
layer();
495 QList<QgsFeature> &lst = features[item.
symbol()];
496 QList<QgsFeature>::iterator fit;
497 for ( fit = lst.begin(); fit != lst.end(); ++fit )
501 stopRenderer( selRenderer );
518 QgsDebugMsg( QStringLiteral(
"Failed to transform a point while drawing a feature with ID '%1'. Ignoring this feature. %2" )
519 .arg( fet.
id() ).arg( cse.
what() ) );
525 stopRenderer( selRenderer );
543 void QgsVectorLayerRenderer::prepareLabeling(
QgsVectorLayer *layer, QSet<QString> &attributeNames )
564 #if 0 // TODO: limit of labels, font not found
568 if ( palyr.limitNumLabels && palyr.maxNumLabels > 0 )
571 .setFilterRect( mContext.extent() )
576 int nFeatsToLabel = 0;
585 if ( !palyr.mTextFontFound && !mLabelFontNotFoundNotified )
587 emit labelingFontNotFound(
this, palyr.mTextFontFamily );
588 mLabelFontNotFoundNotified =
true;
593 void QgsVectorLayerRenderer::prepareDiagrams(
QgsVectorLayer *layer, QSet<QString> &attributeNames )
618 : mContext( context )
619 , mTimer(
new QTimer(
this ) )
621 connect( mTimer, &QTimer::timeout,
this, [ = ]
623 if ( mContext.renderingStopped() )
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
Q_INVOKABLE QgsVectorLayerEditBuffer * editBuffer()
Buffer with uncommitted editing operations. Only valid after editing has been turned on.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) override
Gets an iterator for features matching the specified request.
QgsVectorSimplifyMethod mSimplifyMethod
bool diagramsEnabled() const
Returns whether the layer contains diagrams which are enabled and should be drawn.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
@ NoSimplification
No simplification can be applied.
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
QSet< QString > mAttrNames
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
QgsFeatureRenderer * mRenderer
QList< QgsSymbolLevelItem > QgsSymbolLevel
QgsExpressionContext & expressionContext()
Gets the expression context.
double mapUnitsPerPixel() const
Returns current map units per pixel.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
std::unique_ptr< QgsVectorLayerRendererInterruptionChecker > mInterruptionChecker
#define QgsDebugMsgLevel(str, level)
QgsWkbTypes::GeometryType mGeometryType
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
QgsVectorLayerFeatureSource * mSource
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine....
virtual QgsFeatureRenderer::Capabilities capabilities()
Returns details about internals of this renderer.
double xMaximum() const
Returns the x maximum value (right side of rectangle).
bool hasRenderedFeatureHandlers() const
Returns true if the context has any rendered feature handlers.
bool mVertexMarkerOnlyForSelection
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsVectorLayerRenderer(QgsVectorLayer *layer, QgsRenderContext &context)
void setThreshold(float threshold)
Sets the simplification threshold in pixels. Represents the maximum distance in pixels between two co...
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
QgsRenderContext * renderContext()
Returns the render context associated with the renderer.
virtual QSet< QString > usedAttributes(const QgsRenderContext &context) const =0
Returns a list of attributes required by this renderer.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
@ FullSimplification
All simplification hints can be applied ( Geometry + AA-disabling )
int layer() const
The layer of this symbol level.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
void setVertexMarkerAppearance(int type, double size)
Sets type and size of editing vertex markers for subsequent rendering.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
@ SymbolLevels
Rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
QgsSymbol * symbol() const
The symbol of this symbol level.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
QgsVectorLayer * mLayer
The rendered layer.
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...
QgsVectorLayerRendererInterruptionChecker(const QgsRenderContext &context)
Constructor.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
bool simplifyDrawingCanbeApplied(const QgsRenderContext &renderContext, QgsVectorSimplifyMethod::SimplifyHint simplifyHint) const
Returns whether the VectorLayer can apply the specified simplification hint.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
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.
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...
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
QgsFeatureRequest & combineFilterExpression(const QString &expression)
Modifies the existing filter expression to add an additional expression filter.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns temporal properties associated with the vector layer.
@ OptimizeForRendering
Simplify using the map2pixel data to optimize the rendering of geometries.
QString layerId() const
Gets access to the ID of the layer rendered by this class.
QList< QgsSymbol * > QgsSymbolList
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
const QgsAbstractVectorLayerLabeling * labeling() const
Access to const labeling configuration.
virtual QgsSymbolList originalSymbolsForFeature(const QgsFeature &feature, QgsRenderContext &context) const
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
const Q_INVOKABLE QgsFeatureIds & selectedFeatureIds() const
Returns a list of the selected features IDs in this layer.
void setLayer(QgsVectorLayer *layer)
Sets the associated layer.
virtual QgsSymbolList symbols(QgsRenderContext &context) const
Returns list of symbols used by the renderer.
void setTolerance(double tolerance)
Sets the tolerance of simplification in map units. Represents the maximum distance in map units betwe...
bool usingSymbolLevels() const
virtual QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const =0
To be overridden.
float threshold() const
Gets the simplification threshold of the vector layer managed.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
QPainter::CompositionMode mFeatureBlendMode
QgsFeatureRequest & setSimplifyMethod(const QgsSimplifyMethod &simplifyMethod)
Set a simplification method for geometries that will be fetched.
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
bool forceLocalOptimization() const
Gets where the simplification executes, after fetch the geometries from provider, or when supported,...
double yMaximum() const
Returns the y maximum value (top side of rectangle).
Single scope for storing variables and functions for use within a QgsExpressionContext....
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings for fast rendering of features.
const QgsVectorSimplifyMethod & vectorSimplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
void setForceLocalOptimization(bool localOptimization)
Sets whether the simplification executes after fetch the geometries from provider,...
QgsVectorLayerDiagramProvider * mDiagramProvider
used with new labeling engine (QgsLabelingEngine): provider for diagrams.
The QgsLabelingEngine class provides map labeling functionality. The input for the engine is a list o...
QString toString(int precision=16) const
Returns a string representation of form xmin,ymin : xmax,ymax Coordinates will be truncated to the sp...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
virtual QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const
Factory for label provider implementation.
QColor selectionColor() const
Returns the color to use when rendering selected features.
QgsLabelingEngine * labelingEngine() const
Gets access to new labeling engine (may be nullptr)
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
QgsPointXY center() const
Returns the center point of the rectangle.
bool nextFeature(QgsFeature &f)
void setColor(const QColor &color)
Sets the color for the symbol.
bool hasGeometry() const
Returns true if the feature has an associated geometry.
bool orderByEnabled() const
Returns whether custom ordering will be applied before features are processed by this renderer.
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.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
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.
void setMethodType(MethodType methodType)
Sets the simplification type.
QList< QgsSymbolLevel > QgsSymbolLevelOrder
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
QgsFeatureIds mSelectedFeatureIds
QgsFeatureRequest & setOrderBy(const OrderBy &orderBy)
Set a list of order by clauses.
QgsVectorLayerLabelProvider * mLabelProvider
used with new labeling engine (QgsLabelingEngine): provider for labels.
SimplifyHints simplifyHints() const
Gets the simplification hints of the vector layer managed.
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 QString dump() const
Returns debug information about this renderer.
void setInterruptionChecker(QgsFeedback *interruptionChecker)
Attach an object that can be queried regularly by the iterator to check if it must stopped.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the renderer.
virtual bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
QPainter * painter()
Returns the destination QPainter for the render operation.
bool enabled() const
Returns whether the effect is enabled.
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.
QgsSymbol * symbol() const
Returns the symbol which will be rendered for every feature.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
QgsWkbTypes::GeometryType type
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool isEmpty() const
Returns true if the rectangle is empty.
QgsFeedback * feedback() const override
Access to feedback object of the layer renderer (may be nullptr)
@ GeometrySimplification
The geometries can be simplified using the current map2pixel context state.
bool isValid() const
Will return if this iterator is valid.
bool render() override
Do the rendering (based on data stored in the class)
double xMinimum() const
Returns the x minimum value (left side of rectangle).
bool labelsEnabled() const
Returns whether the layer contains labels which are enabled and should be drawn.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
~QgsVectorLayerRenderer() override
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QgsFeatureRenderer * renderer()
Returns renderer.