Skip to content

Commit 7a259c6

Browse files
committedNov 5, 2018
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)
1 parent 2d1a521 commit 7a259c6

File tree

7 files changed

+13
-0
lines changed

7 files changed

+13
-0
lines changed
 

‎python/core/auto_generated/qgsrelation.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ Returns a list of attributes used to form the referencing fields
273273
bool isValid() const;
274274
%Docstring
275275
Returns the validity of this relation. Don't use the information if it's not valid.
276+
A relation is considered valid if both referenced and referencig layers are valid.
276277

277278
:return: true if the relation is valid
278279
%End

‎python/core/auto_generated/qgsrelationmanager.sip.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Gets access to the relations managed by this class.
4545
void addRelation( const QgsRelation &relation );
4646
%Docstring
4747
Add a relation.
48+
Invalid relations are added only if both referencing layer and referenced
49+
layer exist.
4850

4951
:param relation: The relation to add.
5052
%End

‎src/app/qgsrelationmanagerdialog.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ void QgsRelationManagerDialog::setLayers( const QList< QgsVectorLayer * > &layer
4949

5050
void QgsRelationManagerDialog::addRelation( const QgsRelation &rel )
5151
{
52+
if ( ! rel.isValid() )
53+
return;
54+
5255
mRelationsTable->setSortingEnabled( false );
5356
int row = mRelationsTable->rowCount();
5457
mRelationsTable->insertRow( row );

‎src/core/qgsrelation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class CORE_EXPORT QgsRelation
338338

339339
/**
340340
* Returns the validity of this relation. Don't use the information if it's not valid.
341+
* A relation is considered valid if both referenced and referencig layers are valid.
341342
*
342343
* \returns true if the relation is valid
343344
*/

‎src/core/qgsrelationmanager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ QMap<QString, QgsRelation> QgsRelationManager::relations() const
5050

5151
void QgsRelationManager::addRelation( const QgsRelation &relation )
5252
{
53+
// Do not add relations to layers that do not exist
54+
if ( !( relation.referencingLayer() && relation.referencedLayer() ) )
55+
return;
56+
5357
mRelations.insert( relation.id(), relation );
5458

5559
if ( mProject )

‎src/core/qgsrelationmanager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class CORE_EXPORT QgsRelationManager : public QObject
5959

6060
/**
6161
* Add a relation.
62+
* Invalid relations are added only if both referencing layer and referenced
63+
* layer exist.
6264
*
6365
* \param relation The relation to add.
6466
*/
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.