Skip to content
Permalink
Browse files

Better handling of invalid relations ...

- do not add them to the manager dialog
- do not add relations to not existent layers (but keep relations to invalid layers)
  • Loading branch information
elpaso committed Nov 3, 2018
1 parent 2d1a521 commit 7a259c6ea5e69d04ba26f26f561b98a04b53d141
@@ -273,6 +273,7 @@ Returns a list of attributes used to form the referencing fields
bool isValid() const;
%Docstring
Returns the validity of this relation. Don't use the information if it's not valid.
A relation is considered valid if both referenced and referencig layers are valid.

:return: true if the relation is valid
%End
@@ -45,6 +45,8 @@ Gets access to the relations managed by this class.
void addRelation( const QgsRelation &relation );
%Docstring
Add a relation.
Invalid relations are added only if both referencing layer and referenced
layer exist.

:param relation: The relation to add.
%End
@@ -49,6 +49,9 @@ void QgsRelationManagerDialog::setLayers( const QList< QgsVectorLayer * > &layer

void QgsRelationManagerDialog::addRelation( const QgsRelation &rel )
{
if ( ! rel.isValid() )
return;

mRelationsTable->setSortingEnabled( false );
int row = mRelationsTable->rowCount();
mRelationsTable->insertRow( row );
@@ -338,6 +338,7 @@ class CORE_EXPORT QgsRelation

/**
* Returns the validity of this relation. Don't use the information if it's not valid.
* A relation is considered valid if both referenced and referencig layers are valid.
*
* \returns true if the relation is valid
*/
@@ -50,6 +50,10 @@ QMap<QString, QgsRelation> QgsRelationManager::relations() const

void QgsRelationManager::addRelation( const QgsRelation &relation )
{
// Do not add relations to layers that do not exist
if ( !( relation.referencingLayer() && relation.referencedLayer() ) )
return;

mRelations.insert( relation.id(), relation );

if ( mProject )
@@ -59,6 +59,8 @@ class CORE_EXPORT QgsRelationManager : public QObject

/**
* Add a relation.
* Invalid relations are added only if both referencing layer and referenced
* layer exist.
*
* \param relation The relation to add.
*/
Binary file not shown.

0 comments on commit 7a259c6

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