diff --git a/python/core/qgsvectorlayer.sip b/python/core/qgsvectorlayer.sip index 702a6739fa3..751a7ba2ea6 100644 --- a/python/core/qgsvectorlayer.sip +++ b/python/core/qgsvectorlayer.sip @@ -843,9 +843,17 @@ Return the provider type for this layer bool countSymbolFeatures(); %Docstring - Count features for symbols. Feature counts may be get by featureCount(). - \param showProgress show progress dialog - :return: true if calculated, false if failed or was canceled by user + Count features for symbols. + The method will return immediately. You will need to connect to the + symbolFeatureCountMapChanged() signal to be notified when the freshly updated + feature counts are ready. + +.. note:: + + If you need to wait for the results, create and start your own QgsVectorLayerFeatureCounter + task and call waitForFinished(). + +.. versionadded:: 3.0 :rtype: bool %End diff --git a/python/core/qgsvectorlayerfeaturecounter.sip b/python/core/qgsvectorlayerfeaturecounter.sip index 9e0d2c8e685..609c80b85b6 100644 --- a/python/core/qgsvectorlayerfeaturecounter.sip +++ b/python/core/qgsvectorlayerfeaturecounter.sip @@ -32,6 +32,13 @@ class QgsVectorLayerFeatureCounter : QgsTask virtual bool run(); + long featureCount( const QString &legendKey ) const; +%Docstring + Get the feature count for a particular ``legendKey``. + If the key has not been found, -1 will be returned. + :rtype: long +%End + signals: void symbolsCounted(); diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h index fc1dd9103fa..875d797088b 100644 --- a/src/core/qgsvectorlayer.h +++ b/src/core/qgsvectorlayer.h @@ -807,9 +807,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false ); /** - * Count features for symbols. Feature counts may be get by featureCount(). - * \param showProgress show progress dialog - * \returns true if calculated, false if failed or was canceled by user + * Count features for symbols. + * The method will return immediately. You will need to connect to the + * symbolFeatureCountMapChanged() signal to be notified when the freshly updated + * feature counts are ready. + * + * \note If you need to wait for the results, create and start your own QgsVectorLayerFeatureCounter + * task and call waitForFinished(). + * + * \since This is asynchroneous since QGIS 3.0 */ bool countSymbolFeatures(); diff --git a/src/core/qgsvectorlayerfeaturecounter.cpp b/src/core/qgsvectorlayerfeaturecounter.cpp index e21fe7b11d3..4825002eb21 100644 --- a/src/core/qgsvectorlayerfeaturecounter.cpp +++ b/src/core/qgsvectorlayerfeaturecounter.cpp @@ -77,3 +77,8 @@ QHash QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const { return mSymbolFeatureCountMap; } + +long QgsVectorLayerFeatureCounter::featureCount( const QString &legendKey ) const +{ + return mSymbolFeatureCountMap.value( legendKey, -1 ); +} diff --git a/src/core/qgsvectorlayerfeaturecounter.h b/src/core/qgsvectorlayerfeaturecounter.h index f3d28808f1d..fba4738364b 100644 --- a/src/core/qgsvectorlayerfeaturecounter.h +++ b/src/core/qgsvectorlayerfeaturecounter.h @@ -36,6 +36,12 @@ class CORE_EXPORT QgsVectorLayerFeatureCounter : public QgsTask */ QHash symbolFeatureCountMap() const SIP_SKIP; + /** + * Get the feature count for a particular \a legendKey. + * If the key has not been found, -1 will be returned. + */ + long featureCount( const QString &legendKey ) const; + signals: /**