Fix python bindings for QgsRelation.fieldPairs()

This commit is contained in:
Matthias Kuhn 2014-08-18 14:56:15 +02:00
parent 978642addb
commit 1b205be604
2 changed files with 20 additions and 1 deletions

View File

@ -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 );

View File

@ -119,5 +119,23 @@ class TestQgsRelation( TestCase ):
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()