Skip to content
Permalink
Browse files

Revert "Fix joined attributes can't be used in filter expressions"

This reverts commit acedb39.
  • Loading branch information
nyalldawson committed Jun 10, 2016
1 parent 50a6ed0 commit 8394b574fa2fc039f9575b305810a137dd12105c
Showing with 1 addition and 49 deletions.
  1. +0 −11 src/core/qgsvectorlayerfeatureiterator.cpp
  2. +1 −38 tests/src/python/test_qgsfeatureiterator.py
@@ -93,17 +93,6 @@ QgsVectorLayerFeatureIterator::QgsVectorLayerFeatureIterator( QgsVectorLayerFeat
, mFetchedFid( false )
, mInterruptionChecker( nullptr )
{
//ensure that all fields required for filter expressions are prepared
if ( mRequest.filterType() == QgsFeatureRequest::FilterExpression )
{
Q_FOREACH ( const QString& field, mRequest.filterExpression()->referencedColumns() )
{
int attrIdx = mSource->mFields.fieldNameIndex( field );
if ( !mRequest.subsetOfAttributes().contains( attrIdx ) )
mRequest.setSubsetOfAttributes( mRequest.subsetOfAttributes() << attrIdx );
}
}

prepareFields();

mHasVirtualAttributes = !mFetchJoinInfo.isEmpty() || !mExpressionFieldInfo.isEmpty();
@@ -239,44 +239,7 @@ def test_JoinUsingExpression2(self):
self.assertFalse(fi.nextFeature(f))

QgsMapLayerRegistry.instance().removeMapLayers([layer.id(), joinLayer.id()])

def test_JoinUsingFeatureRequestExpression(self):
""" test requesting features using a filter expression which requires joined columns """
joinLayer = QgsVectorLayer(
"Point?field=x:string&field=y:integer&field=z:integer",
"joinlayer", "memory")
pr = joinLayer.dataProvider()
f1 = QgsFeature()
f1.setAttributes(["foo", 123, 321])
f2 = QgsFeature()
f2.setAttributes(["bar", 124, 654])
self.assertTrue(pr.addFeatures([f1, f2]))

layer = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer",
"addfeat", "memory")
pr = layer.dataProvider()
f1 = QgsFeature()
f1.setAttributes(["test", 123])
f2 = QgsFeature()
f2.setAttributes(["test", 124])
self.assertTrue(pr.addFeatures([f1, f2]))

QgsMapLayerRegistry.instance().addMapLayers([layer, joinLayer])

join = QgsVectorJoinInfo()
join.targetFieldName = "fldint"
join.joinLayerId = joinLayer.id()
join.joinFieldName = "y"
join.memoryCache = True
layer.addJoin(join)

f = QgsFeature()
fi = layer.getFeatures(QgsFeatureRequest().setFilterExpression('joinlayer_z=654'))
self.assertTrue(fi.nextFeature(f))
self.assertEqual(f['fldint'], 124)
self.assertEqual(f['joinlayer_z'], 654)

QgsMapLayerRegistry.instance().removeMapLayers([layer.id(), joinLayer.id()])
# try the other way too


if __name__ == '__main__':

0 comments on commit 8394b57

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