Skip to contents

Drop themes by name, or keep only the ones named. The counterpart to rfp_qgs_theme_set(), and what curating a project's theme list needed before this existed — the alternative was reaching into an unexported internal, or QGIS Desktop.

Usage

rfp_qgs_theme_rm(path, themes = NULL, keep = NULL, backup = TRUE)

Arguments

path

Character. Path to the .qgs.

themes

Character. Theme names to remove.

keep

Character. Theme names to keep; every other theme is removed.

backup

Logical. Back up the .qgs first, outside the project (see rfp-backups). Default TRUE.

Value

Invisibly, the character vector of theme names remaining.

Details

Give exactly one of themes or keep. A name in neither is an error rather than a silent no-op: theme_rm(p, "Low detail") against a project holding "Low Detail" would otherwise report success and change nothing.

A removed theme that a layout map, map canvas, 3D view or PDF export list still names is reported with a catchable warning(), after the write: those surfaces then follow no theme and draw the current layer state, with nothing in QGIS saying so. To retire a theme into another one and re-point those references, use rfp_qgs_theme_rename(), with merge = TRUE when the other theme already exists.

Examples

src <- system.file("templates", "bcrestoration_mobile.qgs", package = "rfp")
p <- file.path(tempdir(), "trimmed.qgs")
file.copy(src, p, overwrite = TRUE)
#> [1] TRUE

rfp_qgs_theme_names(p)
#> [1] "High Detail - Crossings"       "Land Tenure"                  
#> [3] "Low Detail - Bull Trout Model" "Low Detail - Salmon Model"    
#> [5] "Low Detail - Steelhead Model" 
rfp_qgs_theme_rm(p, keep = "Land Tenure", backup = FALSE)
#> ✔ Removed 4 themes from /tmp/RtmpGuotGj/trimmed.qgs; 1 remains.