Skip to contents

The project half of rfp_tracking_fields_add(). A column with no widget is invisible in the field app, so both are needed; run the GeoPackage half first.

Usage

rfp_qgs_tracking_fields_add(qgs, fields = NULL, force = FALSE, backup = TRUE)

Arguments

qgs

Character. Path to the project .qgs.

fields

NULL (default) for the shipped set, or a data frame in its shape.

force

Logical. Rewrite entries for fields that are already configured. Default FALSE, which adds only what is missing. Needed when the shipped set changes for a field a project already has - new dropdown options, a new default, a changed label - because an add-only writer cannot express that. Scoped to the fields in fields, so the four the app itself populates are never touched.

backup

Logical. Copy the .qgs beside itself first. Default TRUE.

Value

Invisibly, a character vector of the fields configured - empty when every one was already present.

Details

Writes <fieldConfiguration> (the widget), <aliases> (the label) and a <default> for any field declaring one, onto the project's Position track maplayer.

Three things about where the nodes go

  • They sit immediately before <defaults>, and no <flags> is written. Measured against Form PSCIS in the shipped templates, QGIS orders these fieldConfiguration, aliases, splitPolicies, defaults, .... A tracking maplayer has 16 children and no style block at all - the plugin writes one that ends at defaults, constraints, constraintExpressions. The rule that a style block starts at flags (#171) governs the positional scan in rfp_qgs_style_export(), not how QGIS reads a maplayer, and the plugin's own working layer is the proof.

  • No <attributeEditorForm> and no <editorlayout>. Absent, QGIS uses the generated layout, which shows every field. A tab layout shows only what it lists, so adding one would hide the plugin's four (#159).

  • index on an alias is computed from the GeoPackage, not guessed, which is also what makes the orphan check free: a field with no column cannot be given an index. QGIS drops a form element naming an absent field silently, and this writer touches two artifacts that can drift apart.

Examples

d <- file.path(tempdir(), "trkproj")
dir.create(d, showWarnings = FALSE)
qgs <- file.path(d, "p.qgs")
file.copy(system.file("templates", "bcrestoration_mobile.qgs", package = "rfp"),
          qgs, overwrite = TRUE)
#> [1] TRUE
gpkg <- file.path(d, "tracking_layer.gpkg")
rfp_tracking_layer_create(gpkg, overwrite = TRUE)
rfp_tracking_fields_add(gpkg)
#>  Added 4 fields to "tracking_layer": track_name, track_type, track_description, and named_by
rfp_qgs_tracking_add(qgs, backup = FALSE)
#>  Added "Position track" to /tmp/RtmpfSNDuG/trkproj/p.qgs
rfp_qgs_tracking_fields_add(qgs, backup = FALSE)
#>  Configured 4 tracking fields in /tmp/RtmpfSNDuG/trkproj/p.qgs