Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not remove broken WMS layers during packaging #76

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion libqfieldsync/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class PackagePreventionReason(Enum):
INVALID = 1
UNSUPPORTED_DATASOURCE = 2
LOCALIZED_PATH = 3
INVALID_REMOTE_RASTER_LAYER = 4

REASONS_TO_REMOVE_LAYER = (
PackagePreventionReason.INVALID,
Expand Down Expand Up @@ -882,6 +883,13 @@ def is_localized_path(self) -> bool:

return path.startswith("localized:")

@property
def is_remote_raster_layer(self) -> bool:
if self.layer.dataProvider() and self.layer.dataProvider().name() == "wms":
return True

return False

@property
def package_prevention_reasons(
self,
Expand All @@ -895,6 +903,11 @@ def package_prevention_reasons(
# do not package the layers within localized paths (stored outside project dir and shared among multiple projects)
if self.is_localized_path:
reasons.append(LayerSource.PackagePreventionReason.LOCALIZED_PATH)
# sometimes the remote layers are inaccessible from the current network, but we should spare them from removal
elif not self.layer.isValid() and self.is_remote_raster_layer:
reasons.append(
LayerSource.PackagePreventionReason.INVALID_REMOTE_RASTER_LAYER
)
# remove invalid layers from the packaged project
# NOTE localized layers will be always invalid on QFieldCloud
elif not self.layer.isValid():
Expand Down Expand Up @@ -1082,7 +1095,7 @@ def convert_to_gpkg(self, target_path):
options = QgsVectorFileWriter.SaveVectorOptions()
options.fileEncoding = "UTF-8"
options.driverName = "GPKG"
(error, returned_dest_file) = QgsVectorFileWriter.writeAsVectorFormatV2(
(error, returned_dest_file) = QgsVectorFileWriter.writeAsVectorFormatV3(
source_layer, dest_file, QgsCoordinateTransformContext(), options
)
if error != QgsVectorFileWriter.NoError:
Expand Down
9 changes: 9 additions & 0 deletions libqfieldsync/project_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ def check_layer_package_prevention(

if reason == LayerSource.PackagePreventionReason.INVALID:
reason_msgs.append(self.tr("The layer is invalid!"))
elif (
reason
== LayerSource.PackagePreventionReason.INVALID_REMOTE_RASTER_LAYER
):
reason_msgs.append(
self.tr(
"The raster layer data source is not accessible from the current network!"
)
)
elif (
reason == LayerSource.PackagePreventionReason.UNSUPPORTED_DATASOURCE
):
Expand Down
Loading