44 : mSettings( settings )
55 tmpImage.setDotsPerMeterX(
static_cast< int >( std::round( mapSettings.
outputDpi() * 25.4 ) ) );
56 tmpImage.setDotsPerMeterY(
static_cast< int >( std::round( mapSettings.
outputDpi() * 25.4 ) ) );
57 QPainter painter( &tmpImage );
62 const QList< QgsMapLayer * > layers = mSettings.
layers();
84 SymbolSet &usedSymbols = mHitTest[vl->
id()];
85 SymbolSet &usedSymbolsRuleKey = mHitTestRuleKey[vl->
id()];
91 std::unique_ptr< QgsVectorLayerFeatureSource > source = std::make_unique< QgsVectorLayerFeatureSource >( vl );
92 runHitTestFeatureSource( source.get(),
94 usedSymbols, usedSymbolsRuleKey, context,
103 return mHitTestRuleKey;
107QMap<QString, QList<QString> > QgsMapHitTest::resultsPy()
const
109 QMap<QString, QList<QString> > res;
110 for (
auto it = mHitTestRuleKey.begin(); it != mHitTestRuleKey.end(); ++it )
112 res.insert( it.key(), qgis::setToList( it.value() ) );
120 if ( !symbol || !layer )
123 auto it = mHitTest.constFind( layer->
id() );
124 if ( it == mHitTest.constEnd() )
135 auto it = mHitTestRuleKey.constFind( layer->
id() );
136 if ( it == mHitTestRuleKey.constEnd() )
139 return it->contains( ruleKey );
143 const QString &layerId,
146 SymbolSet &usedSymbols,
147 SymbolSet &usedSymbolsRuleKey,
152 std::unique_ptr< QgsFeatureRenderer > r( renderer->
clone() );
154 r->startRender( context, fields );
157 if ( r->canSkipRender() )
159 r->stopRender( context );
164 QSet< QString > remainingKeysToFind = r->legendKeys();
165 if ( remainingKeysToFind.empty() )
167 r->stopRender( context );
175 const QString rendererFilterExpression = r->filter( fields );
176 if ( !rendererFilterExpression.isEmpty() )
183 QSet<QString> requiredAttributes = r->usedAttributes( context );
193 r->stopRender( context );
198 if (
auto it = layerFilterExpressions.constFind( layerId ); it != layerFilterExpressions.constEnd() )
200 const QString expression = *it;
204 requiredAttributes.unite( expr.referencedColumns() );
210 std::unique_ptr< QgsGeometryEngine > polygonEngine;
213 if ( transformedPolygon.
isNull() )
222 polygonEngine->prepareGeometry();
228 r->stopRender( context );
235 usedSymbolsRuleKey.clear();
256 const QSet< QString > legendKeysForFeature = r->legendKeysForFeature( f, context );
257 for (
const QString &legendKey : legendKeysForFeature )
259 usedSymbolsRuleKey.insert( legendKey );
260 remainingKeysToFind.remove( legendKey );
263 if ( moreSymbolsPerFeature )
265 const QgsSymbolList originalSymbolsForFeature = r->originalSymbolsForFeature( f, context );
266 for (
QgsSymbol *s : originalSymbolsForFeature )
274 QgsSymbol *s = r->originalSymbolForFeature( f, context );
279 if ( remainingKeysToFind.empty() )
295 , mSettings( settings )
306QMap<QString, QList<QString> > QgsMapHitTestTask::resultsPy()
const
308 QMap<QString, QList<QString> > res;
309 for (
auto it = mResults.begin(); it != mResults.end(); ++it )
311 res.insert( it.key(), qgis::setToList( it.value() ) );
317void QgsMapHitTestTask::prepare()
321 const QList< QgsMapLayer * > layers = mSettings.
layers();
343 PreparedLayerData layerData;
344 layerData.source = std::make_unique< QgsVectorLayerFeatureSource >( vl );
345 layerData.layerId = vl->
id();
346 layerData.fields = vl->
fields();
349 layerData.extent = extent;
352 mPreparedData.emplace_back( std::move( layerData ) );
366 mFeedback = std::make_unique< QgsFeedback >();
369 std::unique_ptr< QgsMapHitTest > hitTest = std::make_unique< QgsMapHitTest >( mSettings );
375 tmpImage.setDotsPerMeterX(
static_cast< int >( std::round( mapSettings.
outputDpi() * 25.4 ) ) );
376 tmpImage.setDotsPerMeterY(
static_cast< int >( std::round( mapSettings.
outputDpi() * 25.4 ) ) );
377 QPainter painter( &tmpImage );
383 std::size_t layerIdx = 0;
384 const std::size_t totalCount = mPreparedData.size();
385 for (
auto &layerData : mPreparedData )
387 mFeedback->setProgress(
static_cast< double >( layerIdx ) /
static_cast< double >( totalCount ) * 100.0 );
388 if ( mFeedback->isCanceled() )
391 QgsMapHitTest::SymbolSet &usedSymbols = hitTest->mHitTest[layerData.layerId];
392 QgsMapHitTest::SymbolSet &usedSymbolsRuleKey = hitTest->mHitTestRuleKey[layerData.layerId];
395 context.
setExtent( layerData.extent.boundingBox() );
400 hitTest->runHitTestFeatureSource( layerData.source.get(),
403 layerData.renderer.get(),
412 mResults = hitTest->mHitTestRuleKey;
@ SkipVisibilityCheck
If set, the standard visibility check should be skipped.
Base class that can be used for any class that is capable of returning features.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Gets an iterator for features matching the specified request.
RAII class to pop scope from an expression context on destruction.
Single scope for storing variables and functions for use within a QgsExpressionContext.
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)
@ MoreSymbolsPerFeature
May use more than one symbol to render a feature: symbolsForFeature() will return them.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
This class wraps a request for features to a vector layer (or directly its vector data provider).
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.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the iterator to check if it should be cance...
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
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.
bool isCanceled() const
Tells whether the operation has been canceled already.
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
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.
Contains settings relating to filtering the contents of QgsLayerTreeModel and views.
QgsMapSettings & mapSettings()
Returns the map settings used to filter the legend content.
QList< QgsMapLayer * > layers() const
Returns the layers which should be shown in the legend.
Qgis::LayerTreeFilterFlags flags() const
Returns the filter flags.
QMap< QString, QString > layerFilterExpressions() const
Returns the map of layer IDs to legend filter expression.
void setFilterPolygon(const QgsGeometry &polygon)
Sets the optional filter polygon, used when testing for symbols to show in the legend.
void setFlags(Qgis::LayerTreeFilterFlags flags)
Sets the filter flags.
void setLayerFilterExpressions(const QMap< QString, QString > &expressions)
Sets the map of layer IDs to legend filter expression.
QgsGeometry combinedVisibleExtentForLayer(const QgsMapLayer *layer)
Returns the combined visible extent for a layer.
QMap< QString, QSet< QString > > results() const
Returns the hit test results, which are a map of layer ID to visible symbol legend keys.
QgsMapHitTestTask(const QgsLayerTreeFilterSettings &settings)
Constructor for QgsMapHitTestTask, using the specified filter settings.
bool run() override
Performs the task's operation.
PRIVATE void cancel() override
Notifies the task that it should terminate.
void run()
Runs the map hit test.
PRIVATE 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, QSet< QString > > results() const
Returns the hit test results, which are a map of layer ID to visible symbol legend keys.
QMap< QString, QString > LayerFilterExpression
Maps an expression string to a layer id.
Restore overridden layer style on destruction.
void setOverrideStyle(const QString &style)
Temporarily apply a different style to the layer.
Base class for all map layer types.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
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
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...
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.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
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
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.
Abstract base class for long running background tasks.
void progressChanged(double progress)
Will be emitted by task when its progress changes.
virtual void cancel()
Notifies the task that it should terminate.
Represents a vector layer which manages a vector based data sets.
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.
QList< QgsSymbol * > QgsSymbolList