Skip to content

Commit

Permalink
Revert "Fix joined attributes can't be used in filter expressions"
Browse files Browse the repository at this point in the history
This reverts commit acedb39.
  • Loading branch information
nyalldawson committed Jun 10, 2016
1 parent 50a6ed0 commit 8394b57
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 deletions.
11 changes: 0 additions & 11 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
39 changes: 1 addition & 38 deletions tests/src/python/test_qgsfeatureiterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit 8394b57

Please sign in to comment.