Skip to content

Commit f799d3a

Browse files
committedSep 8, 2017
Move allFeatureIds from QgsVectorLayer to QgsFeatureSource
1 parent 1aa76ac commit f799d3a

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed
 

‎python/core/qgsfeaturesource.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ class QgsFeatureSource
114114
:rtype: QgsRectangle
115115
%End
116116

117+
virtual QgsFeatureIds allFeatureIds() const;
118+
%Docstring
119+
Returns a list of all feature IDs for features present in the source.
120+
:rtype: QgsFeatureIds
121+
%End
122+
117123
};
118124

119125

‎python/core/qgsvectorlayer.sip

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,6 @@ Select not selected features and deselect selected ones
576576
Select all the features
577577
%End
578578

579-
QgsFeatureIds allFeatureIds() const;
580-
%Docstring
581-
Get all feature Ids
582-
:rtype: QgsFeatureIds
583-
%End
584-
585579
void invertSelectionInRectangle( QgsRectangle &rect );
586580
%Docstring
587581
Invert selection of features found within the search rectangle (in layer's coordinates)

‎src/core/qgsfeaturesource.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,20 @@ QgsRectangle QgsFeatureSource::sourceExtent() const
103103
return r;
104104
}
105105

106+
QgsFeatureIds QgsFeatureSource::allFeatureIds() const
107+
{
108+
QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
109+
.setFlags( QgsFeatureRequest::NoGeometry )
110+
.setSubsetOfAttributes( QgsAttributeList() ) );
111+
112+
QgsFeatureIds ids;
113+
114+
QgsFeature fet;
115+
while ( fit.nextFeature( fet ) )
116+
{
117+
ids << fet.id();
118+
}
119+
120+
return ids;
121+
}
122+

‎src/core/qgsfeaturesource.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ class CORE_EXPORT QgsFeatureSource
117117
*/
118118
virtual QgsRectangle sourceExtent() const;
119119

120+
/**
121+
* Returns a list of all feature IDs for features present in the source.
122+
*/
123+
virtual QgsFeatureIds allFeatureIds() const;
124+
120125
};
121126

122127
Q_DECLARE_METATYPE( QgsFeatureSource * )

‎src/core/qgsvectorlayer.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -516,23 +516,6 @@ void QgsVectorLayer::selectAll()
516516
selectByIds( allFeatureIds() );
517517
}
518518

519-
QgsFeatureIds QgsVectorLayer::allFeatureIds() const
520-
{
521-
QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
522-
.setFlags( QgsFeatureRequest::NoGeometry )
523-
.setSubsetOfAttributes( QgsAttributeList() ) );
524-
525-
QgsFeatureIds ids;
526-
527-
QgsFeature fet;
528-
while ( fit.nextFeature( fet ) )
529-
{
530-
ids << fet.id();
531-
}
532-
533-
return ids;
534-
}
535-
536519
void QgsVectorLayer::invertSelectionInRectangle( QgsRectangle &rect )
537520
{
538521
// normalize the rectangle

‎src/core/qgsvectorlayer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
608608
//! Select all the features
609609
void selectAll();
610610

611-
//! Get all feature Ids
612-
QgsFeatureIds allFeatureIds() const;
613-
614611
/**
615612
* Invert selection of features found within the search rectangle (in layer's coordinates)
616613
*

‎tests/src/python/featuresourcetestbase.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,7 @@ def testMinimumValue(self):
647647
def testMaximumValue(self):
648648
self.assertEqual(self.source.maximumValue(1), 400)
649649
self.assertEqual(self.source.maximumValue(2), 'Pear')
650+
651+
def testAllFeatureIds(self):
652+
ids = set([f.id() for f in self.source.getFeatures()])
653+
self.assertEqual(set(self.source.allFeatureIds()),ids)

0 commit comments

Comments
 (0)
Please sign in to comment.