Skip to content

Commit e252cc0

Browse files
committed
Add empty() and emptyUnknown() to QgsFeatureSource
1 parent adf5eb7 commit e252cc0

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

python/core/auto_generated/qgsfeaturesource.sip.in

+21-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ if the feature count is unknown.
6666
%Docstring
6767
Returns the number of features contained in the source, or -1
6868
if the feature count is unknown.
69+
%End
70+
71+
virtual bool empty() const;
72+
%Docstring
73+
Determines if there are any features available in the source.
74+
75+
In case it is not known if there are features available, false is returned.
76+
Use ``emptyUnknown()`` to determine if this value is reliable.
77+
78+
.. seealso:: :py:func:`QgsVectorDataProvider.empty`
79+
information.
80+
81+
.. versionadded:: 3.2
82+
%End
83+
84+
virtual bool emptyUnknown() const;
85+
%Docstring
86+
Returns true if the value returned by ``empty()`` may be wrong.
87+
This depends on the dataprovider.
88+
89+
.. versionadded:: 3.2
6990
%End
7091

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

140161
.. versionadded:: 3.0
141162
%End
142-
143163
};
144164

145165

src/core/qgsfeaturesource.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
#include "qgsvectorlayer.h"
2424
#include "qgsvectordataprovider.h"
2525

26+
bool QgsFeatureSource::empty() const
27+
{
28+
return featureCount();
29+
}
30+
31+
bool QgsFeatureSource::emptyUnknown() const
32+
{
33+
return featureCount() == -1;
34+
}
35+
2636
QSet<QVariant> QgsFeatureSource::uniqueValues( int fieldIndex, int limit ) const
2737
{
2838
if ( fieldIndex < 0 || fieldIndex >= fields().count() )

src/core/qgsfeaturesource.h

+21-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ class CORE_EXPORT QgsFeatureSource
8585
*/
8686
virtual long featureCount() const = 0;
8787

88+
/**
89+
* Determines if there are any features available in the source.
90+
*
91+
* In case it is not known if there are features available, false is returned.
92+
* Use ``emptyUnknown()`` to determine if this value is reliable.
93+
*
94+
* \see QgsVectorDataProvider::empty() for data provider specific
95+
* information.
96+
*
97+
* \since QGIS 3.2
98+
*/
99+
virtual bool empty() const;
100+
101+
/**
102+
* Returns true if the value returned by ``empty()`` may be wrong.
103+
* This depends on the dataprovider.
104+
*
105+
* \since QGIS 3.2
106+
*/
107+
virtual bool emptyUnknown() const;
108+
88109
/**
89110
* Returns the set of unique values contained within the specified \a fieldIndex from this source.
90111
* If specified, the \a limit option can be used to limit the number of returned values.
@@ -150,7 +171,6 @@ class CORE_EXPORT QgsFeatureSource
150171
*/
151172
QgsVectorLayer *materialize( const QgsFeatureRequest &request,
152173
QgsFeedback *feedback = nullptr ) SIP_FACTORY;
153-
154174
};
155175

156176
Q_DECLARE_METATYPE( QgsFeatureSource * )

0 commit comments

Comments
 (0)