Skip to content

Commit

Permalink
Improve docs and python bindings for feature count
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed May 11, 2017
1 parent d452f7f commit ed747ed
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
14 changes: 11 additions & 3 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions python/core/qgsvectorlayerfeaturecounter.sip
Expand Up @@ -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();
Expand Down
12 changes: 9 additions & 3 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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();

Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayerfeaturecounter.cpp
Expand Up @@ -77,3 +77,8 @@ QHash<QString, long> QgsVectorLayerFeatureCounter::symbolFeatureCountMap() const
{
return mSymbolFeatureCountMap;
}

long QgsVectorLayerFeatureCounter::featureCount( const QString &legendKey ) const
{
return mSymbolFeatureCountMap.value( legendKey, -1 );
}
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayerfeaturecounter.h
Expand Up @@ -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:

/**
Expand Down

0 comments on commit ed747ed

Please sign in to comment.