gws.plugin.qfieldcloud.caps

Parser for QField-related capabilities of a QGIS project.

Source code: gws.plugin.qfieldcloud.caps

Module Contents

class gws.plugin.qfieldcloud.caps.Caps(*args, **kwargs)

Bases: gws.Data

QField related capabilities extracted from the QGIS project and GWS config.

areaOfInterest: gws.Bounds | None

Area of interest.

baseMapLayerIds: list[str]

Ids of the layers rendered into the base map.

copyDirs: list[str]

Absolute paths of directories to copy into the package.

copyOnlyAreaOfInterest: bool

Whether only features in the area of interest are packaged.

layerMap: dict[str, LayerEntry]

Layer entries by QGIS layer id.

modelMap: dict[str, ModelEntry]

Model entries by GeoPackage name.

projectProps: ProjectProps

QFieldSync project properties.

qgisPath: str

Path to the QGIS project file, empty if the project is not stored in a file.

sourceHash: str

Hash of the QGIS project source, used to invalidate cached caps.

class gws.plugin.qfieldcloud.caps.LayerAction

Bases: gws.Enum

What the packager does with a layer.

baseMap = 'baseMap'

Render the layer into the base map.

edit = 'edit'

Package the layer data for offline editing.

remove = 'remove'

Remove the layer from the project.

class gws.plugin.qfieldcloud.caps.LayerEntry(*args, **kwargs)

Bases: gws.Data

QField-related information about a QGIS layer.

action: LayerAction

What to do with the layer.

dataProvider: str

Data provider in the packaged QGIS project.

dataSource: str

Data source string in the packaged QGIS project.

dataSourceFileName: str

Name of the packaged data file.

modelEntry: ModelEntry

Model entry, for edit layers.

props: LayerProps

QFieldSync layer properties.

qgisId: str

Layer id in the QGIS project.

readOnly: bool

Whether all editing is locked in QFieldSync.

sourceLayer: gws.SourceLayer

Source layer from the QGIS project.

sqlFilter: str

SQL filter (subset string) of the layer.

class gws.plugin.qfieldcloud.caps.LayerProps(*args, **kwargs)

Bases: gws.Data

Custom layer properties as defined by QField.

action: str

QFieldSync layer action.

attachment_naming: dict

Naming rules for attachments.

attribute_editing_locked_expression: str

Expression that locks attribute editing.

cloud_action: str

offline, no_action or remove.

Type:

Cloud action

feature_addition_locked_expression: str

Expression that locks feature addition.

feature_deletion_locked_expression: str

Expression that locks feature deletion.

geometry_editing_locked_expression: str

Expression that locks geometry editing.

is_attribute_editing_locked: bool

Whether attribute editing is locked.

is_feature_addition_locked: bool

Whether feature addition is locked.

is_feature_deletion_locked: bool

Whether feature deletion is locked.

is_geometry_editing_locked: bool

Whether geometry editing is locked.

photo_naming: dict

Naming rules for photos.

relationship_maximum_visible: dict

Maximum number of visible related features.

tracking_distance_requirement_minimum_meters: int

Minimum distance between tracked positions, in meters.

tracking_erroneous_distance_safeguard_maximum_meters: int

Maximum distance of a tracked position before it is considered erroneous, in meters.

tracking_measurement_type: int

Tracking measurement type.

tracking_time_requirement_interval_seconds: int

Minimum time between tracked positions, in seconds.

value_map_button_interface_threshold: int

Threshold for showing value maps as buttons.

class gws.plugin.qfieldcloud.caps.ModelEntry(*args, **kwargs)

Bases: gws.Data

A model for an offline table, with its GeoPackage layer name.

gpName: str

Name of the GeoPackage file and layer.

model: gws.DatabaseModel

Model for the table.

tableName: str

Database table name.

class gws.plugin.qfieldcloud.caps.Parser(qfc_project: gws.plugin.qfieldcloud.core.QfcProject)

Reads QField-related capabilities from a QGIS project.

parse reads the project and layer properties. create_models and assign_path_props complete the layer entries and are called separately.

caps: Caps

Capabilities being built.

qfcProject: gws.plugin.qfieldcloud.core.QfcProject

QField project.

qgisCaps: gws.plugin.qgis.caps.Caps

Capabilities of the QGIS project.

assign_path_props()

Set the data file name, data source and provider of edit and baseMap layers in the package.

