Skip to content

Commit

Permalink
When we can't auto load a relationship because its definition is
Browse files Browse the repository at this point in the history
broken, show a warning to users instead of silently failing
  • Loading branch information
nyalldawson committed Sep 28, 2022
1 parent 765d89c commit 6501df1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/app/layers/qgsapplayerhandling.cpp
Expand Up @@ -163,7 +163,7 @@ void QgsAppLayerHandling::postProcessAddedLayers( const QList<QgsMapLayer *> &la
{
vl->setWeakRelations( relations );
resolveVectorLayerDependencies( vl, QgsMapLayer::StyleCategory::Relations, QgsVectorLayerRef::MatchType::Source, DependencyFlag::LoadAllRelationships | DependencyFlag::SilentLoad );
resolveVectorLayerWeakRelations( vl, QgsVectorLayerRef::MatchType::Source );
resolveVectorLayerWeakRelations( vl, QgsVectorLayerRef::MatchType::Source, true );
}
}
}
Expand Down Expand Up @@ -1578,7 +1578,7 @@ void QgsAppLayerHandling::resolveVectorLayerDependencies( QgsVectorLayer *vl, Qg
}
}

void QgsAppLayerHandling::resolveVectorLayerWeakRelations( QgsVectorLayer *vectorLayer, QgsVectorLayerRef::MatchType matchType )
void QgsAppLayerHandling::resolveVectorLayerWeakRelations( QgsVectorLayer *vectorLayer, QgsVectorLayerRef::MatchType matchType, bool guiWarnings )
{
if ( vectorLayer && vectorLayer->isValid() )
{
Expand All @@ -1601,6 +1601,10 @@ void QgsAppLayerHandling::resolveVectorLayerWeakRelations( QgsVectorLayer *vecto
}
QgsProject::instance()->relationManager()->addRelation( relation );
}
else if ( guiWarnings )
{
QgisApp::instance()->messageBar()->pushWarning( QObject::tr( "Invalid relationship %1" ).arg( relation.name() ), relation.validationError() );
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/layers/qgsapplayerhandling.h
Expand Up @@ -202,8 +202,11 @@ class APP_EXPORT QgsAppLayerHandling
*
* This method will automatically attempt to repair any relations using
* other layers already present in the current project.
*
* If \a guiWarnings is TRUE then the explanation for invalid relationships
* will be shown to the user.
*/
static void resolveVectorLayerWeakRelations( QgsVectorLayer *vectorLayer, QgsVectorLayerRef::MatchType matchType = QgsVectorLayerRef::MatchType::Name );
static void resolveVectorLayerWeakRelations( QgsVectorLayer *vectorLayer, QgsVectorLayerRef::MatchType matchType = QgsVectorLayerRef::MatchType::Name, bool guiWarnings = false );

/**
* Triggered when a vector layer style has changed, checks for widget config layer dependencies
Expand Down

0 comments on commit 6501df1

Please sign in to comment.