QgsVectorLayerFeatureCounter class

Counts the features in a QgsVectorLayer in task.

You should most likely not use this directly and instead call QgsVectorLayer::countSymbolFeatures() and connect to the signal QgsVectorLayer::symbolFeatureCountMapChanged().

Base classes

class QgsTask
Abstract base class for long running background tasks.

Constructors, destructors, conversion operators

QgsVectorLayerFeatureCounter(QgsVectorLayer* layer, const QgsExpressionContext& context = QgsExpressionContext())
Create a new feature counter for layer.

Public functions

auto featureCount(const QString& legendKey) const -> long
Gets the feature count for a particular legendKey.
auto run() -> bool override
Performs the task's operation.
auto symbolFeatureCountMap() const -> QHash<QString, long>
Gets the count for each symbol.

Signals

void symbolsCounted()
Emitted when the symbols have been counted.

Function documentation

long QgsVectorLayerFeatureCounter::featureCount(const QString& legendKey) const

Gets the feature count for a particular legendKey.

If the key has not been found, -1 will be returned.

bool QgsVectorLayerFeatureCounter::run() override

Performs the task's operation.

This method will be called when the task commences (ie via calling start() ), and subclasses should implement the operation they wish to perform in the background within this method.

A task must return a boolean value to indicate whether the task was completed successfully or terminated before completion.

QHash<QString, long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const

Gets the count for each symbol.

Only valid after the symbolsCounted() signal has been emitted.