From f7ce4b99f053590ab1319f5c2d429db34481e7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Carrillo?= Date: Fri, 18 Sep 2020 12:15:48 -0500 Subject: [PATCH] Enable QFieldSync API to use layer selection (offline mode) --- qfieldsync/core/offline_converter.py | 14 +++++++++++--- qfieldsync/core/project.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/qfieldsync/core/offline_converter.py b/qfieldsync/core/offline_converter.py index 71ed7653..9e22e12f 100644 --- a/qfieldsync/core/offline_converter.py +++ b/qfieldsync/core/offline_converter.py @@ -147,8 +147,13 @@ def convert(self): continue if layer_source.action == SyncAction.OFFLINE: - if self.project_configuration.offline_copy_only_aoi: + if self.project_configuration.offline_copy_only_aoi and not self.project_configuration.offline_copy_only_selected_features: layer.selectByRect(self.extent) + elif self.project_configuration.offline_copy_only_aoi and self.project_configuration.offline_copy_only_selected_features: + # This option is only possible via API + QgsApplication.instance().messageLog().logMessage(self.tr( + 'Both "Area of Interest" and "only selected features" options were enabled, tha latter takes precedence.'), + 'QFieldSync') self.__offline_layers.append(layer) elif layer_source.action == SyncAction.NO_ACTION: copied_files = layer_source.copy(self.export_folder, copied_files) @@ -173,9 +178,11 @@ def convert(self): gpkg_filename = "data.gpkg" if self.__offline_layers: offline_layer_ids = [l.id() for l in self.__offline_layers] + only_selected = self.project_configuration.offline_copy_only_aoi or self.project_configuration.offline_copy_only_selected_features if not self.offline_editing.convertToOfflineProject(self.export_folder, gpkg_filename, offline_layer_ids, - self.project_configuration.offline_copy_only_aoi, self.offline_editing.GPKG): + only_selected, + self.offline_editing.GPKG): raise Exception(self.tr("Error trying to convert layers to offline layers")) except AttributeError: @@ -183,9 +190,10 @@ def convert(self): spatialite_filename = "data.sqlite" if self.__offline_layers: offline_layer_ids = [l.id() for l in self.__offline_layers] + only_selected = self.project_configuration.offline_copy_only_aoi or self.project_configuration.offline_copy_only_selected_features if not self.offline_editing.convertToOfflineProject(self.export_folder, spatialite_filename, offline_layer_ids, - self.project_configuration.offline_copy_only_aoi): + only_selected): raise Exception(self.tr("Error trying to convert layers to offline layers")) # Disable project options that could create problems on a portable diff --git a/qfieldsync/core/project.py b/qfieldsync/core/project.py index 3e9de934..d47f2a61 100644 --- a/qfieldsync/core/project.py +++ b/qfieldsync/core/project.py @@ -12,6 +12,7 @@ def __init__(self): BASE_MAP_TILE_SIZE = '/baseMapTileSize' BASE_MAP_MUPP = '/baseMapMupp' OFFLINE_COPY_ONLY_AOI = '/offlineCopyOnlyAoi' + OFFLINE_COPY_ONLY_SELECTED_FEATURES = '/offlineCopyOnlySelectedFeatures' ORIGINAL_PROJECT_PATH = '/originalProjectPath' IMPORTED_FILES_CHECKSUMS = '/importedFilesChecksums' @@ -102,6 +103,16 @@ def offline_copy_only_aoi(self): def offline_copy_only_aoi(self, value): self.project.writeEntry('qfieldsync', ProjectProperties.OFFLINE_COPY_ONLY_AOI, value) + @property + def offline_copy_only_selected_features(self): + offline_copy_only_selected_features, _ = self.project.readBoolEntry('qfieldsync', + ProjectProperties.OFFLINE_COPY_ONLY_SELECTED_FEATURES) + return offline_copy_only_selected_features + + @offline_copy_only_selected_features.setter + def offline_copy_only_selected_features(self, value): + self.project.writeEntry('qfieldsync', ProjectProperties.OFFLINE_COPY_ONLY_SELECTED_FEATURES, value) + @property def original_project_path(self): original_project_path, _ = self.project.readEntry('qfieldsync', ProjectProperties.ORIGINAL_PROJECT_PATH)