Renames a theme and re-points everything in the project that refers to it by
name. A theme is named in five places, not one, which is why rewriting the
preset's name attribute by hand leaves a project half-renamed:
Arguments
- path
Character. Path to the
.qgs.- from
Character. The theme's current name.
- to
Character. The new name.
- merge
Logical. When
toalready exists, retirefrominto it rather than refuse. DefaultFALSE. Ignored whentodoes not exist.- backup
Logical. Back up the
.qgsfirst, outside the project (see rfp-backups). DefaultTRUE.
Value
Invisibly, a data frame with one row per surface: surface and
n, the number of references re-pointed. Under merge, the preset row
counts the from presets removed.
Details
the
<visibility-preset name=>itself;a print layout map that follows the theme (
LayoutItem@followPresetName);a map canvas showing it (
mapcanvas@theme, the main canvas and each additional map view);a 3D view's terrain (
terrain@map-theme);a layout's PDF export theme list (the
pdfExportThemeslayout property,~~~-joined, where only the matching entry moves).
These are the listeners of QGIS 4.2's own mapThemeRenamed signal, so this
is the edit QGIS Desktop makes. A surface left behind does not error: a
layout map following a name that no longer exists silently draws the
project's current layer state instead, which is how a live project came to
carry a dangling followPresetName="Overview Report Map".
rfp_qgs_theme_rm() now warns when it would leave one.
Matching is by attribute on each surface, never by searching for the string: a theme name is often also a layer-tree group name, and the group and the preset's group state are left alone.
Refuses, writing nothing, when from is not in the project, when from
equals to, or when to already exists - as QGIS's renameMapTheme()
does. A project that already carries both names is retired into the
existing one with merge = TRUE: every reference to from is re-pointed at
to, the from preset is removed, and to's own preset is left as it is.
A PDF export list naming both keeps to once. Removing from with
rfp_qgs_theme_rm() instead would leave those references following a theme
that no longer exists. If two presets are named from, both are renamed (or
both removed under merge), as rfp_qgs_theme_rm() removes both.
See also
Other qgs:
rfp_qgs_form_add(),
rfp_qgs_layer_rm(),
rfp_qgs_postgres_add(),
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_theme_unbury(),
rfp_qgs_themes(),
rfp_qgs_vector_add(),
rfp_qwc_config_create(),
rfp_qwc_probe(),
rfp_raster_style_path(),
rfp_raster_styles()
Examples
src <- system.file("templates", "bcrestoration_mobile.qgs", package = "rfp")
p <- file.path(tempdir(), "renamed.qgs")
file.copy(src, p, overwrite = TRUE)
#> [1] TRUE
rfp_qgs_theme_rename(p, "Land Tenure", "Tenure", backup = FALSE)
#> ✔ Renamed theme "Land Tenure" to "Tenure" in /tmp/RtmpGuotGj/renamed.qgs.
rfp_qgs_theme_names(p)
#> [1] "High Detail - Crossings" "Tenure"
#> [3] "Low Detail - Bull Trout Model" "Low Detail - Salmon Model"
#> [5] "Low Detail - Steelhead Model"
