mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-06 00:05:02 -05:00
Relations are only valid if the id is set
This commit is contained in:
parent
6992f2450e
commit
ebc9e029f0
@ -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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user