Merge pull request #9207 from mbernasocchi/master

Add safety guard when mDataProvider is not set
This commit is contained in:
Matthias Kuhn 2019-02-20 14:02:16 +01:00 committed by GitHub
commit ddbd06f3f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 0 deletions

View File

@ -1507,6 +1507,8 @@ Returns the list of attributes which make up the layer's primary keys.
%Docstring %Docstring
Returns feature count including changes which have not yet been committed Returns feature count including changes which have not yet been committed
If you need only the count of committed features call this method on this layer's provider. If you need only the count of committed features call this method on this layer's provider.
:return: the number of features on this layer or -1 if unknown.
%End %End
bool setReadOnly( bool readonly = true ); bool setReadOnly( bool readonly = true );

View File

@ -2891,6 +2891,8 @@ QgsAttributeList QgsVectorLayer::primaryKeyAttributes() const
long QgsVectorLayer::featureCount() const long QgsVectorLayer::featureCount() const
{ {
if ( ! mDataProvider )
return -1;
return mDataProvider->featureCount() + return mDataProvider->featureCount() +
( mEditBuffer ? mEditBuffer->mAddedFeatures.size() - mEditBuffer->mDeletedFeatureIds.size() : 0 ); ( mEditBuffer ? mEditBuffer->mAddedFeatures.size() - mEditBuffer->mDeletedFeatureIds.size() : 0 );
} }

View File

@ -1397,6 +1397,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
/** /**
* Returns feature count including changes which have not yet been committed * Returns feature count including changes which have not yet been committed
* If you need only the count of committed features call this method on this layer's provider. * If you need only the count of committed features call this method on this layer's provider.
* \returns the number of features on this layer or -1 if unknown.
*/ */
long featureCount() const FINAL; long featureCount() const FINAL;