Skip to content
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
9 changes: 1 addition & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
args: [ "--select", "I", "--fix" ]

# Run the formatter.
- id: ruff-format
Expand All @@ -27,10 +27,3 @@ repos:
hooks:
- id: mypy
additional_dependencies: []

# Sort imports alphabetically
- repo: https://github.com/PyCQA/isort
rev: 6.0.1
hooks:
- id: isort
args: ["--profile", "black"]
26 changes: 22 additions & 4 deletions libqfieldsync/offliners.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Qgis,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
QgsCsException, # type: ignore[import]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suricactus , thanks :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have any idea why the QgsCsException is not available in the python type definitions? But there is no problem importing it in the end.

QgsDataSourceUri,
QgsFeatureRequest,
QgsField,
Expand Down Expand Up @@ -113,6 +114,11 @@ def convert_to_offline(
if bbox and bbox.isFinite():
only_selected = True
for layer in layers:
if layer.type() != QgsMapLayer.LayerType.VectorLayer:
continue

assert isinstance(layer, QgsVectorLayer)

if Qgis.versionInt() >= 33000: # noqa: PLR2004
no_geometry_types = [
Qgis.GeometryType.Null,
Expand All @@ -131,8 +137,14 @@ def convert_to_offline(
layer.removeSelection()
else:
tr = QgsCoordinateTransform(project.crs(), layer.crs(), project)
layer_bbox = tr.transform(bbox)
layer.selectByRect(layer_bbox)

try:
layer_bbox = tr.transform(bbox)
layer.selectByRect(layer_bbox)
except QgsCsException as err:
logger.warning(
f"Failed to transform project CRS {project.crs().authid()} bbox to layer {layer.name()} CRS {layer.crs().authid()} bbox within `QgisCoreOffliner`: {err}. All features will be offlined for this layer."
)

# 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.
Expand Down Expand Up @@ -437,8 +449,14 @@ def _convert_to_offline_project(
tr = QgsCoordinateTransform(
project.crs(), layer_to_offline.crs(), project
)
layer_bbox = tr.transform(bbox)
request.setFilterRect(layer_bbox)

try:
layer_bbox = tr.transform(bbox)
request.setFilterRect(layer_bbox)
except QgsCsException as err:
logger.warning(
f"Failed to transform project CRS {project.crs().authid()} bbox to layer {layer_to_offline.name()} CRS {layer_to_offline.crs().authid()} bbox within `PythonMiniOffliner`: {err}. All features will be offlined for this layer."
)

if filters_mapping[datasource_hash]:
request.setFilterExpression(filters_mapping[datasource_hash])
Expand Down
Loading