Skip to content

Commit f88af6d

Browse files
committed
QgsVectorLayer, countSymbolFeatures return QgsVectorLayerFeatureCounter
1 parent 08cacd4 commit f88af6d

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

python/core/qgsvectorlayer.sip

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -854,20 +854,21 @@ Return the provider type for this layer
854854
.. versionadded:: 2.10
855855
%End
856856

857-
bool countSymbolFeatures();
857+
QgsVectorLayerFeatureCounter *countSymbolFeatures();
858858
%Docstring
859859
Count features for symbols.
860-
The method will return immediately. You will need to connect to the
861-
symbolFeatureCountMapChanged() signal to be notified when the freshly updated
862-
feature counts are ready.
860+
The method will return the feature counter task. You will need to
861+
connect to the symbolFeatureCountMapChanged() signal to be
862+
notified when the freshly updated feature counts are ready.
863863

864864
.. note::
865865

866-
If you need to wait for the results, create and start your own QgsVectorLayerFeatureCounter
867-
task and call waitForFinished().
866+
If the count features for symbols has been already done a
867+
None is returned. If you need to wait for the results,
868+
you can call waitForFinished() on the feature counter.
868869

869870
.. versionadded:: 3.0
870-
:rtype: bool
871+
:rtype: QgsVectorLayerFeatureCounter
871872
%End
872873

873874
virtual bool setSubsetString( const QString &subset );

src/core/qgsvectorlayer.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,27 +726,27 @@ class QgsVectorLayerInterruptionCheckerDuringCountSymbolFeatures: public QgsInte
726726
QProgressDialog *mDialog = nullptr;
727727
};
728728

729-
bool QgsVectorLayer::countSymbolFeatures()
729+
QgsVectorLayerFeatureCounter *QgsVectorLayer::countSymbolFeatures()
730730
{
731-
if ( mSymbolFeatureCounted )
732-
return true;
731+
if ( mSymbolFeatureCounted || mFeatureCounter )
732+
return mFeatureCounter;
733733

734734
mSymbolFeatureCountMap.clear();
735735

736736
if ( !mValid )
737737
{
738738
QgsDebugMsg( "invoked with invalid layer" );
739-
return false;
739+
return mFeatureCounter;
740740
}
741741
if ( !mDataProvider )
742742
{
743743
QgsDebugMsg( "invoked with null mDataProvider" );
744-
return false;
744+
return mFeatureCounter;
745745
}
746746
if ( !mRenderer )
747747
{
748748
QgsDebugMsg( "invoked with null mRenderer" );
749-
return false;
749+
return mFeatureCounter;
750750
}
751751

752752
if ( !mFeatureCounter )
@@ -758,7 +758,7 @@ bool QgsVectorLayer::countSymbolFeatures()
758758
QgsApplication::taskManager()->addTask( mFeatureCounter );
759759
}
760760

761-
return true;
761+
return mFeatureCounter;
762762
}
763763

764764
void QgsVectorLayer::updateExtents( bool force )

src/core/qgsvectorlayer.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -836,16 +836,17 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
836836

837837
/**
838838
* Count features for symbols.
839-
* The method will return immediately. You will need to connect to the
840-
* symbolFeatureCountMapChanged() signal to be notified when the freshly updated
841-
* feature counts are ready.
839+
* The method will return the feature counter task. You will need to
840+
* connect to the symbolFeatureCountMapChanged() signal to be
841+
* notified when the freshly updated feature counts are ready.
842842
*
843-
* \note If you need to wait for the results, create and start your own QgsVectorLayerFeatureCounter
844-
* task and call waitForFinished().
843+
* \note If the count features for symbols has been already done a
844+
* nullptr is returned. If you need to wait for the results,
845+
* you can call waitForFinished() on the feature counter.
845846
*
846847
* \since This is asynchronous since QGIS 3.0
847848
*/
848-
bool countSymbolFeatures();
849+
QgsVectorLayerFeatureCounter *countSymbolFeatures();
849850

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

0 commit comments

Comments
 (0)