Skip to content
Permalink
Browse files

Improve selected features offline editing performance

  • Loading branch information
m-kuhn committed Sep 15, 2016
1 parent 30b6e7e commit ab6d796e08f2c0255f53aaeb49b4b7155c9b8e0f
Showing with 17 additions and 7 deletions.
  1. +17 −7 src/core/qgsofflineediting.cpp
@@ -622,20 +622,30 @@ QgsVectorLayer* QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlit
// NOTE: force feature recount for PostGIS layer, else only visible features are counted, before iterating over all features (WORKAROUND)
layer->setSubsetString( layer->subsetString() );

QgsFeatureIterator fit = layer->dataProvider()->getFeatures();
QgsFeatureRequest req;

QgsFeatureIds selectedFids = layer->selectedFeaturesIds();
if ( onlySelected )
{
QgsFeatureIds selectedFids = layer->selectedFeaturesIds();
if ( !selectedFids.isEmpty() )
req.setFilterFids( selectedFids );
}

QgsFeatureIterator fit = layer->dataProvider()->getFeatures( req );

emit progressModeSet( QgsOfflineEditing::CopyFeatures, layer->dataProvider()->featureCount() );
if ( req.filterType() == QgsFeatureRequest::FilterFids )
{
emit progressModeSet( QgsOfflineEditing::CopyFeatures, layer->selectedFeaturesIds().size() );
}
else
{
emit progressModeSet( QgsOfflineEditing::CopyFeatures, layer->dataProvider()->featureCount() );
}
int featureCount = 1;

QList<QgsFeatureId> remoteFeatureIds;
while ( fit.nextFeature( f ) )
{
// Check if we only want selected feature, if the selection is not empty and the current feature is not selected: dismiss it
if ( onlySelected && !selectedFids.isEmpty() && !selectedFids.contains( f.id() ) )
continue;

remoteFeatureIds << f.id();

// NOTE: Spatialite provider ignores position of geometry column

1 comment on commit ab6d796

@nyalldawson

This comment has been minimized.

Copy link
Collaborator

@nyalldawson nyalldawson commented on ab6d796 Sep 15, 2016

Perfect - thanks!

Please sign in to comment.
You can’t perform that action at this time.