Skip to content
Permalink
Browse files

Move allFeatureIds from QgsVectorLayer to QgsFeatureSource

  • Loading branch information
nyalldawson committed Sep 8, 2017
1 parent 1aa76ac commit f799d3afc8ef185d30e87c3182d228946da38613
@@ -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

};


@@ -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)
@@ -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;
}

@@ -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 * )
@@ -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
@@ -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)
*
@@ -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.
You can’t perform that action at this time.