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.DataArguments for the packager.
- 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.
- 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, andCOMPLETE_FILEmarks the package as complete.- caps: gws.plugin.qfieldcloud.caps.Caps¶
Capabilities of the QField project.
- layerMap: dict[str, gws.plugin.qfieldcloud.caps.LayerEntry]¶
Layer entries for the user, by QGIS layer id.
- project: gws.Project | None¶
GWS project context.
- qfcProject: gws.plugin.qfieldcloud.core.QfcProject¶
QField project.
- 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
editlayer.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.
- layer_entry_for_user(le: gws.plugin.qfieldcloud.caps.LayerEntry) gws.plugin.qfieldcloud.caps.LayerEntry¶
Create a copy of an
editlayer entry with the read-only flag and custom properties for the user.Operations the user may not perform on the model are locked in QField. Geometry editing is also locked if the user may not write the geometry field. Operations locked in the QGIS project, or all operations if the layer is read-only there, are locked as well. Locks controlled by an expression in the QGIS project are not considered, the expressions are kept as is. If all operations are locked, the layer is read-only.
- Parameters:
le – Layer entry.
- Returns:
Layer entry for the user. Other layer entries are returned unchanged.
- load_file_contents(me: gws.plugin.qfieldcloud.caps.ModelEntry, fields: list[gws.plugin.model_field.file.Object], uids: list[gws.FeatureUid]) dict[str, dict]¶
Read the content of file fields.
- Parameters:
me – Model entry.
fields – File fields of the model.
uids – Feature UIDs to read the content for.
- Returns:
File values with content, by field name, by feature uid as a string.
- 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
baseMaplayers.
- 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
editlayer into a GeoPackage file, and the files ofsyncFilesfields withoutuseBlob.
- 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 that the user can read are written. A field named
fidis written asfid_gws, because GDAL usesfidinternally. The content ofsyncFilesfields withuseBlobthat the user can read is written into a binary column named after thecontentColumn.- Parameters:
le – Layer entry.
ds – GeoPackage data set.
- write_files(le: gws.plugin.qfieldcloud.caps.LayerEntry)¶
Write the content of
syncFilesfields withoutuseBlobinto the package.Each file is added to the package under the path stored in the
nameColumn. Files are stored in the map cache directory and reused while their size matches the size of the content in the database. Fields the user cannot read, empty files, and absolute paths or paths with..are skipped.- Parameters:
le – Layer entry.
- 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
removeaction and empty layer groups, and makes paths relative.- 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:
Trueif 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_custom_properties(layer_el: gws.XmlElement, props: dict)¶
Set or remove custom properties of a map layer.
- Parameters:
layer_el – Map layer element.
props – Property values by name,
Noneremoves the property.
- update_edit_widgets()¶
Update the data source in relation reference widgets that reference
editlayers.
- 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
editlayers.