QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
25 , mRenderer( layer->renderer()->clone() )
26 , mExpressionContext( context )
27 , mWithFids( storeSymbolFids )
28 , mFeatureCount( layer->featureCount() )
40 mSymbolFeatureCountMap.clear();
41 mSymbolFeatureIdMap.clear();
43 QgsLegendSymbolList::const_iterator symbolIt = symbolList.constBegin();
45 for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
47 mSymbolFeatureCountMap.insert( symbolIt->ruleKey(), 0 );
49 mSymbolFeatureIdMap.insert( symbolIt->ruleKey(),
QgsFeatureIds() );
53 if ( mFeatureCount > 0 )
55 mFeedback = std::make_unique< QgsFeedback >();
57 int featuresCounted = 0;
65 if ( !mRenderer->filterNeedsGeometry() )
74 mRenderer->startRender( renderContext, mSource->fields() );
82 const QSet<QString> featureKeyList = mRenderer->legendKeysForFeature( f, renderContext );
83 for (
const QString &key : featureKeyList )
85 mSymbolFeatureCountMap[key] += 1;
87 mSymbolFeatureIdMap[key].insert( f.
id() );
91 const double p = (
static_cast< double >( featuresCounted ) / mFeatureCount ) * 100;
100 mRenderer->stopRender( renderContext );
106 mRenderer->stopRender( renderContext );
124 return mSymbolFeatureCountMap;
129 return mSymbolFeatureCountMap.value( legendKey, -1 );
134 return mSymbolFeatureIdMap;
139 return mSymbolFeatureIdMap.value( symbolkey,
QgsFeatureIds() );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContext & expressionContext()
Gets the expression context.
QHash< QString, QgsFeatureIds > symbolFeatureIdMap() const
Returns the QgsFeatureIds for each symbol.
long long featureCount(const QString &legendKey) const
Returns the feature count for a particular legendKey.
Contains information about the context of a rendering operation.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureIds featureIds(const QString &symbolkey) const
Returns the feature Ids for a particular legendKey.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the expression engine to check if expressio...
int scopeCount() const
Returns the number of scopes contained in the context.
virtual void cancel()
Notifies the task that it should terminate.
This class wraps a request for features to a vector layer (or directly its vector data provider).
void setProgress(double progress)
Sets the task's current progress.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly by the iterator to check if it should be cance...
QSet< QgsFeatureId > QgsFeatureIds
~QgsVectorLayerFeatureCounter() override
QHash< QString, long long > symbolFeatureCountMap() const
Returns the count for each symbol.
void setRendererScale(double scale)
Sets the renderer map scale.
bool run() override
Calculates the feature count and Ids per symbol.
void cancel() override
Notifies the task that it should terminate.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
Partial snapshot of vector layer's state (only the members necessary for access to features)
QgsVectorLayerFeatureCounter(QgsVectorLayer *layer, const QgsExpressionContext &context=QgsExpressionContext(), bool storeSymbolFids=false)
Create a new feature counter for layer.
void symbolsCounted()
Emitted when the symbols have been counted.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Wrapper for iterator of features from vector data provider or vector layer.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
double progress() const
Returns the task's progress (between 0.0 and 100.0)
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
bool isCanceled() const
Will return true if task should terminate ASAP.
Abstract base class for long running background tasks. Tasks can be controlled directly,...