Navigation Menu

Skip to content

Commit

Permalink
Add empty() and emptyUnknown() to QgsFeatureSource
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 4, 2018
1 parent adf5eb7 commit e252cc0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
22 changes: 21 additions & 1 deletion python/core/auto_generated/qgsfeaturesource.sip.in
Expand Up @@ -66,6 +66,27 @@ if the feature count is unknown.
%Docstring
Returns the number of features contained in the source, or -1
if the feature count is unknown.
%End

virtual bool empty() const;
%Docstring
Determines if there are any features available in the source.

In case it is not known if there are features available, false is returned.
Use ``emptyUnknown()`` to determine if this value is reliable.

.. seealso:: :py:func:`QgsVectorDataProvider.empty`
information.

.. versionadded:: 3.2
%End

virtual bool emptyUnknown() const;
%Docstring
Returns true if the value returned by ``empty()`` may be wrong.
This depends on the dataprovider.

.. versionadded:: 3.2
%End

virtual QSet<QVariant> uniqueValues( int fieldIndex, int limit = -1 ) const;
Expand Down Expand Up @@ -139,7 +160,6 @@ for its ownership.

.. versionadded:: 3.0
%End

};


Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsfeaturesource.cpp
Expand Up @@ -23,6 +23,16 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

bool QgsFeatureSource::empty() const
{
return featureCount();
}

bool QgsFeatureSource::emptyUnknown() const
{
return featureCount() == -1;
}

QSet<QVariant> QgsFeatureSource::uniqueValues( int fieldIndex, int limit ) const
{
if ( fieldIndex < 0 || fieldIndex >= fields().count() )
Expand Down
22 changes: 21 additions & 1 deletion src/core/qgsfeaturesource.h
Expand Up @@ -85,6 +85,27 @@ class CORE_EXPORT QgsFeatureSource
*/
virtual long featureCount() const = 0;

/**
* Determines if there are any features available in the source.
*
* In case it is not known if there are features available, false is returned.
* Use ``emptyUnknown()`` to determine if this value is reliable.
*
* \see QgsVectorDataProvider::empty() for data provider specific
* information.
*
* \since QGIS 3.2
*/
virtual bool empty() const;

/**
* Returns true if the value returned by ``empty()`` may be wrong.
* This depends on the dataprovider.
*
* \since QGIS 3.2
*/
virtual bool emptyUnknown() const;

/**
* Returns the set of unique values contained within the specified \a fieldIndex from this source.
* If specified, the \a limit option can be used to limit the number of returned values.
Expand Down Expand Up @@ -150,7 +171,6 @@ class CORE_EXPORT QgsFeatureSource
*/
QgsVectorLayer *materialize( const QgsFeatureRequest &request,
QgsFeedback *feedback = nullptr ) SIP_FACTORY;

};

Q_DECLARE_METATYPE( QgsFeatureSource * )
Expand Down

0 comments on commit e252cc0

Please sign in to comment.