From e06dbc077120aca5493aa6dafb3d633033bd0365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 03:26:48 -0500 Subject: [PATCH 1/4] fix(engine): removing a layer says which map series and presentation titles name it (#3075) --- crates/engine/src/cmd/layer.rs | 59 +++++++++++-- .../engine/src/tests/layout_removed_layer.rs | 85 ++++++++++++++++++- docs/user-guide/layouts.md | 5 +- 3 files changed, 138 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index 299308b78d..c1c76ba832 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -7502,6 +7502,7 @@ fn follow_removal(s: &mut Session, names: &[String]) { terrain_follows_removal(s, names); square_labels_follow_removal(s, names); layouts_follow_removal(s, names); + pages_follow_removal(s, names); // A legend that left it out forgets it. for n in names { legends_follow_layer(s, n, None); @@ -7534,14 +7535,7 @@ fn layouts_follow_removal(s: &mut Session, names: &[String]) { } _ => continue, }; - let mut lost = false; - for name in gone.iter().filter(|n| reads.iter().any(|r| r.eq_ignore_ascii_case(n))) { - lost = true; - if !named.iter().any(|n| n.eq_ignore_ascii_case(name)) { - named.push(name.as_str()); - } - } - count += usize::from(lost); + count += usize::from(reads_removed(&reads, &gone, &mut named)); } } if count == 0 { @@ -7556,6 +7550,55 @@ fn layouts_follow_removal(s: &mut Session, names: &[String]) { s.notify_text(crate::notice_text::NoticeText::format(key, [("count", count.to_string().into()), ("names", names.into())]), false); } +/// Whether `reads`, the layer names one item reads, hold a removed one: each of `gone` it reads +/// joins `named`, once. +fn reads_removed<'a>(reads: &[&str], gone: &[&'a String], named: &mut Vec<&'a str>) -> bool { + let mut lost = false; + for name in gone.iter().filter(|n| reads.iter().any(|r| r.eq_ignore_ascii_case(n))) { + lost = true; + if !named.iter().any(|n| n.eq_ignore_ascii_case(name)) { + named.push(name.as_str()); + } + } + lost +} + +/// After layers called `names` are removed: a map series' index layer, and the layer statistics +/// (#2853) in a presentation map page's title, keep the name, so a layer of that name brings them +/// back: how many series and titles, said once (#3075). Which of them read the active map is as for +/// a rename (`references_follow_layer`). +fn pages_follow_removal(s: &mut Session, names: &[String]) { + use rustgis_map::presentation::PageKind; + + let gone: Vec<&String> = names.iter().filter(|n| named_layers(s, n) == 0).collect(); + let map_name = &s.map().name; + let mut named: Vec<&str> = Vec::new(); + let mut count = 0usize; + for layout in &s.project.layouts { + if let Some(series) = &layout.series + && frames_showing(layout, map_name).contains(&series.frame) + { + count += usize::from(reads_removed(&[&series.layer], &gone, &mut named)); + } + } + for page in s.project.presentations.iter().flat_map(|p| &p.pages) { + if matches!(&page.kind, PageKind::Map { map, .. } if map.eq_ignore_ascii_case(map_name)) { + let reads: Vec<&str> = rustgis_map::layout::stat_tokens(&page.title).iter().map(|t| t.layer).collect(); + count += usize::from(reads_removed(&reads, &gone, &mut named)); + } + } + if count == 0 { + return; + } + let key = if named.len() == 1 { + "{count} map series or presentation title(s) name the removed layer {names}: a series exports only its current page, and a title shows the figure as written, until a layer of that name comes back" + } else { + "{count} map series or presentation title(s) name the removed layers {names}: a series exports only its current page, and a title shows the figure as written, until a layer of that name comes back" + }; + let names = named.iter().map(|n| format!("'{n}'")).collect::>().join(", "); + s.notify_text(crate::notice_text::NoticeText::format(key, [("count", count.to_string().into()), ("names", names.into())]), false); +} + /// After layers called `names` are removed: point labels turned square to one of them (#2263), /// and labels curved along one (#2262), keep its name, so a layer of that name brings their line /// back, and are placed as auto, or as without a guide, meanwhile: said once a kind, naming the diff --git a/crates/engine/src/tests/layout_removed_layer.rs b/crates/engine/src/tests/layout_removed_layer.rs index 1ced975751..cc8aac6654 100644 --- a/crates/engine/src/tests/layout_removed_layer.rs +++ b/crates/engine/src/tests/layout_removed_layer.rs @@ -1,5 +1,6 @@ //! Deleting a layer says how many layout elements name it: a chart's, table's or colorbar's -//! layer, and a text's layer statistics (#3020). The elements keep the name. +//! layer, and a text's layer statistics (#3020). So for map series and presentation titles +//! (#3075). All keep the name. use super::*; use rustgis_map::layout::ElementKind; @@ -117,3 +118,85 @@ fn removing_a_group_says_it_too() { s.run("group.add", &json!({"name": "Places", "layers": ["Cities"]})).unwrap(); assert_eq!(lost(&mut s, "group.remove", json!({"group": "Places"})), [said(1, "'Cities'")]); } + +/// The notices `command` gives about map series and presentation titles that lost a layer. +fn lost_pages(s: &mut Session, command: &str, params: Value) -> Vec { + let mark = s.notice_mark(); + s.run(command, ¶ms).unwrap(); + s.notices_since(mark).iter().map(|n| n.text.clone()).filter(|t| t.contains("map series or presentation title(s)")).collect() +} + +fn said_pages(count: usize, names: &str) -> String { + let layers = if names.contains(", ") { "layers" } else { "layer" }; + format!( + "{count} map series or presentation title(s) name the removed {layers} {names}: a series exports only its current page, and a title shows the figure as written, until a layer of that name comes back" + ) +} + +fn series(s: &mut Session, layer: &str) { + s.run("layout.series", &json!({"layer": layer, "nameField": "name"})).unwrap(); +} + +fn titled(s: &mut Session, title: &str) { + if s.project.presentations.is_empty() { + s.run("presentation.new", &json!({"name": "Talk"})).unwrap(); + } + s.run("presentation.mapPage", &json!({"title": title})).unwrap(); +} + +#[test] +fn removing_a_series_index_layer_says_it() { + let mut s = with_layout(); + series(&mut s, "Countries"); + assert_eq!(lost_pages(&mut s, "layer.remove", json!({"layer": "Countries"})), [said_pages(1, "'Countries'")]); + assert_eq!(s.project.layouts[0].series.as_ref().map(|r| r.layer.as_str()), Some("Countries"), "the series keeps the name"); + assert_eq!(lost_pages(&mut s, "edit.undo", Value::Null), Vec::::new()); +} + +#[test] +fn removing_a_layer_a_presentation_title_counts_says_it() { + let mut s = world(); + // Two statistics of the layer in one title count it once; each page counts. + titled(&mut s, "{count:countries} countries, {sum:Countries:pop_est} people"); + titled(&mut s, "{count:Countries}"); + let pages = s.project.presentations[0].pages.len(); + assert_eq!(lost_pages(&mut s, "layer.remove", json!({"layer": "Countries"})), [said_pages(2, "'Countries'")]); + assert_eq!(s.project.presentations[0].pages.len(), pages); + assert_eq!(s.project.presentations[0].pages.last().map(|p| p.title.as_str()), Some("{count:Countries}")); +} + +#[test] +fn a_series_and_titles_of_several_layers_are_said_once() { + let mut s = with_layout(); + series(&mut s, "Countries"); + titled(&mut s, "{count:Countries} and {count:Cities}"); + s.run("group.add", &json!({"name": "Places", "layers": ["Countries", "Cities"]})).unwrap(); + let said_now = lost_pages(&mut s, "group.remove", json!({"group": "Places"})); + assert_eq!(said_now.len(), 1, "{said_now:?}"); + assert!(said_now[0].starts_with("2 map series or presentation title(s) name the removed layers "), "{said_now:?}"); + for name in ["'Countries'", "'Cities'"] { + assert_eq!(said_now[0].matches(name).count(), 1, "{said_now:?}"); + } +} + +#[test] +fn a_series_or_title_no_removed_layer_is_in_says_nothing() { + let mut s = with_layout(); + series(&mut s, "Countries"); + titled(&mut s, "{count:Countries} in {map}"); + assert_eq!(lost_pages(&mut s, "layer.remove", json!({"layer": "Cities"})), Vec::::new()); + // Another layer of the name stays: nothing is lost until the last goes. + s.run("layer.rename", &json!({"layer": "Lakes", "name": "Countries"})).unwrap(); + let first = s.map().layers.iter().find(|l| l.name == "Countries").unwrap().id; + assert_eq!(lost_pages(&mut s, "layer.remove", json!({"layer": first})), Vec::::new()); +} + +#[test] +fn a_series_and_titles_of_another_map_are_not_counted() { + let mut s = with_layout(); + series(&mut s, "Countries"); + titled(&mut s, "{count:Countries}"); + s.run("map.new", &json!({"name": "Other"})).unwrap(); + s.run("layer.addSample", &json!({"name": "countries"})).unwrap(); + assert_eq!(lost_pages(&mut s, "layer.remove", json!({"layer": "Countries"})), Vec::::new()); +} diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 0af58791e4..9603605ab0 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -504,8 +504,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu in a presentation's map pages of it); a text that a longer name would take past the characters a text holds, or that a name with a brace (which a token can't hold) would break, keeps the old name, and the rename says so; deleting it leaves them as written, and when layout elements still - name it (a text's tokens, or a chart's, table's or colorbar's layer), says how many. A layer - read in place covers what is loaded, as a chart does, and a warning says so. A token with no + name it (a text's tokens, or a chart's, table's or colorbar's layer), says how many. It also + says how many map series (by their index layer) and presentation map page titles (by their + tokens) name it. A layer read in place covers what is loaded, as a chart does, and a warning says so. A token with no figure (no such layer or field, a field with no numbers, a raster layer, or a sum, mean, least or greatest written without its field) stays as written, and a warning names what is missing. Both warnings come when the text is added or changed, or its layout is made or imported, or when From 5e00b435d49e3efcb6244b78722f746dee6ca168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 03:52:18 -0500 Subject: [PATCH 2/4] fix(engine): exporting a map series without its index layer says the PDF holds one page (#3075) --- crates/engine/src/cmd/layout/export.rs | 8 ++++ .../engine/src/tests/layout_removed_layer.rs | 38 +++++++++++++++++++ docs/user-guide/layouts.md | 3 +- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/layout/export.rs b/crates/engine/src/cmd/layout/export.rs index 88ce085acd..093e8a053d 100644 --- a/crates/engine/src/cmd/layout/export.rs +++ b/crates/engine/src/cmd/layout/export.rs @@ -101,6 +101,14 @@ pub(in crate::cmd::layout) fn layout_bytes_inner( // Only a whole-series PDF names every page. let info = series_info(s, li, current); let names = if all && pdf { series_pages(s, li) } else { None }; + // A series whose index layer is gone has no pages to step through (#3075). + if all + && pdf + && info.is_none() + && let Some(series) = &saved.series + { + s.warn(format!("The map series' index layer '{}' isn't in its frame's map: the PDF holds the current page only", series.layer)); + } let total = info.as_ref().map_or(1, |i| i.0); // Every page of a map series (PDF), or just the layout as it is now. let pages: Vec = match (&names, all && pdf) { diff --git a/crates/engine/src/tests/layout_removed_layer.rs b/crates/engine/src/tests/layout_removed_layer.rs index cc8aac6654..2e38bb5e62 100644 --- a/crates/engine/src/tests/layout_removed_layer.rs +++ b/crates/engine/src/tests/layout_removed_layer.rs @@ -200,3 +200,41 @@ fn a_series_and_titles_of_another_map_are_not_counted() { s.run("layer.addSample", &json!({"name": "countries"})).unwrap(); assert_eq!(lost_pages(&mut s, "layer.remove", json!({"layer": "Countries"})), Vec::::new()); } + +/// What exporting the first layout to a file named `file` warns about its map series' index layer. +fn export_warnings(s: &mut Session, file: &str, all: bool) -> Vec { + let dir = std::env::temp_dir().join(format!("rustgis-3075-{}-{:?}", std::process::id(), std::thread::current().id())); + std::fs::create_dir_all(&dir).unwrap(); + let path = dir.join(file); + let mark = s.notice_mark(); + s.run("layout.export", &json!({"path": path, "dpi": 36, "allPages": all})).unwrap(); + std::fs::remove_dir_all(&dir).unwrap(); + s.notices_since(mark).iter().map(|n| n.text.clone()).filter(|t| t.contains("index layer")).collect() +} + +const ONE_PAGE: &str = "The map series' index layer 'Countries' isn't in its frame's map: the PDF holds the current page only"; + +#[test] +fn exporting_a_series_without_its_index_layer_says_the_pdf_holds_one_page() { + let mut s = with_layout(); + series(&mut s, "Countries"); + s.run("layer.remove", &json!({"layer": "Countries"})).unwrap(); + assert_eq!(export_warnings(&mut s, "series.pdf", true), [ONE_PAGE]); +} + +#[test] +fn an_export_that_never_wrote_the_series_says_nothing_of_its_index_layer() { + let mut s = with_layout(); + // No series. + assert_eq!(export_warnings(&mut s, "plain.pdf", true), Vec::::new()); + series(&mut s, "Countries"); + s.run("layer.remove", &json!({"layer": "Countries"})).unwrap(); + // One page asked for, or a format that only ever writes one. + assert_eq!(export_warnings(&mut s, "page.pdf", false), Vec::::new()); + assert_eq!(export_warnings(&mut s, "page.png", true), Vec::::new()); + assert_eq!(export_warnings(&mut s, "page.svg", true), Vec::::new()); + // The layer back, the series is whole again. + s.run("edit.undo", &Value::Null).unwrap(); + assert!(s.map().layer_by_name("Countries").is_some()); + assert_eq!(export_warnings(&mut s, "series.pdf", false), Vec::::new()); +} diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 9603605ab0..ac0f09dda7 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -809,7 +809,8 @@ The locator outlines the main frame's changing extent as the series turns its pa **Export Layout** writes all pages to PDF by default, but only the **first 500** when there are more, with a warning. Split longer books' index data into layers of at most 500 features. `layout.export` with `"allPages":false` writes only the current PDF page; PNG and SVG always -write the current page. +write the current page. When the index layer is no longer in the series frame's map (it was +removed, say), the PDF holds only the current page, and the export says so. ### Mark the page's own feature From 2b2fa0484e3ad387c22f9e31a859980c39aceac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 03:53:51 -0500 Subject: [PATCH 3/4] test(engine): ask for every series page once the index layer is back (#3075) --- crates/engine/src/tests/layout_removed_layer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine/src/tests/layout_removed_layer.rs b/crates/engine/src/tests/layout_removed_layer.rs index 2e38bb5e62..49b9bdf68e 100644 --- a/crates/engine/src/tests/layout_removed_layer.rs +++ b/crates/engine/src/tests/layout_removed_layer.rs @@ -236,5 +236,5 @@ fn an_export_that_never_wrote_the_series_says_nothing_of_its_index_layer() { // The layer back, the series is whole again. s.run("edit.undo", &Value::Null).unwrap(); assert!(s.map().layer_by_name("Countries").is_some()); - assert_eq!(export_warnings(&mut s, "series.pdf", false), Vec::::new()); + assert_eq!(export_warnings(&mut s, "series.pdf", true), Vec::::new()); } From 7734f17dda54d5a684e34bc0fe56dc85743d337a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 04:30:05 -0500 Subject: [PATCH 4/4] refactor(engine): one notice tail for removed layers, clean up the export test (#3075) --- crates/engine/src/cmd/layer.rs | 42 +++++++++++-------- .../engine/src/tests/layout_removed_layer.rs | 3 +- docs/user-guide/layouts.md | 11 ++--- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/crates/engine/src/cmd/layer.rs b/crates/engine/src/cmd/layer.rs index c1c76ba832..a353ed8238 100644 --- a/crates/engine/src/cmd/layer.rs +++ b/crates/engine/src/cmd/layer.rs @@ -7509,6 +7509,18 @@ fn follow_removal(s: &mut Session, names: &[String]) { } } +/// The notice that `count` items name the removed layers `named`, in the first of `keys` for one +/// name and the second for more. `None` when no item does. +fn removed_notice(keys: [&'static str; 2], count: usize, named: &[&str]) -> Option { + if count == 0 { + return None; + } + let [one, more] = keys; + let key = if named.len() == 1 { one } else { more }; + let names = named.iter().map(|n| format!("'{n}'")).collect::>().join(", "); + Some(crate::notice_text::NoticeText::format(key, [("count", count.to_string().into()), ("names", names.into())])) +} + /// After layers called `names` are removed: a table's, chart's or colorbar's layer, and a text's /// layer statistics (#2853), keep the name, so a layer of that name brings them back, and are drawn /// without it meanwhile: how many elements, said once. Which elements read the active map is as for @@ -7538,16 +7550,13 @@ fn layouts_follow_removal(s: &mut Session, names: &[String]) { count += usize::from(reads_removed(&reads, &gone, &mut named)); } } - if count == 0 { - return; + let keys = [ + "{count} layout element(s) name the removed layer {names}: they are drawn without it until a layer of that name comes back", + "{count} layout element(s) name the removed layers {names}: they are drawn without it until a layer of that name comes back", + ]; + if let Some(notice) = removed_notice(keys, count, &named) { + s.notify_text(notice, false); } - let key = if named.len() == 1 { - "{count} layout element(s) name the removed layer {names}: they are drawn without it until a layer of that name comes back" - } else { - "{count} layout element(s) name the removed layers {names}: they are drawn without it until a layer of that name comes back" - }; - let names = named.iter().map(|n| format!("'{n}'")).collect::>().join(", "); - s.notify_text(crate::notice_text::NoticeText::format(key, [("count", count.to_string().into()), ("names", names.into())]), false); } /// Whether `reads`, the layer names one item reads, hold a removed one: each of `gone` it reads @@ -7587,16 +7596,13 @@ fn pages_follow_removal(s: &mut Session, names: &[String]) { count += usize::from(reads_removed(&reads, &gone, &mut named)); } } - if count == 0 { - return; + let keys = [ + "{count} map series or presentation title(s) name the removed layer {names}: a series exports only its current page, and a title shows the figure as written, until a layer of that name comes back", + "{count} map series or presentation title(s) name the removed layers {names}: a series exports only its current page, and a title shows the figure as written, until a layer of that name comes back", + ]; + if let Some(notice) = removed_notice(keys, count, &named) { + s.notify_text(notice, false); } - let key = if named.len() == 1 { - "{count} map series or presentation title(s) name the removed layer {names}: a series exports only its current page, and a title shows the figure as written, until a layer of that name comes back" - } else { - "{count} map series or presentation title(s) name the removed layers {names}: a series exports only its current page, and a title shows the figure as written, until a layer of that name comes back" - }; - let names = named.iter().map(|n| format!("'{n}'")).collect::>().join(", "); - s.notify_text(crate::notice_text::NoticeText::format(key, [("count", count.to_string().into()), ("names", names.into())]), false); } /// After layers called `names` are removed: point labels turned square to one of them (#2263), diff --git a/crates/engine/src/tests/layout_removed_layer.rs b/crates/engine/src/tests/layout_removed_layer.rs index 49b9bdf68e..dc4fd4ed2a 100644 --- a/crates/engine/src/tests/layout_removed_layer.rs +++ b/crates/engine/src/tests/layout_removed_layer.rs @@ -207,8 +207,9 @@ fn export_warnings(s: &mut Session, file: &str, all: bool) -> Vec { std::fs::create_dir_all(&dir).unwrap(); let path = dir.join(file); let mark = s.notice_mark(); - s.run("layout.export", &json!({"path": path, "dpi": 36, "allPages": all})).unwrap(); + let run = s.run("layout.export", &json!({"path": path, "dpi": 36, "allPages": all})); std::fs::remove_dir_all(&dir).unwrap(); + run.unwrap(); s.notices_since(mark).iter().map(|n| n.text.clone()).filter(|t| t.contains("index layer")).collect() } diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index ac0f09dda7..f3a0341c97 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -504,11 +504,12 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu in a presentation's map pages of it); a text that a longer name would take past the characters a text holds, or that a name with a brace (which a token can't hold) would break, keeps the old name, and the rename says so; deleting it leaves them as written, and when layout elements still - name it (a text's tokens, or a chart's, table's or colorbar's layer), says how many. It also - says how many map series (by their index layer) and presentation map page titles (by their - tokens) name it. A layer read in place covers what is loaded, as a chart does, and a warning says so. A token with no - figure (no such layer or field, a field with no numbers, a raster layer, or a sum, mean, least - or greatest written without its field) stays as written, and a warning names what is missing. + name it (a text's tokens, or a chart's, table's or colorbar's layer), says how many. It also says + how many map series (by their index layer) and presentation map page titles (by their tokens) + name it. A layer read in place covers what is loaded, as a chart does, and a warning says so. A + token with no figure (no such layer or field, a field with no numbers, a raster layer, or a sum, + mean, least or greatest written without its field) stays as written, and a warning names what is + missing. Both warnings come when the text is added or changed, or its layout is made or imported, or when another map frame becomes the first (it is given another map, the one before it is deleted or drawn over it, or its map is deleted), not when the page is exported. A presentation map page's