create_model_entry_for_layer(le: LayerEntry)

Assign a model entry to an edit layer.

If no model is found, or the layer is editable but the model is not, the layer gets the remove action.

Parameters:

le – Layer entry.

create_models()

Create model entries for all edit layers.

extract_layer_props(sl: gws.SourceLayer) → LayerProps

Read the QFieldSync properties of a layer.

Parameters:

sl – Source layer.

Returns:

Layer properties.

extract_project_props() → ProjectProps

Read the QFieldSync project properties.

Returns:

Project properties.

gp_name_for_model(table_name)

Return the GeoPackage name for a table.

Parameters:

table_name – Table name, optionally with a schema (public by default).

Returns:

Name in the form qm_<schema>_<table>, lowercase.

iter_layers()

Create layer entries for all non-group source layers.

layer_entry(sl: gws.SourceLayer) → LayerEntry | None

Create a layer entry for a source layer.

Parameters:

sl – Source layer.

Returns:

Layer entry, or None if the layer is left unchanged in the package.

layer_entry_2(sl: gws.SourceLayer) → LayerEntry | None

Determine the action for a source layer.

Base map layers get baseMap. Layers with the cloud action remove get remove. Postgres layers with the cloud action offline get edit, offline layers of other providers get remove.

Parameters:

sl – Source layer.

Returns:

Layer entry without the id and source layer, or None for other layers.

model_entry_for_source_layer(sl: gws.SourceLayer) → ModelEntry | None

Find or create a model entry for the table of a source layer.

A configured model with the same table name is used if present. Otherwise a generic Postgres model is created for the table.

Parameters:

sl – Source layer.

Returns:

Model entry, or None if the layer has no table or the table does not exist.

parse() → Caps

Parse the QGIS project.

Reads the project properties, the area of interest, the directories to copy, the base map layers and the layer entries.

Returns:

Capabilities, also stored in self.caps.

parse_area_of_interest()

Set the area of interest from the project properties.

parse_base_map()

Set the base map layer ids from the map theme or the single base map layer.

parse_copy_dirs()

Set the directories to copy into the package.

Relative paths are resolved against the QGIS project file. Nested directories are dropped.

postgres_layer_entry(sl, props: LayerProps) → LayerEntry

Create a layer entry for an offline Postgres layer.

Layers without a plain table name (e.g. SQL queries) get the remove action.

Parameters:
  • sl – Source layer.

  • props – QFieldSync layer properties.

Returns:

Layer entry.

class gws.plugin.qfieldcloud.caps.ProjectProps(*args, **kwargs)

Bases: gws.Data

Custom project properties as defined by QField.

areaOfInterest: str

Area of interest as WKT.

areaOfInterestCrs: str

CRS of the area of interest.

attachmentDirs: list[str]

Attachment directories.

baseMapLayer: str

Id of the layer used as the base map, if baseMapType is singleLayer.

baseMapTheme: str

Map theme used as the base map, if baseMapType is mapTheme.

baseMapTileSize: int

Base map tile size.

baseMapTilesMaxZoomLevel: int

Maximum zoom level of the base map.

baseMapTilesMinZoomLevel: int

Minimum zoom level of the base map.

baseMapType: str

Base map type, mapTheme or singleLayer.

createBaseMap: bool

Whether a base map is created.

dataDirs: list[str]

Data directories.

digitizingLogsLayer: str

Id of the digitizing logs layer.

dirsToCopy: dict

Directories to copy, as a dict {dirname: bool}.

forceAutoPush: bool

Whether changes are pushed automatically.

forceAutoPushIntervalMins: int

Automatic push interval in minutes.

forceStamping: bool

Whether photos are stamped.

geofencingBehavior: int

Geofencing behavior.

geofencingIsActive: bool

Whether geofencing is active.

geofencingLayer: str

Id of the geofencing layer.

geofencingShouldPreventDigitizing: bool

Whether geofencing prevents digitizing.

mapThemesActiveLayers: dict

Active layers of map themes.

maximumImageWidthHeight: int

Maximum width and height of images.

offlineCopyOnlyAoi: bool

Whether only features in the area of interest are packaged.

stampingDetailsTemplate: str

Template for photo stamping.

stampingFontStyle: str

Font style for photo stamping.

stampingHorizontalAlignment: int

Horizontal alignment for photo stamping.

stampingImageDecoration: str

Image decoration for photo stamping.