Skip to content

Commit

Permalink
Integration minioffliner
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Sep 18, 2023
1 parent 91d28d4 commit 4d72d5c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 46 deletions.
87 changes: 52 additions & 35 deletions libqfieldsync/offline_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from qgis.PyQt.QtCore import QCoreApplication, QObject, pyqtSignal

from .layer import LayerSource, SyncAction
from .offline_editing_mini import convert_to_offline_project
from .project import ProjectConfiguration, ProjectProperties
from .utils.file_utils import copy_attachments
from .utils.logger import logger
Expand Down Expand Up @@ -251,7 +252,11 @@ def _convert(self, project: QgsProject) -> None:
self.trUtf8("Copying layers…"),
)

if layer_action == SyncAction.OFFLINE:
if (
layer_action == SyncAction.OFFLINE
and self.export_type == ExportType.Cable
):
# Select features in case of QGIS offline editing (cable export)
if self.project_configuration.offline_copy_only_aoi:
extent = QgsCoordinateTransform(
QgsCoordinateReferenceSystem(self.area_of_interest_crs),
Expand Down Expand Up @@ -300,44 +305,56 @@ def _convert(self, project: QgsProject) -> None:
export_project_filename.parent,
Path(source_dir),
)
try:
# Run the offline plugin for gpkg

if self.export_type == ExportType.Cloud:
gpkg_filename = "data.gpkg"
if self.__offline_layers:
offline_layer_ids = [o_l.id() for o_l in self.__offline_layers]

if not self.offline_editing.convertToOfflineProject(
str(self.export_folder),
gpkg_filename,
offline_layer_ids,
self.project_configuration.offline_copy_only_aoi,
self.offline_editing.GPKG,
None,
):
raise Exception(
self.tr(
"QGIS Offline editing error: failed to convert layers to offline layers"
bbox = QgsCoordinateTransform(
QgsCoordinateReferenceSystem(self.area_of_interest_crs),
QgsProject.instance().crs(),
QgsProject.instance(),
).transformBoundingBox(self.area_of_interest.boundingBox())
convert_to_offline_project(gpkg_filename, self.__offline_layers, bbox)

else:
try:
# Run the offline plugin for gpkg
gpkg_filename = "data.gpkg"
if self.__offline_layers:
offline_layer_ids = [o_l.id() for o_l in self.__offline_layers]

if not self.offline_editing.convertToOfflineProject(
str(self.export_folder),
gpkg_filename,
offline_layer_ids,
self.project_configuration.offline_copy_only_aoi,
self.offline_editing.GPKG,
None,
):
raise Exception(
self.tr(
"QGIS Offline editing error: failed 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 = [o_l.id() for o_l in self.__offline_layers]

if not self.offline_editing.convertToOfflineProject(
str(self.export_folder),
spatialite_filename,
offline_layer_ids,
self.project_configuration.offline_copy_only_aoi,
self.offline_editing.SpatiaLite,
None,
):
raise Exception(
self.tr(
"QGIS Offline editing error: failed 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 = [o_l.id() for o_l in self.__offline_layers]

if not self.offline_editing.convertToOfflineProject(
str(self.export_folder),
spatialite_filename,
offline_layer_ids,
self.project_configuration.offline_copy_only_aoi,
self.offline_editing.SpatiaLite,
None,
):
raise Exception(
self.tr(
"QGIS Offline editing error: failed to convert layers to offline layers"
)
)
)

# Disable project options that could create problems on a portable
# project with offline layers
Expand Down
12 changes: 1 addition & 11 deletions libqfieldsync/offline_editing_mini.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import hashlib
import logging
from collections import defaultdict
from typing import List, Optional

Expand All @@ -19,10 +18,7 @@
edit,
)

# from .utils import logger


logger = logging.getLogger("x")
from .utils.logger import logger

CUSTOM_PROPERTY_IS_OFFLINE_EDITABLE = "isOfflineEditable"
CUSTOM_PROPERTY_REMOTE_SOURCE = "remoteSource"
Expand Down Expand Up @@ -159,9 +155,6 @@ def convert_to_offline_layer(
with edit(new_layer):
feature_request = QgsFeatureRequest()

print(layer.name())
print(repr([field.name() for field in new_layer.fields()]))

new_fields = new_layer.fields()

for feature in layer.dataProvider().getFeatures(feature_request):
Expand Down Expand Up @@ -295,6 +288,3 @@ def __init__(self, layer, subset_string) -> None:
PROJECT_ENTRY_KEY_OFFLINE_DB_PATH,
project.writePath(offline_gpkg_path),
)


convert_to_offline_project("/tmp/out.gpkg", QgsProject.instance().mapLayers().keys())

0 comments on commit 4d72d5c

Please sign in to comment.