Skip to content
Permalink
Browse files

Add empty() and emptyUnknown() to QgsFeatureSource

  • Loading branch information
m-kuhn committed Jun 4, 2018
1 parent adf5eb7 commit e252cc0ce946a74b206a593efd325f14c01c23ba
Showing with 52 additions and 2 deletions.
  1. +21 −1 python/core/auto_generated/qgsfeaturesource.sip.in
  2. +10 −0 src/core/qgsfeaturesource.cpp
  3. +21 −1 src/core/qgsfeaturesource.h
@@ -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;
@@ -139,7 +160,6 @@ for its ownership.

.. versionadded:: 3.0
%End

};


@@ -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() )
@@ -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.
@@ -150,7 +171,6 @@ class CORE_EXPORT QgsFeatureSource
*/
QgsVectorLayer *materialize( const QgsFeatureRequest &request,
QgsFeedback *feedback = nullptr ) SIP_FACTORY;

};

Q_DECLARE_METATYPE( QgsFeatureSource * )

0 comments on commit e252cc0

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