Skip to content

Commit

Permalink
Better handling of invalid relations ...
Browse files Browse the repository at this point in the history
- 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 5, 2018
1 parent 2d1a521 commit 7a259c6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsrelation.sip.in
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions python/core/auto_generated/qgsrelationmanager.sip.in
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsrelationmanagerdialog.cpp
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsrelation.h
Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsrelationmanager.cpp
Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsrelationmanager.h
Expand Up @@ -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.
*/
Expand Down
Binary file modified tests/testdata/projects/bad_layers_test.gpkg
Binary file not shown.

0 comments on commit 7a259c6

Please sign in to comment.