Skip to content

Commit

Permalink
Improve selected features offline editing performance
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 15, 2016
1 parent 30b6e7e commit ab6d796
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/core/qgsofflineediting.cpp
Expand Up @@ -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
Expand Down

1 comment on commit ab6d796

@nyalldawson
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect - thanks!

Please sign in to comment.