Skip to content
Permalink
Browse files

Don't send expressions with special fields to provider

  • Loading branch information
3nids committed Aug 14, 2015
1 parent fee5da9 commit 480a0f17c318cca806b68bf381dad59f097d96ef
Showing with 35 additions and 0 deletions.
  1. +10 −0 python/core/qgsfeaturerequest.sip
  2. +10 −0 src/core/qgsfeaturerequest.h
  3. +15 −0 src/core/qgsvectorlayerfeatureiterator.cpp
@@ -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;
@@ -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; }
@@ -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;

0 comments on commit 480a0f1

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