
Make Every Layer a Map Theme Shows Actually Draw
Source:R/rfp_qgs_theme_unbury.R
rfp_qgs_theme_unbury.RdA map theme records which layer-tree groups it checks by path, and a
layer only draws where every group above it is checked (#216). So anything
that changes a group's path - renaming it, moving it, deleting it, a hand
edit in QGIS Desktop - strands the reference, the group reads as unchecked,
and every layer inside is present, enumerated in the theme, visible="1"
and invisible. Nothing errors and every count reads healthy.
Value
Invisibly, a list of ticked (a theme/group_path data frame) and
pruned (character vector of the paths dropped).
Details
This repairs that, and it is cause-agnostic on purpose: it asks what each theme shows and makes those layers reachable, without being told what broke. It therefore covers a project that was renamed, one whose groups were reorganised, and one that arrived carrying the damage from something else.
Two operations, both reported:
tick - check the group holding every visible layer a theme currently buries, and every group above it.
prune - drop group references that name no group in the tree. They are inert, since QGIS matches group state by path, so this changes no rendering and leaves the project asserting only things that are true.
Nothing is ever unchecked. Only additions are made, so a layer a theme deliberately conceals cannot be revealed - which is what makes this safe to run over a whole project rather than a named theme.
A preset recording no group state at all is left alone. That is presence-significant: one is inferred on the next write, so ticking groups into it would turn "not recorded" into a full declaration nobody asked for.
Why not re-apply the registry
rfp_qgs_theme_add() rewrites the themes the shipped registry carries,
and derives their group state, so it repairs those. It cannot repair a theme
the registry has never seen, and real projects are mostly those - measured,
sern_fraser_2024 carries 16 presets and restoration_wedzin_kwa 15 against
the registry's 8. Re-applying the registry took fraser from 29 buried entries
to 23 and left wedzin kwa at 22; this takes both to 0.
See also
Other qgs:
rfp_qgs_form_add(),
rfp_qgs_layer_rm(),
rfp_qgs_preview_set(),
rfp_qgs_raster_add(),
rfp_qgs_service_add(),
rfp_qgs_service_rm(),
rfp_qgs_services(),
rfp_qgs_style_export(),
rfp_qgs_style_set(),
rfp_qgs_subset_get(),
rfp_qgs_subset_set(),
rfp_qgs_theme_add(),
rfp_qgs_theme_lookup(),
rfp_qgs_theme_names(),
rfp_qgs_theme_rm(),
rfp_qgs_theme_set(),
rfp_qgs_themes(),
rfp_qgs_vector_add(),
rfp_qwc_config_create(),
rfp_raster_style_path(),
rfp_raster_styles()
Examples
qgs <- file.path(tempdir(), "unbury_example.qgs")
file.copy(
system.file("templates", "bcfishpass_mobile.qgs", package = "rfp"),
qgs,
overwrite = TRUE
)
#> [1] TRUE
# A shipped template is already correct, so there is nothing to do.
res <- rfp_qgs_theme_unbury(qgs)
#> ℹ Nothing to do - every visible theme entry draws.
nrow(res$ticked)
#> [1] 0
unlink(qgs)