Skip to content
Permalink
Browse files

Modernize code, fix potential leak

  • Loading branch information
nyalldawson committed Jul 21, 2018
1 parent 8fac4d8 commit 7b36737b0796feb54a28f133b2da742a3aaabfce
Showing with 11 additions and 18 deletions.
  1. +6 −13 src/core/qgspointlocator.cpp
  2. +5 −5 src/core/qgspointlocator.h
@@ -621,8 +621,7 @@ class QgsPointLocator_DumpTree : public SpatialIndex::IQueryStrategy


QgsPointLocator::QgsPointLocator( QgsVectorLayer *layer, const QgsCoordinateReferenceSystem &destCRS, const QgsCoordinateTransformContext &transformContext, const QgsRectangle *extent )
: mIsEmptyLayer( false )
, mLayer( layer )
: mLayer( layer )
{
if ( destCRS.isValid() )
{
@@ -631,7 +630,7 @@ QgsPointLocator::QgsPointLocator( QgsVectorLayer *layer, const QgsCoordinateRefe

setExtent( extent );

mStorage = StorageManager::createNewMemoryStorageManager();
mStorage.reset( StorageManager::createNewMemoryStorageManager() );

connect( mLayer, &QgsVectorLayer::featureAdded, this, &QgsPointLocator::onFeatureAdded );
connect( mLayer, &QgsVectorLayer::featureDeleted, this, &QgsPointLocator::onFeatureDeleted );
@@ -644,8 +643,6 @@ QgsPointLocator::QgsPointLocator( QgsVectorLayer *layer, const QgsCoordinateRefe
QgsPointLocator::~QgsPointLocator()
{
destroyIndex();
delete mStorage;
delete mExtent;
}

QgsCoordinateReferenceSystem QgsPointLocator::destinationCrs() const
@@ -655,10 +652,7 @@ QgsCoordinateReferenceSystem QgsPointLocator::destinationCrs() const

void QgsPointLocator::setExtent( const QgsRectangle *extent )
{
if ( extent )
{
mExtent = new QgsRectangle( *extent );
}
mExtent.reset( extent ? new QgsRectangle( *extent ) : nullptr );

destroyIndex();
}
@@ -803,8 +797,8 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )
}

QgsPointLocator_Stream stream( dataList );
mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, stream, *mStorage, fillFactor, indexCapacity,
leafCapacity, dimension, variant, indexId );
mRTree.reset( RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, stream, *mStorage, fillFactor, indexCapacity,
leafCapacity, dimension, variant, indexId ) );

if ( ctx && renderer )
{
@@ -816,8 +810,7 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )

void QgsPointLocator::destroyIndex()
{
delete mRTree;
mRTree = nullptr;
mRTree.reset();

mIsEmptyLayer = false;

@@ -87,7 +87,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
* Gets extent of the area point locator covers - if null then it caches the whole layer
* \since QGIS 2.14
*/
const QgsRectangle *extent() const { return mExtent; }
const QgsRectangle *extent() const { return mExtent.get(); }

/**
* Configure extent - if not null, it will index only that area
@@ -278,19 +278,19 @@ class CORE_EXPORT QgsPointLocator : public QObject

private:
//! Storage manager
SpatialIndex::IStorageManager *mStorage = nullptr;
std::unique_ptr< SpatialIndex::IStorageManager > mStorage;

QHash<QgsFeatureId, QgsGeometry *> mGeoms;
SpatialIndex::ISpatialIndex *mRTree = nullptr;
std::unique_ptr< 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;
bool mIsEmptyLayer = false;


//! R-tree containing spatial index
QgsCoordinateTransform mTransform;
QgsVectorLayer *mLayer = nullptr;
QgsRectangle *mExtent = nullptr;
std::unique_ptr< QgsRectangle > mExtent;

std::unique_ptr<QgsRenderContext> mContext;

0 comments on commit 7b36737

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