Skip to content

Commit

Permalink
Modernize code, fix potential leak
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 21, 2018
1 parent 8fac4d8 commit 7b36737
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
19 changes: 6 additions & 13 deletions src/core/qgspointlocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand All @@ -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 );
Expand All @@ -644,8 +643,6 @@ QgsPointLocator::QgsPointLocator( QgsVectorLayer *layer, const QgsCoordinateRefe
QgsPointLocator::~QgsPointLocator()
{
destroyIndex();
delete mStorage;
delete mExtent;
}

QgsCoordinateReferenceSystem QgsPointLocator::destinationCrs() const
Expand All @@ -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();
}
Expand Down Expand Up @@ -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 )
{
Expand All @@ -816,8 +810,7 @@ bool QgsPointLocator::rebuildIndex( int maxFeaturesToIndex )

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

mIsEmptyLayer = false;

Expand Down
10 changes: 5 additions & 5 deletions src/core/qgspointlocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 7b36737

Please sign in to comment.