diff --git a/libqfieldsync/layer.py b/libqfieldsync/layer.py index 7d57721..a499e66 100644 --- a/libqfieldsync/layer.py +++ b/libqfieldsync/layer.py @@ -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, @@ -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, @@ -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(): @@ -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: diff --git a/libqfieldsync/project_checker.py b/libqfieldsync/project_checker.py index 170003c..decdc6e 100644 --- a/libqfieldsync/project_checker.py +++ b/libqfieldsync/project_checker.py @@ -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 ):