Skip to content

Commit

Permalink
Fix python bindings for QgsRelation.fieldPairs()
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 18, 2014
1 parent 978642a commit 1b205be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/core/qgsrelation.sip
Expand Up @@ -165,7 +165,8 @@ class QgsRelation
*/
QMap< QString, QString > fieldPairs() const;
%MethodCode
QList< QgsRelation::FieldPair > pairs = sipCpp->fieldPairs();
const QList< QgsRelation::FieldPair >& pairs = sipCpp->fieldPairs();
sipRes = new QMap< QString, QString >();
Q_FOREACH( const QgsRelation::FieldPair& pair, pairs )
{
sipRes->insert( pair.first, pair.second );
Expand Down
18 changes: 18 additions & 0 deletions tests/src/python/test_qgsrelation.py
Expand Up @@ -119,5 +119,23 @@ def test_getRelatedFeatures(self):

QgsMapLayerRegistry.instance().removeAllMapLayers()

def test_fieldPairs(self):
referencedLayer = createReferencedLayer()
referencingLayer = createReferencingLayer()
QgsMapLayerRegistry.instance().addMapLayers([referencedLayer,referencingLayer])

rel = QgsRelation()

rel.setRelationId( 'rel1' )
rel.setRelationName( 'Relation Number One' )
rel.setReferencingLayer( referencingLayer.id() )
rel.setReferencedLayer( referencedLayer.id() )
rel.addFieldPair( 'foreignkey', 'y' )

assert( rel.fieldPairs() == { 'foreignkey': 'y'} )

QgsMapLayerRegistry.instance().removeAllMapLayers()


if __name__ == '__main__':
unittest.main()

0 comments on commit 1b205be

Please sign in to comment.