Skip to content

Commit

Permalink
Adding Warning for layers outside the current project home directory
Browse files Browse the repository at this point in the history
  • Loading branch information
SeqLaz committed Nov 14, 2024
1 parent 1b923ba commit 36fc36f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions libqfieldsync/project_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ def __init__(self, project: QgsProject) -> None:
"fn": self.check_layer_has_ascii_filename,
"scope": None,
},
{
"type": Feedback.Level.WARNING,
"fn": self.check_external_layers,
"scope": None,
},
{
"type": Feedback.Level.WARNING,
"fn": self.check_layer_primary_key,
Expand Down Expand Up @@ -410,3 +415,22 @@ def check_layer_package_prevention(
return FeedbackResult(main_msg)

return None

def check_external_layers(
self, layer_source: LayerSource
) -> Optional[FeedbackResult]:
home_path = Path(self.project.fileName()).parent

if layer_source.is_file and not layer_source.is_localized_path:
layer_path = Path(layer_source.layer.source()).resolve()

if home_path not in layer_path.parents:
return FeedbackResult(
self.tr(
'Layer "{}" is outside the project\'s home directory.'
"This layers may cause issues."
'Please move the layer within "{}".'
).format(layer_source.filename, home_path)
)

return None

0 comments on commit 36fc36f

Please sign in to comment.