Improve docs and python bindings for feature count

This commit is contained in:
Matthias Kuhn 2017-05-10 14:05:55 +02:00
parent d452f7f21e
commit ed747edc94
5 changed files with 38 additions and 6 deletions

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

@ -77,3 +77,8 @@ QHash<QString, long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const
{
return mSymbolFeatureCountMap;
}
long QgsVectorLayerFeatureCounter::featureCount( const QString &legendKey ) const
{
return mSymbolFeatureCountMap.value( legendKey, -1 );
}

View File

@ -36,6 +36,12 @@ class CORE_EXPORT QgsVectorLayerFeatureCounter : public QgsTask
*/
QHash<QString, long> 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:
/**