Skip to content

Commit ddbd06f

Browse files
authoredFeb 20, 2019
Merge pull request #9207 from mbernasocchi/master
Add safety guard when mDataProvider is not set
2 parents 8eb1c4e + 8ea09b6 commit ddbd06f

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed
 

‎python/core/auto_generated/qgsvectorlayer.sip.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,8 @@ Returns the list of attributes which make up the layer's primary keys.
15071507
%Docstring
15081508
Returns feature count including changes which have not yet been committed
15091509
If you need only the count of committed features call this method on this layer's provider.
1510+
1511+
:return: the number of features on this layer or -1 if unknown.
15101512
%End
15111513

15121514
bool setReadOnly( bool readonly = true );

‎src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,8 @@ QgsAttributeList QgsVectorLayer::primaryKeyAttributes() const
28912891

28922892
long QgsVectorLayer::featureCount() const
28932893
{
2894+
if ( ! mDataProvider )
2895+
return -1;
28942896
return mDataProvider->featureCount() +
28952897
( mEditBuffer ? mEditBuffer->mAddedFeatures.size() - mEditBuffer->mDeletedFeatureIds.size() : 0 );
28962898
}

‎src/core/qgsvectorlayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
13971397
/**
13981398
* Returns feature count including changes which have not yet been committed
13991399
* If you need only the count of committed features call this method on this layer's provider.
1400+
* \returns the number of features on this layer or -1 if unknown.
14001401
*/
14011402
long featureCount() const FINAL;
14021403

0 commit comments

Comments
 (0)
Please sign in to comment.