Skip to content

Commit

Permalink
Move allFeatureIds from QgsVectorLayer to QgsFeatureSource
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 8, 2017
1 parent 1aa76ac commit f799d3a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
6 changes: 6 additions & 0 deletions python/core/qgsfeaturesource.sip
Expand Up @@ -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

};


Expand Down
6 changes: 0 additions & 6 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsfeaturesource.cpp
Expand Up @@ -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;
}

5 changes: 5 additions & 0 deletions src/core/qgsfeaturesource.h
Expand Up @@ -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 * )
Expand Down
17 changes: 0 additions & 17 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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)
*
Expand Down
4 changes: 4 additions & 0 deletions tests/src/python/featuresourcetestbase.py
Expand Up @@ -647,3 +647,7 @@ def testMinimumValue(self):
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)

0 comments on commit f799d3a

Please sign in to comment.