Skip to content

Commit

Permalink
Don't send expressions with special fields to provider
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Aug 14, 2015
1 parent fee5da9 commit 480a0f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/core/qgsfeaturerequest.sip
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ class QgsFeatureRequest
QgsFeatureRequest& setFilterExpression( const QString& expression );
QgsExpression* filterExpression() const;

/**
* Disables filter conditions.
* The spatial filter (filterRect) will be kept in place.
*
* @return The object the method is called on for chaining
*
* @note Added in 2.12
*/
QgsFeatureRequest& disableFilter();

//! Set flags that affect how features will be fetched
QgsFeatureRequest& setFlags( Flags flags );
const Flags& flags() const;
Expand Down
10 changes: 10 additions & 0 deletions src/core/qgsfeaturerequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ class CORE_EXPORT QgsFeatureRequest
QgsFeatureRequest& setFilterExpression( const QString& expression );
QgsExpression* filterExpression() const { return mFilterExpression; }

/**
* Disables filter conditions.
* The spatial filter (filterRect) will be kept in place.
*
* @return The object the method is called on for chaining
*
* @note Added in 2.12
*/
QgsFeatureRequest& disableFilter() { mFilter = FilterNone; return *this; }

//! Set flags that affect how features will be fetched
QgsFeatureRequest& setFlags( Flags flags );
const Flags& flags() const { return mFlags; }
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
mProviderRequest.setSubsetOfAttributes( providerSubset );
}

if ( mProviderRequest.filterType() == QgsFeatureRequest::FilterExpression )
{
Q_FOREACH( const QString& field, mProviderRequest.filterExpression()->referencedColumns() )
{
int idx = source->mFields.fieldNameIndex( field );

// If there are fields in the expression which are not of origin provider, the provider will not be able to filter based on them.
// In this case we disable the expression filter.
if ( source->mFields.fieldOrigin( idx ) != QgsFields::OriginProvider )
{
mProviderRequest.disableFilter();
}
}
}

if ( mSource->mHasEditBuffer )
{
mChangedFeaturesRequest = mProviderRequest;
Expand Down

0 comments on commit 480a0f1

Please sign in to comment.