mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Fix select by expression
Layer scope was missing from the expression context Fix #62231
This commit is contained in:
parent
e0e6405172
commit
d945494a2b
@ -572,13 +572,22 @@ void QgsVectorLayer::selectByExpression( const QString &expression, Qgis::Select
|
||||
defaultContext.emplace( QgsExpressionContextUtils::globalProjectLayerScopes( this ) );
|
||||
context = &defaultContext.value();
|
||||
}
|
||||
else
|
||||
{
|
||||
context->appendScope( QgsExpressionContextUtils::layerScope( this ) );
|
||||
}
|
||||
|
||||
QgsExpression exp( expression );
|
||||
exp.prepare( context );
|
||||
|
||||
if ( behavior == Qgis::SelectBehavior::SetSelection || behavior == Qgis::SelectBehavior::AddToSelection )
|
||||
{
|
||||
QgsFeatureRequest request = QgsFeatureRequest().setFilterExpression( expression )
|
||||
.setExpressionContext( *context )
|
||||
.setFlags( Qgis::FeatureRequestFlag::NoGeometry )
|
||||
.setNoAttributes();
|
||||
.setExpressionContext( *context );
|
||||
request.setSubsetOfAttributes( exp.referencedColumns(), fields() );
|
||||
|
||||
if ( !exp.needsGeometry() )
|
||||
request.setFlags( Qgis::FeatureRequestFlag::NoGeometry );
|
||||
|
||||
QgsFeatureIterator features = getFeatures( request );
|
||||
|
||||
@ -595,8 +604,6 @@ void QgsVectorLayer::selectByExpression( const QString &expression, Qgis::Select
|
||||
}
|
||||
else if ( behavior == Qgis::SelectBehavior::IntersectSelection || behavior == Qgis::SelectBehavior::RemoveFromSelection )
|
||||
{
|
||||
QgsExpression exp( expression );
|
||||
exp.prepare( context );
|
||||
|
||||
QgsFeatureIds oldSelection = selectedFeatureIds();
|
||||
QgsFeatureRequest request = QgsFeatureRequest().setFilterFids( oldSelection );
|
||||
|
Loading…
x
Reference in New Issue
Block a user