Skip to content

Commit

Permalink
Merge pull request #9207 from mbernasocchi/master
Browse files Browse the repository at this point in the history
Add safety guard when mDataProvider is not set
  • Loading branch information
m-kuhn committed Feb 20, 2019
2 parents 8eb1c4e + 8ea09b6 commit ddbd06f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -1507,6 +1507,8 @@ Returns the list of attributes which make up the layer's primary keys.
%Docstring
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.

:return: the number of features on this layer or -1 if unknown.
%End

bool setReadOnly( bool readonly = true );
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2891,6 +2891,8 @@ QgsAttributeList QgsVectorLayer::primaryKeyAttributes() const

long QgsVectorLayer::featureCount() const
{
if ( ! mDataProvider )
return -1;
return mDataProvider->featureCount() +
( mEditBuffer ? mEditBuffer->mAddedFeatures.size() - mEditBuffer->mDeletedFeatureIds.size() : 0 );
}
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1397,6 +1397,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
/**
* 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.
* \returns the number of features on this layer or -1 if unknown.
*/
long featureCount() const FINAL;

Expand Down

0 comments on commit ddbd06f

Please sign in to comment.