Skip to content

Commit

Permalink
Relations are only valid if the id is set
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 30, 2015
1 parent 6992f24 commit ebc9e02
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/core/qgsrelation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void QgsRelation::writeXML( QDomNode &node, QDomDocument &doc ) const
void QgsRelation::setRelationId( const QString& id )
{
mRelationId = id;

updateRelationStatus();
}

void QgsRelation::setRelationName( const QString& name )
Expand Down Expand Up @@ -260,6 +262,29 @@ QList<QgsRelation::FieldPair> QgsRelation::fieldPairs() const
return mFieldPairs;
}

QgsAttributeList QgsRelation::referencedFields() const
{
QgsAttributeList attrs;

Q_FOREACH ( const FieldPair& pair, mFieldPairs )
{
attrs << mReferencedLayer->fieldNameIndex( pair.second );
}
return attrs;
}

QgsAttributeList QgsRelation::referencingFields() const
{
QgsAttributeList attrs;

Q_FOREACH ( const FieldPair& pair, mFieldPairs )
{
attrs << mReferencingLayer->fieldNameIndex( pair.first );
}
return attrs;

}

bool QgsRelation::isValid() const
{
return mValid;
Expand All @@ -274,6 +299,9 @@ void QgsRelation::updateRelationStatus()

mValid = true;

if ( mRelationId.isEmpty() )
mValid = false;

if ( !mReferencedLayer || !mReferencingLayer )
{
mValid = false;
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsrelation.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ class CORE_EXPORT QgsRelation
*/
QList< FieldPair > fieldPairs() const;

QgsAttributeList referencedFields() const;

QgsAttributeList referencingFields() const;

/**
* Returns the validity of this relation. Don't use the information if it's not valid.
*
Expand Down

0 comments on commit ebc9e02

Please sign in to comment.