Skip to content
Permalink
Browse files

Fix issue with intents to rebuild index of an empty layer

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 0386ed01fca69661943fc088563f6a7a26bf85c8
Showing with 14 additions and 1 deletion.
  1. +11 −1 src/core/qgspointlocator.cpp
  2. +3 −0 src/core/qgspointlocator.h
@@ -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 )
@@ -602,7 +603,7 @@ bool QgsPointLocator::init( int maxFeaturesToIndex )

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


@@ -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,
@@ -672,6 +676,8 @@ void QgsPointLocator::destroyIndex()
delete mRTree;
mRTree = 0;

mIsEmptyLayer = false;

foreach ( QgsGeometry* g, mGeoms )
delete g;
mGeoms.clear();
@@ -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 ) )
@@ -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;

0 comments on commit 0386ed0

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