Skip to content

Commit

Permalink
QgsVectorLayer, countSymbolFeatures return QgsVectorLayerFeatureCounter
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Sep 19, 2017
1 parent 08cacd4 commit f88af6d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
15 changes: 8 additions & 7 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -854,20 +854,21 @@ Return the provider type for this layer
.. versionadded:: 2.10
%End

bool countSymbolFeatures();
QgsVectorLayerFeatureCounter *countSymbolFeatures();
%Docstring
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.
The method will return the feature counter task. 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().
If the count features for symbols has been already done a
None is returned. If you need to wait for the results,
you can call waitForFinished() on the feature counter.

.. versionadded:: 3.0
:rtype: bool
:rtype: QgsVectorLayerFeatureCounter
%End

virtual bool setSubsetString( const QString &subset );
Expand Down
14 changes: 7 additions & 7 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -726,27 +726,27 @@ class QgsVectorLayerInterruptionCheckerDuringCountSymbolFeatures: public QgsInte
QProgressDialog *mDialog = nullptr;
};

bool QgsVectorLayer::countSymbolFeatures()
QgsVectorLayerFeatureCounter *QgsVectorLayer::countSymbolFeatures()
{
if ( mSymbolFeatureCounted )
return true;
if ( mSymbolFeatureCounted || mFeatureCounter )
return mFeatureCounter;

mSymbolFeatureCountMap.clear();

if ( !mValid )
{
QgsDebugMsg( "invoked with invalid layer" );
return false;
return mFeatureCounter;
}
if ( !mDataProvider )
{
QgsDebugMsg( "invoked with null mDataProvider" );
return false;
return mFeatureCounter;
}
if ( !mRenderer )
{
QgsDebugMsg( "invoked with null mRenderer" );
return false;
return mFeatureCounter;
}

if ( !mFeatureCounter )
Expand All @@ -758,7 +758,7 @@ bool QgsVectorLayer::countSymbolFeatures()
QgsApplication::taskManager()->addTask( mFeatureCounter );
}

return true;
return mFeatureCounter;
}

void QgsVectorLayer::updateExtents( bool force )
Expand Down
13 changes: 7 additions & 6 deletions src/core/qgsvectorlayer.h
Expand Up @@ -836,16 +836,17 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte

/**
* 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.
* The method will return the feature counter task. 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().
* \note If the count features for symbols has been already done a
* nullptr is returned. If you need to wait for the results,
* you can call waitForFinished() on the feature counter.
*
* \since This is asynchronous since QGIS 3.0
*/
bool countSymbolFeatures();
QgsVectorLayerFeatureCounter *countSymbolFeatures();

/**
* Set the string (typically sql) used to define a subset of the layer
Expand Down

0 comments on commit f88af6d

Please sign in to comment.