Skip to content
Permalink
Browse files

Add optimized versions of empty() to QgsVectorDataProvider

  • Loading branch information
m-kuhn committed Jun 4, 2018
1 parent e252cc0 commit 381a7661ba6c7b0a2f80fa46032436ab73748949
@@ -122,6 +122,21 @@ Returns the geometry type which is returned by this layer
Number of features in the layer

:return: long containing number of features
%End

virtual bool empty() const;
%Docstring
Returns true if the layer contains at least one feature.

.. versionadded:: 3.2
%End

virtual bool emptyUnknown() const;
%Docstring
For QgsVectorDataProviders this always returns true because
the provider is actually queried for features.

.. versionadded:: 3.2
%End

virtual QgsFields fields() const = 0;
@@ -46,6 +46,20 @@ QString QgsVectorDataProvider::storageType() const
return QStringLiteral( "Generic vector file" );
}

bool QgsVectorDataProvider::empty() const
{
QgsFeature f;
if ( getFeatures().nextFeature( f ) )
return true;
else
return false;
}

bool QgsVectorDataProvider::emptyUnknown() const
{
return false;
}

QgsCoordinateReferenceSystem QgsVectorDataProvider::sourceCrs() const
{
return crs();
@@ -163,6 +163,21 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider, public QgsFeat
*/
long featureCount() const override = 0;

/**
* Returns true if the layer contains at least one feature.
*
* \since QGIS 3.2
*/
virtual bool empty() const override;

/**
* For QgsVectorDataProviders this always returns true because
* the provider is actually queried for features.
*
* \since QGIS 3.2
*/
virtual bool emptyUnknown() const override;

/**
* Returns the fields associated with this data provider.
*/

0 comments on commit 381a766

Please sign in to comment.
You can’t perform that action at this time.