32 : mSettings( settings )
33 , mLayerFilterExpression( layerFilterExpression )
34 , mOnlyExpressions( false )
43 : mSettings( settings )
44 , mLayerFilterExpression( layerFilterExpression )
45 , mOnlyExpressions( true )
53 tmpImage.setDotsPerMeterX( mSettings.
outputDpi() * 25.4 );
54 tmpImage.setDotsPerMeterY( mSettings.
outputDpi() * 25.4 );
55 QPainter painter( &tmpImage );
60 const auto constLayers = mSettings.
layers();
67 if ( !mOnlyExpressions )
71 mHitTest[vl] = SymbolSet();
72 mHitTestRuleKey[vl] = SymbolSet();
81 SymbolSet &usedSymbols = mHitTest[vl];
82 SymbolSet &usedSymbolsRuleKey = mHitTestRuleKey[vl];
83 runHitTestLayer( vl, usedSymbols, usedSymbolsRuleKey, context );
91 if ( !symbol || !layer || !mHitTest.contains( layer ) )
99 if ( !layer || !mHitTestRuleKey.contains( layer ) )
102 return mHitTestRuleKey.value( layer ).contains( ruleKey );
111 std::unique_ptr< QgsFeatureRenderer > r( vl->
renderer()->
clone() );
113 r->startRender( context, vl->
fields() );
116 if ( !mOnlyExpressions && !mPolygon.
isNull() )
127 std::unique_ptr< QgsGeometryEngine > polygonEngine;
128 if ( !mOnlyExpressions )
139 polygonEngine->prepareGeometry();
144 SymbolSet lUsedSymbols;
145 SymbolSet lUsedSymbolsRuleKey;
146 bool allExpressionFalse =
false;
147 const bool hasExpression = mLayerFilterExpression.contains( vl->
id() );
148 std::unique_ptr<QgsExpression> expr;
172 allExpressionFalse =
false;
177 const auto constLegendKeysForFeature = r->legendKeysForFeature( f, context );
178 for (
const QString &legendKey : constLegendKeysForFeature )
180 lUsedSymbolsRuleKey.insert( legendKey );
183 if ( moreSymbolsPerFeature )
185 const auto constOriginalSymbolsForFeature = r->originalSymbolsForFeature( f, context );
186 for (
QgsSymbol *s : constOriginalSymbolsForFeature )
194 QgsSymbol *s = r->originalSymbolForFeature( f, context );
201 if ( !allExpressionFalse )
204 usedSymbols = lUsedSymbols;
205 usedSymbolsRuleKey = lUsedSymbolsRuleKey;
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
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.
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.
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.
QgsWkbTypes::GeometryType type
static QgsGeometryEngine * createGeometryEngine(const QgsAbstractGeometry *geometry)
Creates and returns a new geometry engine representing the specified geometry.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
void run()
Runs the map hit test.
bool symbolVisible(QgsSymbol *symbol, QgsVectorLayer *layer) const
Tests whether a symbol is visible for a specified layer.
bool legendKeyVisible(const QString &ruleKey, QgsVectorLayer *layer) const
Tests whether a given legend key is visible for a specified layer.
QgsMapHitTest(const QgsMapSettings &settings, const QgsGeometry &polygon=QgsGeometry(), const QgsMapHitTest::LayerFilterExpression &layerFilterExpression=QgsMapHitTest::LayerFilterExpression())
QMap< QString, QString > LayerFilterExpression
Maps an expression string to a layer id.
Restore overridden layer style on destruction.
Base class for all map layer types.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
QgsCoordinateReferenceSystem crs
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
The QgsMapSettings class contains configuration for rendering of the map.
double scale() const
Returns the calculated map scale.
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
QList< QgsMapLayer * > layers() const
Returns the list of layers which will be rendered in the map.
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
QMap< QString, QString > layerStyleOverrides() const
Returns the map of map layer style overrides (key: layer ID, value: style name) where a different sty...
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Contains information about the context of a rendering operation.
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
Abstract base class for all rendered symbols.
void stopRender(QgsRenderContext &context)
Ends the rendering process.
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.