mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-15 00:02:52 -04:00
Move allFeatureIds from QgsVectorLayer to QgsFeatureSource
This commit is contained in:
parent
1aa76ac175
commit
f799d3afc8
@ -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 @@ 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)
|
Loading…
x
Reference in New Issue
Block a user