diff --git a/python/core/qgspointlocator.sip.in b/python/core/qgspointlocator.sip.in index c6d243eddd7..2ccc3b7e318 100644 --- a/python/core/qgspointlocator.sip.in +++ b/python/core/qgspointlocator.sip.in @@ -73,7 +73,7 @@ Configure extent - if not null, it will index only that area .. versionadded:: 2.14 %End - void setRenderContext( const QgsRenderContext &context ); + void setRenderContext( const QgsRenderContext *context ); %Docstring Configure render context - if not null, it will use to index only visible feature diff --git a/src/core/qgspointlocator.cpp b/src/core/qgspointlocator.cpp index 8cfcc675647..89517862594 100644 --- a/src/core/qgspointlocator.cpp +++ b/src/core/qgspointlocator.cpp @@ -663,12 +663,19 @@ void QgsPointLocator::setExtent( const QgsRectangle *extent ) destroyIndex(); } -void QgsPointLocator::setRenderContext( const QgsRenderContext &context ) +void QgsPointLocator::setRenderContext( const QgsRenderContext *context ) { - mContext = std::unique_ptr( new QgsRenderContext( context ) ); + disconnect( mLayer, &QgsVectorLayer::styleChanged, this, &QgsPointLocator::destroyIndex ); - connect( mLayer, &QgsVectorLayer::styleChanged, this, &QgsPointLocator::destroyIndex ); destroyIndex(); + mContext.reset( nullptr ); + + if ( context ) + { + mContext = std::unique_ptr( new QgsRenderContext( *context ) ); + connect( mLayer, &QgsVectorLayer::styleChanged, this, &QgsPointLocator::destroyIndex ); + } + } bool QgsPointLocator::init( int maxFeaturesToIndex ) diff --git a/src/core/qgspointlocator.h b/src/core/qgspointlocator.h index 09fc877638d..0c8f5a941de 100644 --- a/src/core/qgspointlocator.h +++ b/src/core/qgspointlocator.h @@ -99,7 +99,7 @@ class CORE_EXPORT QgsPointLocator : public QObject * Configure render context - if not null, it will use to index only visible feature * \since QGIS 3.2 */ - void setRenderContext( const QgsRenderContext &context ); + void setRenderContext( const QgsRenderContext *context ); /** * The type of a snap result or the filter type for a snap request. diff --git a/src/core/qgssnappingutils.cpp b/src/core/qgssnappingutils.cpp index 03bab01556a..b7c22fc16a1 100644 --- a/src/core/qgssnappingutils.cpp +++ b/src/core/qgssnappingutils.cpp @@ -363,7 +363,10 @@ void QgsSnappingUtils::prepareIndex( const QList &layers QgsPointLocator *loc = locatorForLayer( vl ); if ( !mEnableSnappingForInvisibleFeature ) - loc->setRenderContext( QgsRenderContext::fromMapSettings( mMapSettings ) ); + { + QgsRenderContext ctx = QgsRenderContext::fromMapSettings( mMapSettings ); + loc->setRenderContext( &ctx ); + } if ( mStrategy == IndexExtent ) {