QgsVectorLayer, countSymbolFeatures return QgsVectorLayerFeatureCounter

This commit is contained in:
rldhont 2017-09-14 13:03:56 +02:00
parent 08cacd4a1e
commit f88af6d55f
3 changed files with 22 additions and 20 deletions

View File

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

View File

@ -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 )
@ -758,7 +758,7 @@ bool QgsVectorLayer::countSymbolFeatures()
QgsApplication::taskManager()->addTask( mFeatureCounter );
}
return true;
return mFeatureCounter;
}
void QgsVectorLayer::updateExtents( bool force )

View File

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