Commit
The slowness of merge / split features tools was caused by the change in the logic in selectedFeatures(): instead of fetching individual features one by one by ID, the whole layer is traversed. Such approach makes sense when many features are selected, but with few features there is considerable delay when dealing with big layers. The implementation is not ideal, but for some common cases the performance is much better. Merging of features now does not request selected features when not necessary. When rendering, avoid using layer's extent() method that may force expensive calculation of layer's extent.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2327,24 +2327,43 @@ const QgsFeatureIds& QgsVectorLayer::selectedFeaturesIds() const | |
QgsFeatureList QgsVectorLayer::selectedFeatures() | ||
{ | ||
QgsFeatureList features; | ||
|
||
QgsFeatureIterator it = selectedFeaturesIterator(); | ||
|
||
QgsFeature f; | ||
while ( it.nextFeature( f ) ) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wonder-sk
Author
Member
|
||
|
||
if ( mSelectedFeatureIds.count() <= 8 ) | ||
{ | ||
// for small amount of selected features, fetch them directly | ||
// because request with FilterFids would go iterate over the whole layer | ||
foreach ( int fid, mSelectedFeatureIds ) | ||
{ | ||
getFeatures( QgsFeatureRequest( fid ) ).nextFeature( f ); | ||
features << f; | ||
} | ||
} | ||
else | ||
{ | ||
features.push_back( f ); | ||
QgsFeatureIterator it = selectedFeaturesIterator(); | ||
|
||
while ( it.nextFeature( f ) ) | ||
{ | ||
features.push_back( f ); | ||
} | ||
} | ||
|
||
return features; | ||
} | ||
|
||
QgsFeatureIterator QgsVectorLayer::selectedFeaturesIterator( QgsFeatureRequest request ) | ||
{ | ||
if ( mSelectedFeatureIds.count() == 0 ) | ||
return QgsFeatureIterator(); | ||
|
||
if ( geometryType() == QGis::NoGeometry ) | ||
request.setFlags( QgsFeatureRequest::NoGeometry ); | ||
|
||
request.setFilterFids( mSelectedFeatureIds ); | ||
if ( mSelectedFeatureIds.count() == 1 ) | ||
request.setFilterFid( *mSelectedFeatureIds.constBegin() ); | ||
else | ||
request.setFilterFids( mSelectedFeatureIds ); | ||
|
||
return getFeatures( request ); | ||
} | ||
|
Wouldn't it be even better to fix the
FilterFids
code for affected providers?That would give a better performance and fix similar effects in other areas of the code/plugins. Evenmore as the current threshold of 8 is arbitrary (and I couldn't think of a good way to get an appropriate guess)