gws.plugin.qfieldcloud.packager

Creates QField packages from QGIS projects.

Source code: gws.plugin.qfieldcloud.packager

Module Contents

class gws.plugin.qfieldcloud.packager.Args(*args, **kwargs)

Bases: gws.Data

Arguments for the packager.

caps: gws.plugin.qfieldcloud.caps.Caps

Capabilities of the QField project.

mapCacheDir: str

Directory for cached base map images.

packageDir: str

Directory to write the package into.

project: gws.Project | None

GWS project context.

qfcProject: gws.plugin.qfieldcloud.core.QfcProject

QField project.

uid: str

Package uid, used in log messages.

user: gws.User

User the package is created for.

withBaseMap: bool

Render base maps.

withData: bool

Write the data of offline layers.

withMedia: bool

Add media files.

withQgis: bool

Write the modified QGIS project.

gws.plugin.qfieldcloud.packager.COMPLETE_FILE = 'package_complete'

Name of the marker file written when a package is complete.

class gws.plugin.qfieldcloud.packager.Object

Packager, writes a QField package into a directory.

Data files and the QGIS project are written into the package directory. Base maps and media files are not copied; the package path map refers to them where they are. The path map is written into PATH_MAP_FILE, and COMPLETE_FILE marks the package as complete.

args: Args

Packager arguments.

caps: gws.plugin.qfieldcloud.caps.Caps

Capabilities of the QField project.

project: gws.Project | None

GWS project context.

qfcProject: gws.plugin.qfieldcloud.core.QfcProject

QField project.

root: gws.Root

Root object.

uid: str

Package uid.

user: gws.User

User the package is created for.

create_package(root: gws.Root, args: Args)

Create a package.

Parameters:
  • root – Root object.

  • args – Packager arguments.

get_features_for_layer(le: gws.plugin.qfieldcloud.caps.LayerEntry) → list[gws.Feature]

Read the features of an edit layer.

If only the area of interest is copied, features are limited to the area of interest, or the project bounds.

Parameters:

le – Layer entry.

Returns:

Features.

replace_vars(s: str) → str

Replace user variables in a string.

Supported variables are {user.authToken}, {user.loginName} and {user.displayName}.

Parameters:

s – Source string.

Returns:

String with the variables replaced.

write_base_map()

Render all baseMap layers.

write_base_map_layer(le: gws.plugin.qfieldcloud.caps.LayerEntry)

Render a base map layer into a raster file.

The layer is rendered as a single image covering the area of interest (or the project bounds), at the resolution of the maximum zoom level (clamped to 3..20) in the grid of the target CRS. The file is stored in the map cache directory and reused while it is younger than mapCacheLifeTime.

Parameters:

le – Layer entry.

write_data()

Write the features of each edit layer into a GeoPackage file.

write_features(le: gws.plugin.qfieldcloud.caps.LayerEntry, ds: gws.lib.gdalx.VectorDataSet)

Write the features of a layer into a GeoPackage layer.

Only fields of simple types are written. A field named fid is written as fid_gws, because GDAL uses fid internally.

Parameters:
  • le – Layer entry.

  • ds – GeoPackage data set.

write_media()

Add the files from the directories to copy to the path map.

Paths in the package are relative to the QGIS project file. If the project is not stored in a file, the last directory name is used.

write_qgis_project()

Write the modified QGIS project into the package.

The original project is also written next to it, with the extension .source.qgs.

gws.plugin.qfieldcloud.packager.PATH_MAP_FILE = 'path_map.json'

Name of the file that maps package file names to paths on disk.

class gws.plugin.qfieldcloud.packager.QgisXmlTransformer

Modifies the QGIS project XML for the package.

Points layers and references to the packaged data sources, removes layers with the remove action and empty layer groups, and makes paths relative.

po: Object

Packager.

root: gws.XmlElement

Root element of the project.

toRemove: list[gws.XmlElement]

Elements to remove.

change_global_props()

Set the project to use relative paths.

cleanup_layer_group(group_el)

Mark empty layer groups for removal, recursively.

Parameters:

group_el – Layer tree group element.

Returns:

True if the group contains layers that are kept.

remove_elements(el, parent_el)

Remove the elements marked for removal, recursively.

Parameters:
  • el – Element to check.

  • parent_el – Parent element.

run(po: Object, root_el: gws.XmlElement)

Transform the project XML in place.

Parameters:
  • po – Packager.

  • root_el – Root element of the project.

update_edit_widgets()

Update the data source in relation reference widgets that reference edit layers.

update_layer_tree()

Update the data source of layer tree entries, or mark them for removal.

update_map_layers()

Update the data source of map layers, or mark them for removal.

update_referenced_layers()

Update the data source in relations that reference edit layers.