Skip to content

Commit

Permalink
Merge pull request #188 from SwissTierrasColombia/offline_copy_only_s…
Browse files Browse the repository at this point in the history
…elected_features

Only copy selected features for offline layers
  • Loading branch information
m-kuhn authored Sep 21, 2020
2 parents 8ec7b83 + f7ce4b9 commit 848f346
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions qfieldsync/core/offline_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -173,19 +178,22 @@ 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:
# Run the offline plugin for spatialite
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
Expand Down
11 changes: 11 additions & 0 deletions qfieldsync/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 848f346

Please sign in to comment.