Skip to content

Commit

Permalink
Make it compatible with ancien QGIS versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Feb 24, 2024
1 parent fd0d556 commit 9081641
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions libqfieldsync/offline_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,26 @@ def _convert(self, project: QgsProject) -> None:
temporary_project = QgsProject()
temporary_project.readProject.connect(on_original_project_read)

temporary_project_filename = ""
if self.export_type == ExportType.Cable:
# the `backup_filename` is copied right after packaging is requested. It has all the unsaved
# project settings, which means they will be available in the packaged project too.
temporary_project.read(
self.backup_filename,
Qgis.ProjectReadFlag.FlagDontResolveLayers
| Qgis.ProjectReadFlag.FlagDontLoadLayouts
| Qgis.ProjectReadFlag.FlagDontLoad3DViews,
)
temporary_project_filename = self.backup_filename
elif self.export_type == ExportType.Cloud:
# if you save the project without QGIS GUI, the project no longer has `theMapCanvas` canvas
# so we should use the original project file that already has `theMapCanvas`. There is no
# gain using the `backup_filename`, since there is no user to modify the project.
temporary_project.read(
project.fileName(),
Qgis.ProjectReadFlag.FlagDontResolveLayers
| Qgis.ProjectReadFlag.FlagDontLoadLayouts
| Qgis.ProjectReadFlag.FlagDontLoad3DViews,
)
temporary_project_filename = project.fileName()
else:
raise NotImplementedError(f"Unknown package type: {self.export_type}")

read_flags = QgsProject.ReadFlags()
read_flags |= QgsProject.ReadFlag.DontResolveLayers
read_flags |= QgsProject.ReadFlag.DontLoadLayouts
if Qgis.versionInt() >= 32600:
read_flags |= QgsProject.ReadFlag.DontLoad3DViews
temporary_project.read(temporary_project_filename, read_flags)

temporary_project.readProject.disconnect(on_original_project_read)

self.export_folder.mkdir(parents=True, exist_ok=True)
Expand Down

0 comments on commit 9081641

Please sign in to comment.