Skip to content
Permalink
Browse files

Add support for visible features in onFeatureAdded, onGeometryChanged…

… and onAttributeValueChanged
  • Loading branch information
lbartoletti committed Apr 25, 2018
1 parent 5e5fdf9 commit 43e905d7fcb4bbaf8851f5f1125d6fc9f9db48e4
Showing with 34 additions and 0 deletions.
  1. +33 −0 src/core/qgspointlocator.cpp
  2. +1 −0 src/core/qgspointlocator.h
@@ -636,6 +636,7 @@ QgsPointLocator::QgsPointLocator( QgsVectorLayer *layer, const QgsCoordinateRefe
connect( mLayer, &QgsVectorLayer::featureAdded, this, &QgsPointLocator::onFeatureAdded );
connect( mLayer, &QgsVectorLayer::featureDeleted, this, &QgsPointLocator::onFeatureDeleted );
connect( mLayer, &QgsVectorLayer::geometryChanged, this, &QgsPointLocator::onGeometryChanged );
connect( mLayer, &QgsVectorLayer::attributeValueChanged, this, &QgsPointLocator::onAttributeValueChanged );
connect( mLayer, &QgsVectorLayer::dataChanged, this, &QgsPointLocator::destroyIndex );
}

@@ -834,6 +835,30 @@ void QgsPointLocator::onFeatureAdded( QgsFeatureId fid )
if ( !f.hasGeometry() )
return;

std::unique_ptr< QgsFeatureRenderer > renderer( mLayer->renderer() ? mLayer->renderer()->clone() : nullptr );
QgsRenderContext *ctx = nullptr;
if ( mContext )
{
mContext->expressionContext() << QgsExpressionContextUtils::layerScope( mLayer );
ctx = mContext.get();
if ( renderer && ctx )
{
bool pass = false;
renderer->startRender( *ctx, mLayer->fields() );

ctx->expressionContext().setFeature( f );
if ( !renderer->willRenderFeature( f, *ctx ) )
{
pass = true;
}

renderer->stopRender( *ctx );
renderer.release();
if ( pass )
return;
}
}

if ( mTransform.isValid() )
{
try
@@ -884,6 +909,14 @@ void QgsPointLocator::onGeometryChanged( QgsFeatureId fid, const QgsGeometry &ge
onFeatureAdded( fid );
}

void QgsPointLocator::onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
{
Q_UNUSED( idx );
Q_UNUSED( value );
onFeatureDeleted( fid );
onFeatureAdded( fid );
}


QgsPointLocator::Match QgsPointLocator::nearestVertex( const QgsPointXY &point, double tolerance, MatchFilter *filter )
{
@@ -274,6 +274,7 @@ class CORE_EXPORT QgsPointLocator : public QObject
void onFeatureAdded( QgsFeatureId fid );
void onFeatureDeleted( QgsFeatureId fid );
void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
void onAttributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );

private:
//! Storage manager

0 comments on commit 43e905d

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