Move allFeatureIds from QgsVectorLayer to QgsFeatureSource

This commit is contained in:
Nyall Dawson 2017-09-08 20:09:29 +10:00
parent 1aa76ac175
commit f799d3afc8
7 changed files with 32 additions and 26 deletions

View File

@ -114,6 +114,12 @@ class QgsFeatureSource
:rtype: QgsRectangle
%End
virtual QgsFeatureIds allFeatureIds() const;
%Docstring
Returns a list of all feature IDs for features present in the source.
:rtype: QgsFeatureIds
%End
};

View File

@ -576,12 +576,6 @@ Select not selected features and deselect selected ones
Select all the features
%End
QgsFeatureIds allFeatureIds() const;
%Docstring
Get all feature Ids
:rtype: QgsFeatureIds
%End
void invertSelectionInRectangle( QgsRectangle &rect );
%Docstring
Invert selection of features found within the search rectangle (in layer's coordinates)

View File

@ -103,3 +103,20 @@ QgsRectangle QgsFeatureSource::sourceExtent() const
return r;
}
QgsFeatureIds QgsFeatureSource::allFeatureIds() const
{
QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
.setFlags( QgsFeatureRequest::NoGeometry )
.setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeatureIds ids;
QgsFeature fet;
while ( fit.nextFeature( fet ) )
{
ids << fet.id();
}
return ids;
}

View File

@ -117,6 +117,11 @@ class CORE_EXPORT QgsFeatureSource
*/
virtual QgsRectangle sourceExtent() const;
/**
* Returns a list of all feature IDs for features present in the source.
*/
virtual QgsFeatureIds allFeatureIds() const;
};
Q_DECLARE_METATYPE( QgsFeatureSource * )

View File

@ -516,23 +516,6 @@ void QgsVectorLayer::selectAll()
selectByIds( allFeatureIds() );
}
QgsFeatureIds QgsVectorLayer::allFeatureIds() const
{
QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
.setFlags( QgsFeatureRequest::NoGeometry )
.setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeatureIds ids;
QgsFeature fet;
while ( fit.nextFeature( fet ) )
{
ids << fet.id();
}
return ids;
}
void QgsVectorLayer::invertSelectionInRectangle( QgsRectangle &rect )
{
// normalize the rectangle

View File

@ -608,9 +608,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Select all the features
void selectAll();
//! Get all feature Ids
QgsFeatureIds allFeatureIds() const;
/**
* Invert selection of features found within the search rectangle (in layer's coordinates)
*

View File

@ -647,3 +647,7 @@ class FeatureSourceTestCase(object):
def testMaximumValue(self):
self.assertEqual(self.source.maximumValue(1), 400)
self.assertEqual(self.source.maximumValue(2), 'Pear')
def testAllFeatureIds(self):
ids = set([f.id() for f in self.source.getFeatures()])
self.assertEqual(set(self.source.allFeatureIds()),ids)