Skip to content

Commit

Permalink
Manage edition while indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 committed Sep 6, 2019
1 parent 3128fa3 commit fbc88a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/core/qgspointlocator.cpp
Expand Up @@ -591,6 +591,14 @@ void QgsPointLocator::setRenderContext( const QgsRenderContext *context )
void QgsPointLocator::onRebuildIndexFinished( bool ok )
{
mIsIndexing = false;

// treat added and deleted feature while indexing
for ( QgsFeatureId fid : mAddedFeatures )
onFeatureAdded( fid );

for ( QgsFeatureId fid : mDeletedFeatures )
onFeatureDeleted( fid );

emit initFinished( ok );
}

Expand Down Expand Up @@ -778,10 +786,17 @@ void QgsPointLocator::destroyIndex()

void QgsPointLocator::onFeatureAdded( QgsFeatureId fid )
{
if ( mIsIndexing )
{
// will modify index once current indexing is finished
mAddedFeatures << fid;
return;
}

if ( !mRTree )
{
if ( mIsEmptyLayer )
rebuildIndex(); // first feature - let's built the index
init(); // first feature - let's built the index
return; // nothing to do if we are not initialized yet
}

Expand Down Expand Up @@ -847,6 +862,20 @@ void QgsPointLocator::onFeatureAdded( QgsFeatureId fid )

void QgsPointLocator::onFeatureDeleted( QgsFeatureId fid )
{
if ( mIsIndexing )
{
if ( mAddedFeatures.contains( fid ) )
{
mAddedFeatures.remove( fid );
}
else
{
// will modify index once current indexing is finished
mDeletedFeatures << fid;
}
return;
}

if ( !mRTree )
return; // nothing to do if we are not initialized yet

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgspointlocator.h
Expand Up @@ -332,6 +332,8 @@ class CORE_EXPORT QgsPointLocator : public QObject
int mMaxFeaturesToIndex = -1;
bool mAsynchronous = false;
bool mIsIndexing = false;
QgsFeatureIds mAddedFeatures;
QgsFeatureIds mDeletedFeatures;

friend class QgsPointLocator_VisitorNearestVertex;
friend class QgsPointLocator_VisitorNearestEdge;
Expand Down

0 comments on commit fbc88a2

Please sign in to comment.