Skip to content

Commit

Permalink
Fix issue with intents to rebuild index of an empty layer
Browse files Browse the repository at this point in the history
With one or more empty layers, this would lead to a weird blinking due to progress
dialog being opened when snapping to empty layers is active.

The fix adds a flag in the point locator, so the index is not rebuilt unless there
are some features in the layer
  • Loading branch information
wonder-sk committed Feb 9, 2015
1 parent ee50520 commit 0386ed0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/core/qgspointlocator.cpp
Expand Up @@ -564,6 +564,7 @@ class QgsPointLocator_DumpTree : public SpatialIndex::IQueryStrategy
QgsPointLocator::QgsPointLocator( QgsVectorLayer* layer, const QgsCoordinateReferenceSystem* destCRS, const QgsRectangle* extent )
: mStorage( 0 )
, mRTree( 0 )
, mIsEmptyLayer( false )
, mTransform( 0 )
, mLayer( layer )
, mExtent( 0 )
Expand Down Expand Up @@ -602,7 +603,7 @@ bool QgsPointLocator::init( int maxFeaturesToIndex )

bool QgsPointLocator::hasIndex() const
{
return mRTree != 0;
return mRTree != 0 || mIsEmptyLayer;
}


Expand Down Expand Up @@ -658,7 +659,10 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )
SpatialIndex::id_type indexId;

if ( dataList.isEmpty() )
{
mIsEmptyLayer = true;
return true; // no features
}

QgsPointLocator_Stream stream( dataList );
mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, stream, *mStorage, fillFactor, indexCapacity,
Expand All @@ -672,6 +676,8 @@ void QgsPointLocator::destroyIndex()
delete mRTree;
mRTree = 0;

mIsEmptyLayer = false;

foreach ( QgsGeometry* g, mGeoms )
delete g;
mGeoms.clear();
Expand All @@ -680,7 +686,11 @@ void QgsPointLocator::destroyIndex()
void QgsPointLocator::onFeatureAdded( QgsFeatureId fid )
{
if ( !mRTree )
{
if ( mIsEmptyLayer )
rebuildIndex(); // first feature - let's built the index
return; // nothing to do if we are not initialized yet
}

QgsFeature f;
if ( mLayer->getFeatures( QgsFeatureRequest( fid ) ).nextFeature( f ) )
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgspointlocator.h
Expand Up @@ -170,6 +170,9 @@ class CORE_EXPORT QgsPointLocator : public QObject
QHash<QgsFeatureId, QgsGeometry*> mGeoms;
SpatialIndex::ISpatialIndex* mRTree;

//! flag whether the layer is currently empty (i.e. mRTree is null but it is not necessary to rebuild it)
bool mIsEmptyLayer;

/** R-tree containing spatial index */
QgsCoordinateTransform* mTransform;
QgsVectorLayer* mLayer;
Expand Down

0 comments on commit 0386ed0

Please sign in to comment.