Skip to content

Commit 7b36737

Browse files
committedJul 21, 2018
Modernize code, fix potential leak
1 parent 8fac4d8 commit 7b36737

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed
 

‎src/core/qgspointlocator.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,7 @@ class QgsPointLocator_DumpTree : public SpatialIndex::IQueryStrategy
621621

622622

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

632631
setExtent( extent );
633632

634-
mStorage = StorageManager::createNewMemoryStorageManager();
633+
mStorage.reset( StorageManager::createNewMemoryStorageManager() );
635634

636635
connect( mLayer, &QgsVectorLayer::featureAdded, this, &QgsPointLocator::onFeatureAdded );
637636
connect( mLayer, &QgsVectorLayer::featureDeleted, this, &QgsPointLocator::onFeatureDeleted );
@@ -644,8 +643,6 @@ QgsPointLocator::QgsPointLocator( QgsVectorLayer *layer, const QgsCoordinateRefe
644643
QgsPointLocator::~QgsPointLocator()
645644
{
646645
destroyIndex();
647-
delete mStorage;
648-
delete mExtent;
649646
}
650647

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

656653
void QgsPointLocator::setExtent( const QgsRectangle *extent )
657654
{
658-
if ( extent )
659-
{
660-
mExtent = new QgsRectangle( *extent );
661-
}
655+
mExtent.reset( extent ? new QgsRectangle( *extent ) : nullptr );
662656

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

805799
QgsPointLocator_Stream stream( dataList );
806-
mRTree = RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, stream, *mStorage, fillFactor, indexCapacity,
807-
leafCapacity, dimension, variant, indexId );
800+
mRTree.reset( RTree::createAndBulkLoadNewRTree( RTree::BLM_STR, stream, *mStorage, fillFactor, indexCapacity,
801+
leafCapacity, dimension, variant, indexId ) );
808802

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

817811
void QgsPointLocator::destroyIndex()
818812
{
819-
delete mRTree;
820-
mRTree = nullptr;
813+
mRTree.reset();
821814

822815
mIsEmptyLayer = false;
823816

‎src/core/qgspointlocator.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
8787
* Gets extent of the area point locator covers - if null then it caches the whole layer
8888
* \since QGIS 2.14
8989
*/
90-
const QgsRectangle *extent() const { return mExtent; }
90+
const QgsRectangle *extent() const { return mExtent.get(); }
9191

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

279279
private:
280280
//! Storage manager
281-
SpatialIndex::IStorageManager *mStorage = nullptr;
281+
std::unique_ptr< SpatialIndex::IStorageManager > mStorage;
282282

283283
QHash<QgsFeatureId, QgsGeometry *> mGeoms;
284-
SpatialIndex::ISpatialIndex *mRTree = nullptr;
284+
std::unique_ptr< SpatialIndex::ISpatialIndex > mRTree;
285285

286286
//! flag whether the layer is currently empty (i.e. mRTree is null but it is not necessary to rebuild it)
287-
bool mIsEmptyLayer;
287+
bool mIsEmptyLayer = false;
288288

289289

290290
//! R-tree containing spatial index
291291
QgsCoordinateTransform mTransform;
292292
QgsVectorLayer *mLayer = nullptr;
293-
QgsRectangle *mExtent = nullptr;
293+
std::unique_ptr< QgsRectangle > mExtent;
294294

295295
std::unique_ptr<QgsRenderContext> mContext;
296296

0 commit comments

Comments
 (0)
Please sign in to comment.