From 4212f47685f06193029e9f63ba11e78589e635f2 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Tue, 6 Feb 2024 11:19:53 +0200 Subject: [PATCH] Fix geometry-less exported as empty layers If the selection by BBOX did not select anything, make sure we fool `QgsOfflineEditing` something is selected. Otherwise when `layer.selectedFeatureIds().isEmpty()`, `QgsOfflineEditing` dumps all features. NOTE that `layer.selectedFeatureIds()` should be renamed to `layer.requestedFeaturesIds()`, as it does not indicate actual features ids being already selected. This was wrongly applied on non-spatial layers, which caused them to be exported as empty layers. --- libqfieldsync/offliners.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libqfieldsync/offliners.py b/libqfieldsync/offliners.py index d061889..e156d5b 100644 --- a/libqfieldsync/offliners.py +++ b/libqfieldsync/offliners.py @@ -114,8 +114,12 @@ def convert_to_offline( else: layer.selectByRect(bbox) - if layer.selectedFeatureCount() == 0: - layer.selectByIds([FID_NULL]) + # If the selection by BBOX did not select anything, make sure we fool `QgsOfflineEditing` something is selected. + # Otherwise when `layer.selectedFeatureIds().isEmpty()`, `QgsOfflineEditing` dumps all features. + # NOTE that `layer.selectedFeatureIds()` should be renamed to `layer.requestedFeaturesIds()`, as it does + # not indicate actual features ids being already selected. + if layer.selectedFeatureCount() == 0: + layer.selectByIds([FID_NULL]) is_success = self.offliner.convertToOfflineProject( str(offline_db_path),