mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
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)
This commit is contained in:
parent
2d1a521fe4
commit
7a259c6ea5
@ -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.
|
||||
*/
|
||||
|
BIN
tests/testdata/projects/bad_layers_test.gpkg
vendored
BIN
tests/testdata/projects/bad_layers_test.gpkg
vendored
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user