Skip to content
Permalink
Browse files

Relations are only valid if the id is set

  • Loading branch information
m-kuhn committed Nov 29, 2015
1 parent 6992f24 commit ebc9e029f0fdb4081be563ed7ddaf242a7b551a3
Showing with 32 additions and 0 deletions.
  1. +28 −0 src/core/qgsrelation.cpp
  2. +4 −0 src/core/qgsrelation.h
@@ -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 )
@@ -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;
@@ -274,6 +299,9 @@ void QgsRelation::updateRelationStatus()

mValid = true;

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

if ( !mReferencedLayer || !mReferencingLayer )
{
mValid = false;
@@ -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.
*

0 comments on commit ebc9e02

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