From 66b5242d47efe167fe3424a667c837ad2d772ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 05:38:20 -0500 Subject: [PATCH 01/11] feat(ui): the Publication Layout Wizard asks for the map extent and the layout's name (#3103) --- crates/ui-egui/src/publicationwizard/map.rs | 280 ++++++++++++++++++ crates/ui-egui/src/publicationwizard/mod.rs | 64 ++-- .../ui-egui/src/publicationwizard/review.rs | 5 +- crates/ui-egui/src/publicationwizard/texts.rs | 5 +- docs/user-guide/layouts.md | 29 +- 5 files changed, 349 insertions(+), 34 deletions(-) create mode 100644 crates/ui-egui/src/publicationwizard/map.rs diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs new file mode 100644 index 0000000000..138602e169 --- /dev/null +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -0,0 +1,280 @@ +//! The wizard's map step. +use super::*; + +/// Which area the map frame shows. +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum Area { + /// The view, left to `layout.publication`. + View, + /// The features a layer shows: the layer's id, in the map named. + Layer { map: String, id: u32 }, + /// The selected features of the map named. + Selection { map: String }, +} + +/// The name `layout.publication` gives when none is: data, not translated. +pub(super) const DEFAULT_NAME: &str = "Publication"; + +/// A side sent for an extent with none along it (a point, a straight line), in degrees. +const MIN_SIDE: f64 = 0.01; + +/// The map step: the area the map frame shows and the layout's name. +pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { + let map = s.map(); + // Top first, as Contents lists them. A layer's kept extent here; the one it shows is read at + // Create, as it walks the rows under a definition query. + let framable = || map.layers.iter().rev().filter(|l| !l.extent().is_empty()); + egui::Grid::new("publication_wizard_map").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { + ui.label(tl!("Map extent")); + ui.vertical(|ui| { + if ui.radio(d.area == Area::View, tl!("View")).on_hover_text(tl!("What the map view shows.")).clicked() { + d.area = Area::View; + } + ui.horizontal(|ui| { + let picked = match &d.area { + Area::Layer { map: name, id } if *name == map.name => Some(*id), + _ => None, + }; + let top = framable().next().map(|l| l.id); + if ui.add_enabled(top.is_some(), egui::RadioButton::new(matches!(d.area, Area::Layer { .. }), tl!("Layer"))).clicked() + && let Some(id) = picked.or(top) + { + d.area = Area::Layer { map: map.name.clone(), id }; + } + if let Some(id) = picked { + let shown = framable().find(|l| l.id == id).map_or_else(String::new, |l| l.name.clone()); + egui::ComboBox::from_id_salt("publication_wizard_map_layer") + .selected_text(shown) + .width(ui.available_width().min(180.0)) + .show_ui(ui, |ui| { + for l in framable() { + if ui.selectable_label(l.id == id, l.name.as_str()).clicked() { + d.area = Area::Layer { map: map.name.clone(), id: l.id }; + } + } + }); + } + }); + let selection = egui::RadioButton::new(matches!(d.area, Area::Selection { .. }), tl!("Selection")); + if ui + .add_enabled(map.selection_count() > 0, selection) + .on_hover_text(tl!("The selected features.")) + .on_disabled_hover_text(tl!("Nothing is selected in the map.")) + .clicked() + { + d.area = Area::Selection { map: map.name.clone() }; + } + }); + ui.end_row(); + let label = ui.label(tl!("Name")); + ui.add(egui::TextEdit::singleline(&mut d.name).hint_text(DEFAULT_NAME).desired_width(field_width(ui))).labelled_by(label.id); + ui.end_row(); + }); +} + +/// How the review names the area. +pub(super) fn area_label(s: &Session, area: &Area) -> String { + match area { + Area::View => tl!("The view").to_string(), + Area::Layer { map, id } => s + .map() + .layers + .iter() + .find(|l| l.id == *id && s.map().name == *map) + .map_or_else(|| tl!("(none)").to_string(), |l| i18n::fmt("Layer: {layer}", &[("layer", &l.name)])), + Area::Selection { .. } => tl!("Selected features").to_string(), + } +} + +/// `e` as `layout.publication` takes it: cut to ±180 and ±90, a side of no length widened to +/// [`MIN_SIDE`]; none when nothing is left to frame. +fn framed(e: Extent) -> Option<[f64; 4]> { + if e.is_empty() { + return None; + } + let side = |min: f64, max: f64, limit: f64| { + let pad = if max > min { 0.0 } else { MIN_SIDE / 2.0 }; + let (min, max) = ((min - pad).max(-limit), (max + pad).min(limit)); + (min < max).then_some((min, max)) + }; + let ((west, east), (south, north)) = (side(e.min_x, e.max_x, 180.0)?, side(e.min_y, e.max_y, 90.0)?); + Some([west, south, east, north]) +} + +/// The `extent` to send for `area`, none for the view; an area that is gone since it was picked is +/// an error rather than another one framed. +pub(super) fn area_extent(s: &Session, area: &Area) -> Result, String> { + let map = s.map(); + let extent = match area { + Area::View => return Ok(None), + Area::Layer { map: name, .. } | Area::Selection { map: name } if *name != map.name => { + return Err(tl!("Another map is open since the map extent was picked: pick it again.").to_string()); + } + Area::Layer { id, .. } => map + .layers + .iter() + .find(|l| l.id == *id) + .ok_or_else(|| tl!("The layer picked is no longer in the map: pick the map extent again.").to_string())? + .shown_extent(), + Area::Selection { .. } => { + if map.selection_count() == 0 { + return Err(tl!("Nothing is selected: pick the map extent again.").to_string()); + } + map.selection_extent() + } + }; + framed(extent).map(Some).ok_or_else(|| tl!("There is nothing to frame there: pick another map extent.").to_string()) +} + +#[cfg(test)] +mod tests { + use super::harness::*; + use super::*; + use egui::accesskit::Role; + use egui_kittest::kittest::{NodeT, Queryable}; + + fn close(got: Option<[f64; 4]>, want: [f64; 4]) { + let got = got.expect("an extent"); + assert!(got.iter().zip(want).all(|(g, w)| (g - w).abs() < 1e-9), "{got:?} is not {want:?}"); + } + + /// A side of no length (a point, a straight line) is widened to 0.01°, the rest is left as it + /// is; what lies past ±180 and ±90 is cut; nothing left to frame is none. + #[test] + fn an_extent_is_widened_and_cut_to_what_the_command_takes() { + close(framed(Extent::new(10.0, 20.0, 10.0, 20.0)), [9.995, 19.995, 10.005, 20.005]); + close(framed(Extent::new(10.0, 20.0, 12.0, 20.0)), [10.0, 19.995, 12.0, 20.005]); + close(framed(Extent::new(10.0, 20.0, 10.0, 22.0)), [9.995, 20.0, 10.005, 22.0]); + close(framed(Extent::new(180.0, 90.0, 180.0, 90.0)), [179.995, 89.995, 180.0, 90.0]); + close(framed(Extent::new(-190.0, -95.0, 200.0, 91.0)), [-180.0, -90.0, 180.0, 90.0]); + assert_eq!(framed(Extent::EMPTY), None); + assert_eq!(framed(Extent::new(190.0, 0.0, 200.0, 1.0)), None); + } + + /// The view sends no extent; a layer sends the extent of the features it shows; the + /// selection, that of the selected features. + #[test] + fn each_area_sends_its_own_extent() { + let mut app = app(); + let map = app.session.map().name.clone(); + assert_eq!(area_extent(&app.session, &Area::View), Ok(None)); + app.run("layer.definitionQuery", json!({"layer": "Cities", "where": "pop_max > 10000000"})).unwrap(); + let (id, shown, all) = { + let l = app.session.map().layers.iter().find(|l| l.name == "Cities").unwrap(); + (l.id, l.shown_extent(), l.extent()) + }; + assert_ne!(shown, all, "the query narrows it"); + assert_eq!(area_extent(&app.session, &Area::Layer { map: map.clone(), id }), Ok(framed(shown))); + app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); + let selected = app.session.map().selection_extent(); + let got = area_extent(&app.session, &Area::Selection { map }).unwrap(); + assert_eq!(got, framed(selected)); + assert!(got.is_some_and(|[w, s, e, n]| w < e && s < n), "one point, framed: {got:?}"); + } + + /// A layer removed, a selection cleared or another map since the area was picked is refused, + /// saying so, rather than framing something else. + #[test] + fn an_area_gone_is_refused() { + let mut app = app(); + let map = app.session.map().name.clone(); + let id = app.session.map().layers.iter().find(|l| l.name == "Rivers").unwrap().id; + let layer = Area::Layer { map: map.clone(), id }; + let selection = Area::Selection { map }; + assert_eq!(area_extent(&app.session, &selection), Err("Nothing is selected: pick the map extent again.".to_string())); + app.run("layer.remove", json!({"layer": "Rivers"})).unwrap(); + assert_eq!( + area_extent(&app.session, &layer), + Err("The layer picked is no longer in the map: pick the map extent again.".to_string()) + ); + app.run("map.new", json!({})).unwrap(); + let other = Err("Another map is open since the map extent was picked: pick it again.".to_string()); + assert_eq!(area_extent(&app.session, &layer), other); + assert_eq!(area_extent(&app.session, &selection), other); + } + + /// The step starts on the view; Layer picks one from the list; Selection is off with nothing + /// selected. + #[test] + fn the_step_picks_the_view_a_layer_or_the_selection() { + let mut app = app(); + open(&mut app); + app.dialogs.publication.as_mut().unwrap().step = Step::Map; + let mut h = harness(app); + let area = |h: &egui_kittest::Harness<'static, RustGisApp>| h.state().dialogs.publication.as_ref().unwrap().area.clone(); + assert_eq!(area(&h), Area::View); + assert!(h.get_by_role_and_label(Role::RadioButton, "Selection").accesskit_node().is_disabled()); + h.get_by_role_and_label(Role::RadioButton, "Layer").click(); + h.run_steps(4); + let top = h.state().session.map().layers.last().unwrap().id; + assert!(matches!(area(&h), Area::Layer { id, .. } if id == top), "{:?}", area(&h)); + h.state_mut().run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); + h.run_steps(2); + h.get_by_role_and_label(Role::RadioButton, "Selection").click(); + h.run_steps(4); + assert!(matches!(area(&h), Area::Selection { .. }), "{:?}", area(&h)); + } + + /// Create frames the layer picked and names the layout as typed; a figure takes both too. + #[test] + fn create_frames_the_area_and_names_the_layout() { + for size in ["a4", "figure-1col"] { + let mut app = app(); + open(&mut app); + let map = app.session.map().name.clone(); + app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); + let [w, s, e, n] = framed(app.session.map().selection_extent()).unwrap(); + { + let d = app.dialogs.publication.as_mut().unwrap(); + d.size = size.into(); + d.area = Area::Selection { map }; + d.name = " Tokyo sheet ".into(); + d.step = Step::Review; + } + let mut h = harness(app); + click(&mut h, "Create"); + let l = h.state().session.project.layouts.last().unwrap(); + assert_eq!(l.name, "Tokyo sheet", "{size}"); + let center = l.elements.iter().find_map(|el| match &el.kind { + rustgis_engine::map::layout::ElementKind::MapFrame { center, .. } if el.name == "Map Frame" => Some(*center), + _ => None, + }); + let c = center.expect("the map frame"); + assert!(c.x > w - 0.01 && c.x < e + 0.01 && c.y > s - 0.01 && c.y < n + 0.01, "{size}: {c:?}"); + } + } + + /// An area gone at Create is said, and the wizard stays with nothing made. + #[test] + fn create_with_the_area_gone_is_said_and_makes_nothing() { + let mut app = app(); + open(&mut app); + let map = app.session.map().name.clone(); + { + let d = app.dialogs.publication.as_mut().unwrap(); + d.area = Area::Selection { map }; + d.step = Step::Review; + } + let before = app.session.project.layouts.len(); + let mut h = harness(app); + let said = h.state().session.notice_mark(); + click(&mut h, "Create"); + let app = h.state(); + assert_eq!(app.session.project.layouts.len(), before); + assert_eq!(app.session.notice_mark(), said + 1); + assert_eq!(app.dialogs.open, Some("publicationWizard")); + } + + /// The name goes only when typed, for a sheet and for a figure. + #[test] + fn the_name_is_sent_only_when_typed() { + let app = app(); + let mut d = Draft::new(&app.session); + d.name = " ".into(); + assert!(d.params().get("name").is_none()); + d.name = "Rivers".into(); + assert_eq!(d.params()["name"], "Rivers"); + d.size = "figure-1col".into(); + assert_eq!(d.params(), json!({"profile": "figure-1col", "name": "Rivers"})); + } +} diff --git a/crates/ui-egui/src/publicationwizard/mod.rs b/crates/ui-egui/src/publicationwizard/mod.rs index 37f15ab69b..1b10200bd6 100644 --- a/crates/ui-egui/src/publicationwizard/mod.rs +++ b/crates/ui-egui/src/publicationwizard/mod.rs @@ -1,7 +1,8 @@ -//! Publication Layout Wizard: `layout.publication` asked step by step (size, style, texts, sources -//! and reference, accent), then made at once, as the New Layout › Publication Layout menu makes it -//! (#2850). +//! Publication Layout Wizard: `layout.publication` asked step by step (size, map, style, texts, +//! sources and reference, accent), then made at once, as the New Layout › Publication Layout menu +//! makes it (#2850). mod accent; +mod map; mod review; mod size; mod sources; @@ -11,12 +12,14 @@ mod texts; use crate::textform::StatLayer; use crate::{RustGisApp, i18n, theme::Tokens}; use accent::accent_step; +use map::{Area, area_extent, map_step}; use review::review_step; use rustgis_engine::Session; use rustgis_engine::cmd::layout::{ MAX_PUBLICATION_LINES, MAX_PUBLICATION_TEXT, PUBLICATION_DEFAULT_REFERENCE, PUBLICATION_HEADINGS, PUBLICATION_PROFILES, publication_style_accent, }; +use rustgis_engine::geom::Extent; use rustgis_engine::map::Map; use rustgis_engine::map::layout::PAGES; use serde_json::{Value, json}; @@ -29,6 +32,7 @@ use texts::texts_step; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Step { Size, + Map, Style, Texts, Sources, @@ -88,6 +92,9 @@ pub struct Draft { /// A page size's id (`a4`, from [`PAGES`]) or a figure's profile id (`figure-1col`). pub size: String, pub orientation: Orientation, + pub area: Area, + /// The layout's name; empty leaves it to the command. + pub name: String, pub style: String, pub title: String, /// Whether the title was typed; until then it is the active map's name, as the menu's. @@ -126,6 +133,8 @@ impl Draft { step: Step::Size, size: "a4".into(), orientation: Orientation::Auto, + area: Area::View, + name: String::new(), style: "classic".into(), title: s.map().name.clone(), title_typed: false, @@ -160,9 +169,9 @@ impl Draft { /// The steps this draft goes through, in order. fn steps(&self) -> &'static [Step] { if self.figure() { - return &[Step::Size, Step::Review]; + return &[Step::Size, Step::Map, Step::Review]; } - &[Step::Size, Step::Style, Step::Texts, Step::Sources, Step::Accent, Step::Review] + &[Step::Size, Step::Map, Step::Style, Step::Texts, Step::Sources, Step::Accent, Step::Review] } /// The step `by` places from this one, if there is one. @@ -181,6 +190,9 @@ impl Draft { (false, Orientation::Landscape) => format!("{}-landscape", self.size), }; let mut p = json!({"profile": profile}); + if !self.name.trim().is_empty() { + p["name"] = json!(self.name.trim()); + } if self.figure() { return p; } @@ -334,6 +346,7 @@ fn size_label(id: &str) -> String { fn step_name(step: Step) -> &'static str { match step { Step::Size => tl_raw!("Size"), + Step::Map => tl_raw!("Map"), Step::Style => tl_raw!("Style"), Step::Texts => tl_raw!("Texts"), Step::Sources => tl_raw!("Sources and reference"), @@ -422,11 +435,12 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { .auto_shrink([false, false]) .show(ui, |ui| match d.step { Step::Size => size_step(ui, &mut d), + Step::Map => map_step(ui, &app.session, &mut d), Step::Style => style_step(ui, &mut d, t.accent), Step::Texts => texts_step(ui, &mut d, app.session.map()), Step::Sources => sources_step(ui, &mut d, app.session.map()), Step::Accent => accent_step(ui, &mut d, t.accent), - Step::Review => review_step(ui, &d), + Step::Review => review_step(ui, &app.session, &d), }); ui.separator(); let size = egui::vec2(84.0, 28.0); @@ -451,8 +465,17 @@ pub fn show(app: &mut RustGisApp, ctx: &egui::Context) { }); }); // A layout the command refuses is said (a map with no extent), and the wizard stays. - if create && crate::ribbon::make_publication(app, d.params()) { - close = true; + if create { + match area_extent(&app.session, &d.area) { + Ok(extent) => { + let mut params = d.params(); + if let Some(extent) = extent { + params["extent"] = json!(extent); + } + close |= crate::ribbon::make_publication(app, params); + } + Err(e) => app.session.notify(e, true), + } } if !open || close { app.dialogs.open = None; @@ -533,6 +556,7 @@ mod tests { assert_eq!(d.title, name); assert!(d.subtitle.is_empty() && d.note.is_empty() && d.sources.is_empty() && d.author.is_empty()); assert!(d.accent.is_none() && !d.no_author); + assert!(d.area == Area::View && d.name.is_empty()); assert_eq!(app.dialogs.open, Some("publicationWizard")); app.dialogs.publication.as_mut().unwrap().subtitle = "Kept".into(); open(&mut app); @@ -570,8 +594,8 @@ mod tests { assert_eq!(d.params(), json!({"profile": "figure-1col"})); } - /// A sheet goes through the six steps; a figure goes from its size to the review, the steps - /// it takes nothing from skipped both ways. Back is off on the first step; Next becomes + /// A sheet goes through the seven steps; a figure goes from its size to its map and the review, + /// the steps it takes nothing from skipped both ways. Back is off on the first step; Next becomes /// Create on the last. #[test] fn a_sheet_takes_every_step_and_a_figure_skips_what_it_doesnt_draw() { @@ -579,22 +603,26 @@ mod tests { open(&mut app); let mut h = harness(app); assert!(h.get_by_role_and_label(Role::Button, "Back").accesskit_node().is_disabled(), "Back is off"); - for want in [Step::Style, Step::Texts, Step::Sources, Step::Accent, Step::Review] { + for want in [Step::Map, Step::Style, Step::Texts, Step::Sources, Step::Accent, Step::Review] { click(&mut h, "Next"); assert_eq!(step(&h), want); } assert!(h.query_by_role_and_label(Role::Button, "Next").is_none()); assert!(h.query_by_role_and_label(Role::Button, "Create").is_some()); - for want in [Step::Accent, Step::Sources, Step::Texts, Step::Style, Step::Size] { + for want in [Step::Accent, Step::Sources, Step::Texts, Step::Style, Step::Map, Step::Size] { click(&mut h, "Back"); assert_eq!(step(&h), want); } h.state_mut().dialogs.publication.as_mut().unwrap().size = "figure-2col".into(); h.run_steps(2); - click(&mut h, "Next"); - assert_eq!(step(&h), Step::Review); - click(&mut h, "Back"); - assert_eq!(step(&h), Step::Size); + for want in [Step::Map, Step::Review] { + click(&mut h, "Next"); + assert_eq!(step(&h), want); + } + for want in [Step::Map, Step::Size] { + click(&mut h, "Back"); + assert_eq!(step(&h), want); + } } /// Create makes the layout in one step, closes the wizard and opens the Publish tab, as the @@ -657,7 +685,7 @@ mod tests { let mut h = harness(app); let at = |h: &egui_kittest::Harness<'static, RustGisApp>| h.get_by_role_and_label(Role::Button, "Next").rect(); let first = at(&h); - for _ in 0..4 { + for _ in 0..5 { click(&mut h, "Next"); assert_eq!(at(&h), first, "{:?}", step(&h)); } @@ -678,7 +706,7 @@ mod tests { assert_ne!(next, "Next", "{code}: the language changed"); let at = |h: &egui_kittest::Harness<'static, RustGisApp>| h.get_by_role_and_label(Role::Button, &next).rect(); let first = at(&h); - for _ in 0..4 { + for _ in 0..5 { h.get_by_role_and_label(Role::Button, &next).click(); h.run_steps(4); assert_eq!(at(&h), first, "{code}: {:?}", step(&h)); diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index b0ed52b070..2f0c286158 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -1,8 +1,9 @@ //! The wizard's review step. +use super::map::{DEFAULT_NAME, area_label}; use super::*; /// The review step: what was picked, step by step. -pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { +pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { let none = tl!("(none)"); let or_none = |t: &str| if t.trim().is_empty() { none.to_string() } else { t.trim().to_string() }; egui::Grid::new("publication_wizard_review").num_columns(2).spacing(egui::vec2(12.0, 6.0)).show(ui, |ui| { @@ -12,6 +13,8 @@ pub(super) fn review_step(ui: &mut egui::Ui, d: &Draft) { ui.end_row(); }; row(tl!("Size"), size_label(&d.size)); + row(tl!("Map extent"), area_label(s, &d.area)); + row(tl!("Name"), if d.name.trim().is_empty() { DEFAULT_NAME.to_string() } else { d.name.trim().to_string() }); if d.figure() { return; } diff --git a/crates/ui-egui/src/publicationwizard/texts.rs b/crates/ui-egui/src/publicationwizard/texts.rs index ebfdcacd80..006f0c2456 100644 --- a/crates/ui-egui/src/publicationwizard/texts.rs +++ b/crates/ui-egui/src/publicationwizard/texts.rs @@ -69,8 +69,9 @@ mod tests { h.state_mut().run("map.new", json!({"name": "Rivers"})).unwrap(); h.run_steps(2); assert_eq!(h.state().dialogs.publication.as_ref().unwrap().title, "Rivers"); - click(&mut h, "Next"); - click(&mut h, "Next"); + for _ in 0..3 { + click(&mut h, "Next"); + } h.get_by_label("Title").focus(); h.run_steps(1); h.get_by_label("Title").type_text(" basins"); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 9ad89c65f7..e3e3d038cd 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -40,19 +40,22 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu datum under it, at 7 pt. A figure's title and sources belong in its caption, so they are left out, and the result says so. - **Step by step**: **Publication Layout Wizard…**, at the end of the same menu, asks for the size - (a sheet turned Auto, Portrait or Landscape, or a figure), the style (each beside an outline of - where its title, map and footer go, and its column or panel if it has one, with the accent - colour picked, or else its own, where the sheet takes it, which Classic's doesn't; a click on - the outline picks the style), the texts (title, the active map's name until one is typed; - subtitle, note and credit line, or none; an Editorial sheet's column heading), the sources and - reference (each one per line, with its heading; the reference can be left out) and the accent - colour, then shows what was picked; **Create** makes the layout as the menu does. **Insert - Statistic**, on the texts and sources steps, adds a layer figure of the active map to the field - the cursor was last in there (the note or the sources, where it was in none). A figure goes from - its size to the review, as it takes no style, texts or accent. A field left empty is left out - (for the credit line, the reference and the headings, the command's default applies); the title - is the exception: empty, it means no title. A layout the command refuses is said, and the wizard - stays open. + (a sheet turned Auto, Portrait or Landscape, or a figure), the map extent and the layout's name, + the style (each beside an outline of where its title, map and footer go, and its column or panel + if it has one, with the accent colour picked, or else its own, where the sheet takes it, which + Classic's doesn't; a click on the outline picks the style), the texts (title, the active map's + name until one is typed; subtitle, note and credit line, or none; an Editorial sheet's column + heading), the sources and reference (each one per line, with its heading; the reference can be + left out) and the accent colour, then shows what was picked; **Create** makes the layout as the + menu does. **Insert Statistic**, on the texts and sources steps, adds a layer figure of the + active map to the field the cursor was last in there (the note or the sources, where it was in + none). The map extent is the view, the features one layer shows or the selected features (a + point or a straight line is widened to 0.01°; one gone by Create is said); without a name the + layout is `Publication`. A figure goes from its size to its map and the review, as it takes no + style, texts or accent. A field left empty is left out (for the credit line, the reference and + the headings, the command's default applies); the title is the exception: empty, it means no + title. A layout the command refuses is said, and the wizard stays + open. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From 87a444deab3684d9827a49ea1bb0e0afdeb40740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 14:33:03 -0500 Subject: [PATCH 02/11] docs(ui): say the wizard's layer extent takes a hidden layer too --- crates/ui-egui/src/publicationwizard/map.rs | 3 ++- docs/user-guide/layouts.md | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index 138602e169..121da41d26 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -6,7 +6,8 @@ use super::*; pub enum Area { /// The view, left to `layout.publication`. View, - /// The features a layer shows: the layer's id, in the map named. + /// A layer's features, as Zoom To Layer frames them (hidden or not): the layer's id, in the + /// map named. Layer { map: String, id: u32 }, /// The selected features of the map named. Selection { map: String }, diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 85e85ebb1b..cfd30220f1 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -49,14 +49,14 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu left out) and the accent colour, then shows what was picked; **Create** makes the layout as the menu does. **Insert Statistic**, on the texts and sources steps, adds a layer figure of the active map to the field the cursor was last in there (the note or the sources, where it was in - none). The map extent is the view, the features one layer shows or the selected features (a - point or a straight line is widened to 0.01°; one gone by Create is said); without a name the - layout is `Publication`. A figure goes from its size to its map and the review, as it takes no - style, texts or accent. A field left empty is left out (for the credit line, the reference and - the headings, the command's default applies); the title is the exception: empty, it means no - title. A layout the command refuses is said, and the wizard stays open. The window can be - resized. Its steps are listed on the left, and a click goes to one; a narrow screen leaves the - list out, and the heading still says which step this is. + none). The map extent is the view, one layer (as **Zoom To Layer** frames it, hidden or not) or + the selected features (a point or a straight line is widened to 0.01°; one gone by Create is + said); without a name the layout is `Publication`. A figure goes from its size to its map and + the review, as it takes no style, texts or accent. A field left empty is left out (for the + credit line, the reference and the headings, the command's default applies); the title is the + exception: empty, it means no title. A layout the command refuses is said, and the wizard stays + open. The window can be resized. Its steps are listed on the left, and a click goes to one; a + narrow screen leaves the list out, and the heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From d0f4985aac3499ef25020319ecb5b22e70334604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 14:35:15 -0500 Subject: [PATCH 03/11] fix(ui): put the wizard's Map extent label beside the first choice --- crates/ui-egui/src/publicationwizard/map.rs | 73 +++++++++++---------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index 121da41d26..c99c65c92c 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -26,47 +26,50 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { // Create, as it walks the rows under a definition query. let framable = || map.layers.iter().rev().filter(|l| !l.extent().is_empty()); egui::Grid::new("publication_wizard_map").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { + // A row for each choice, so the label sits beside the first one. ui.label(tl!("Map extent")); - ui.vertical(|ui| { - if ui.radio(d.area == Area::View, tl!("View")).on_hover_text(tl!("What the map view shows.")).clicked() { - d.area = Area::View; + if ui.radio(d.area == Area::View, tl!("View")).on_hover_text(tl!("What the map view shows.")).clicked() { + d.area = Area::View; + } + ui.end_row(); + ui.label(""); + ui.horizontal(|ui| { + let picked = match &d.area { + Area::Layer { map: name, id } if *name == map.name => Some(*id), + _ => None, + }; + let top = framable().next().map(|l| l.id); + if ui.add_enabled(top.is_some(), egui::RadioButton::new(matches!(d.area, Area::Layer { .. }), tl!("Layer"))).clicked() + && let Some(id) = picked.or(top) + { + d.area = Area::Layer { map: map.name.clone(), id }; } - ui.horizontal(|ui| { - let picked = match &d.area { - Area::Layer { map: name, id } if *name == map.name => Some(*id), - _ => None, - }; - let top = framable().next().map(|l| l.id); - if ui.add_enabled(top.is_some(), egui::RadioButton::new(matches!(d.area, Area::Layer { .. }), tl!("Layer"))).clicked() - && let Some(id) = picked.or(top) - { - d.area = Area::Layer { map: map.name.clone(), id }; - } - if let Some(id) = picked { - let shown = framable().find(|l| l.id == id).map_or_else(String::new, |l| l.name.clone()); - egui::ComboBox::from_id_salt("publication_wizard_map_layer") - .selected_text(shown) - .width(ui.available_width().min(180.0)) - .show_ui(ui, |ui| { - for l in framable() { - if ui.selectable_label(l.id == id, l.name.as_str()).clicked() { - d.area = Area::Layer { map: map.name.clone(), id: l.id }; - } + if let Some(id) = picked { + let shown = framable().find(|l| l.id == id).map_or_else(String::new, |l| l.name.clone()); + egui::ComboBox::from_id_salt("publication_wizard_map_layer") + .selected_text(shown) + .width(ui.available_width().min(180.0)) + .show_ui(ui, |ui| { + for l in framable() { + if ui.selectable_label(l.id == id, l.name.as_str()).clicked() { + d.area = Area::Layer { map: map.name.clone(), id: l.id }; } - }); - } - }); - let selection = egui::RadioButton::new(matches!(d.area, Area::Selection { .. }), tl!("Selection")); - if ui - .add_enabled(map.selection_count() > 0, selection) - .on_hover_text(tl!("The selected features.")) - .on_disabled_hover_text(tl!("Nothing is selected in the map.")) - .clicked() - { - d.area = Area::Selection { map: map.name.clone() }; + } + }); } }); ui.end_row(); + ui.label(""); + let selection = egui::RadioButton::new(matches!(d.area, Area::Selection { .. }), tl!("Selection")); + if ui + .add_enabled(map.selection_count() > 0, selection) + .on_hover_text(tl!("The selected features.")) + .on_disabled_hover_text(tl!("Nothing is selected in the map.")) + .clicked() + { + d.area = Area::Selection { map: map.name.clone() }; + } + ui.end_row(); let label = ui.label(tl!("Name")); ui.add(egui::TextEdit::singleline(&mut d.name).hint_text(DEFAULT_NAME).desired_width(field_width(ui))).labelled_by(label.id); ui.end_row(); From 98d3b85bb785c0c95833df92282bb26a1762ecfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 14:58:01 -0500 Subject: [PATCH 04/11] fix(ui): show no map extent picked once the map is switched or renamed --- crates/ui-egui/src/publicationwizard/map.rs | 40 +++++++++++++++++---- docs/user-guide/layouts.md | 15 ++++---- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index c99c65c92c..22ce830dc6 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -39,7 +39,7 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { _ => None, }; let top = framable().next().map(|l| l.id); - if ui.add_enabled(top.is_some(), egui::RadioButton::new(matches!(d.area, Area::Layer { .. }), tl!("Layer"))).clicked() + if ui.add_enabled(top.is_some(), egui::RadioButton::new(picked.is_some(), tl!("Layer"))).clicked() && let Some(id) = picked.or(top) { d.area = Area::Layer { map: map.name.clone(), id }; @@ -60,7 +60,9 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { }); ui.end_row(); ui.label(""); - let selection = egui::RadioButton::new(matches!(d.area, Area::Selection { .. }), tl!("Selection")); + // A pick made in another map, or before this one was renamed, marks nothing. + let selected = matches!(&d.area, Area::Selection { map: name } if *name == map.name); + let selection = egui::RadioButton::new(selected, tl!("Selection")); if ui .add_enabled(map.selection_count() > 0, selection) .on_hover_text(tl!("The selected features.")) @@ -86,7 +88,8 @@ pub(super) fn area_label(s: &Session, area: &Area) -> String { .iter() .find(|l| l.id == *id && s.map().name == *map) .map_or_else(|| tl!("(none)").to_string(), |l| i18n::fmt("Layer: {layer}", &[("layer", &l.name)])), - Area::Selection { .. } => tl!("Selected features").to_string(), + Area::Selection { map } if s.map().name == *map => tl!("Selected features").to_string(), + Area::Selection { .. } => tl!("(none)").to_string(), } } @@ -112,7 +115,7 @@ pub(super) fn area_extent(s: &Session, area: &Area) -> Result, let extent = match area { Area::View => return Ok(None), Area::Layer { map: name, .. } | Area::Selection { map: name } if *name != map.name => { - return Err(tl!("Another map is open since the map extent was picked: pick it again.").to_string()); + return Err(tl!("The map was switched or renamed since the map extent was picked: pick it again.").to_string()); } Area::Layer { id, .. } => map .layers @@ -176,8 +179,8 @@ mod tests { assert!(got.is_some_and(|[w, s, e, n]| w < e && s < n), "one point, framed: {got:?}"); } - /// A layer removed, a selection cleared or another map since the area was picked is refused, - /// saying so, rather than framing something else. + /// A layer removed, a selection cleared or another map (or the same one renamed) since the + /// area was picked is refused, saying so, rather than framing something else. #[test] fn an_area_gone_is_refused() { let mut app = app(); @@ -192,7 +195,7 @@ mod tests { Err("The layer picked is no longer in the map: pick the map extent again.".to_string()) ); app.run("map.new", json!({})).unwrap(); - let other = Err("Another map is open since the map extent was picked: pick it again.".to_string()); + let other = Err("The map was switched or renamed since the map extent was picked: pick it again.".to_string()); assert_eq!(area_extent(&app.session, &layer), other); assert_eq!(area_extent(&app.session, &selection), other); } @@ -219,6 +222,29 @@ mod tests { assert!(matches!(area(&h), Area::Selection { .. }), "{:?}", area(&h)); } + /// A pick made in another map, or before the map was renamed, shows as no pick: neither radio + /// marked, the review naming none. + #[test] + fn a_pick_from_a_renamed_map_shows_as_none() { + for layer in [true, false] { + let mut app = app(); + open(&mut app); + let map = app.session.map().name.clone(); + app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); + let id = app.session.map().layers.last().unwrap().id; + let area = if layer { Area::Layer { map, id } } else { Area::Selection { map } }; + app.run("map.rename", json!({"name": "Renamed"})).unwrap(); + assert_eq!(area_label(&app.session, &area), "(none)", "layer: {layer}"); + let d = app.dialogs.publication.as_mut().unwrap(); + (d.area, d.step) = (area, Step::Map); + let h = harness(app); + for name in ["View", "Layer", "Selection"] { + let radio = h.get_by_role_and_label(Role::RadioButton, name); + assert_ne!(radio.accesskit_node().toggled(), Some(egui::accesskit::Toggled::True), "{name}, layer: {layer}"); + } + } + } + /// Create frames the layer picked and names the layout as typed; a figure takes both too. #[test] fn create_frames_the_area_and_names_the_layout() { diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index cfd30220f1..66b987502d 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -50,13 +50,14 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu menu does. **Insert Statistic**, on the texts and sources steps, adds a layer figure of the active map to the field the cursor was last in there (the note or the sources, where it was in none). The map extent is the view, one layer (as **Zoom To Layer** frames it, hidden or not) or - the selected features (a point or a straight line is widened to 0.01°; one gone by Create is - said); without a name the layout is `Publication`. A figure goes from its size to its map and - the review, as it takes no style, texts or accent. A field left empty is left out (for the - credit line, the reference and the headings, the command's default applies); the title is the - exception: empty, it means no title. A layout the command refuses is said, and the wizard stays - open. The window can be resized. Its steps are listed on the left, and a click goes to one; a - narrow screen leaves the list out, and the heading still says which step this is. + the selected features (a point or a straight line is widened to 0.01°; one gone by Create, or + picked before the map was switched or renamed, is said); without a name the layout is + `Publication`. A figure goes from its size to its map and the review, as it takes no style, + texts or accent. A field left empty is left out (for the credit line, the reference and the + headings, the command's default applies); the title is the exception: empty, it means no title. + A layout the command refuses is said, and the wizard stays open. The window can be resized. Its + steps are listed on the left, and a click goes to one; a narrow screen leaves the list out, and + the heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From 56321950cca48cb12be1baa4b61d0e539e9bc31c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 15:08:22 -0500 Subject: [PATCH 05/11] fix(ui): keep the wizard's layer list in its window, top layer first, and its picks to their own project --- crates/ui-egui/src/dialogs.rs | 2 +- crates/ui-egui/src/publicationwizard/map.rs | 93 +++++++++++++++------ docs/user-guide/layouts.md | 14 ++-- 3 files changed, 77 insertions(+), 32 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 8958219b52..b3cc32e982 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -26,7 +26,7 @@ pub(crate) fn map_key(s: &Session) -> MapKey { /// The project (`Session::opened`) and the map in view a dialog or a form was opened on: layer ids /// are a map's own, so what it captured is only good while both are still in view. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct MapOwner { project: u64, map: MapKey, diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index 22ce830dc6..5779ff6b58 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -1,5 +1,6 @@ //! The wizard's map step. use super::*; +use crate::dialogs::MapOwner; /// Which area the map frame shows. #[derive(Clone, Debug, PartialEq, Eq)] @@ -7,10 +8,10 @@ pub enum Area { /// The view, left to `layout.publication`. View, /// A layer's features, as Zoom To Layer frames them (hidden or not): the layer's id, in the - /// map named. - Layer { map: String, id: u32 }, - /// The selected features of the map named. - Selection { map: String }, + /// map it was picked in. + Layer { map: MapOwner, id: u32 }, + /// The selected features of the map it was picked in. + Selection { map: MapOwner }, } /// The name `layout.publication` gives when none is: data, not translated. @@ -24,7 +25,7 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { let map = s.map(); // Top first, as Contents lists them. A layer's kept extent here; the one it shows is read at // Create, as it walks the rows under a definition query. - let framable = || map.layers.iter().rev().filter(|l| !l.extent().is_empty()); + let framable = || map.layers.iter().filter(|l| !l.extent().is_empty()); egui::Grid::new("publication_wizard_map").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { // A row for each choice, so the label sits beside the first one. ui.label(tl!("Map extent")); @@ -35,33 +36,37 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { ui.label(""); ui.horizontal(|ui| { let picked = match &d.area { - Area::Layer { map: name, id } if *name == map.name => Some(*id), + Area::Layer { map: owner, id } if owner.holds(s) => Some(*id), _ => None, }; let top = framable().next().map(|l| l.id); - if ui.add_enabled(top.is_some(), egui::RadioButton::new(picked.is_some(), tl!("Layer"))).clicked() + let layer = ui.add_enabled(top.is_some(), egui::RadioButton::new(picked.is_some(), tl!("Layer"))); + if layer.clicked() && let Some(id) = picked.or(top) { - d.area = Area::Layer { map: map.name.clone(), id }; + d.area = Area::Layer { map: MapOwner::of(s), id }; } if let Some(id) = picked { - let shown = framable().find(|l| l.id == id).map_or_else(String::new, |l| l.name.clone()); + let shown = framable().find(|l| l.id == id).map_or_else(|| tl!("(none)").to_string(), |l| l.name.clone()); egui::ComboBox::from_id_salt("publication_wizard_map_layer") .selected_text(shown) .width(ui.available_width().min(180.0)) + .truncate() .show_ui(ui, |ui| { for l in framable() { if ui.selectable_label(l.id == id, l.name.as_str()).clicked() { - d.area = Area::Layer { map: map.name.clone(), id: l.id }; + d.area = Area::Layer { map: MapOwner::of(s), id: l.id }; } } - }); + }) + .response + .labelled_by(layer.id); } }); ui.end_row(); ui.label(""); - // A pick made in another map, or before this one was renamed, marks nothing. - let selected = matches!(&d.area, Area::Selection { map: name } if *name == map.name); + // A pick made in another map or project, or before this map was renamed, marks nothing. + let selected = matches!(&d.area, Area::Selection { map: owner } if owner.holds(s)); let selection = egui::RadioButton::new(selected, tl!("Selection")); if ui .add_enabled(map.selection_count() > 0, selection) @@ -69,7 +74,7 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { .on_disabled_hover_text(tl!("Nothing is selected in the map.")) .clicked() { - d.area = Area::Selection { map: map.name.clone() }; + d.area = Area::Selection { map: MapOwner::of(s) }; } ui.end_row(); let label = ui.label(tl!("Name")); @@ -86,9 +91,9 @@ pub(super) fn area_label(s: &Session, area: &Area) -> String { .map() .layers .iter() - .find(|l| l.id == *id && s.map().name == *map) + .find(|l| l.id == *id && map.holds(s)) .map_or_else(|| tl!("(none)").to_string(), |l| i18n::fmt("Layer: {layer}", &[("layer", &l.name)])), - Area::Selection { map } if s.map().name == *map => tl!("Selected features").to_string(), + Area::Selection { map } if map.holds(s) => tl!("Selected features").to_string(), Area::Selection { .. } => tl!("(none)").to_string(), } } @@ -109,12 +114,14 @@ fn framed(e: Extent) -> Option<[f64; 4]> { } /// The `extent` to send for `area`, none for the view; an area that is gone since it was picked is -/// an error rather than another one framed. +/// an error rather than another one framed. Read once, at Create, on the UI thread where +/// `layout.publication` runs next: a layer under a definition query is walked whole, as is the +/// selection. pub(super) fn area_extent(s: &Session, area: &Area) -> Result, String> { let map = s.map(); let extent = match area { Area::View => return Ok(None), - Area::Layer { map: name, .. } | Area::Selection { map: name } if *name != map.name => { + Area::Layer { map: owner, .. } | Area::Selection { map: owner } if !owner.holds(s) => { return Err(tl!("The map was switched or renamed since the map extent was picked: pick it again.").to_string()); } Area::Layer { id, .. } => map @@ -163,7 +170,7 @@ mod tests { #[test] fn each_area_sends_its_own_extent() { let mut app = app(); - let map = app.session.map().name.clone(); + let map = MapOwner::of(&app.session); assert_eq!(area_extent(&app.session, &Area::View), Ok(None)); app.run("layer.definitionQuery", json!({"layer": "Cities", "where": "pop_max > 10000000"})).unwrap(); let (id, shown, all) = { @@ -184,7 +191,7 @@ mod tests { #[test] fn an_area_gone_is_refused() { let mut app = app(); - let map = app.session.map().name.clone(); + let map = MapOwner::of(&app.session); let id = app.session.map().layers.iter().find(|l| l.name == "Rivers").unwrap().id; let layer = Area::Layer { map: map.clone(), id }; let selection = Area::Selection { map }; @@ -213,7 +220,8 @@ mod tests { assert!(h.get_by_role_and_label(Role::RadioButton, "Selection").accesskit_node().is_disabled()); h.get_by_role_and_label(Role::RadioButton, "Layer").click(); h.run_steps(4); - let top = h.state().session.map().layers.last().unwrap().id; + let top = h.state().session.map().layers.first().unwrap().id; + assert_eq!(h.state().session.map().layers[0].name, "Cities", "the layer drawn on top"); assert!(matches!(area(&h), Area::Layer { id, .. } if id == top), "{:?}", area(&h)); h.state_mut().run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); h.run_steps(2); @@ -229,7 +237,7 @@ mod tests { for layer in [true, false] { let mut app = app(); open(&mut app); - let map = app.session.map().name.clone(); + let map = MapOwner::of(&app.session); app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); let id = app.session.map().layers.last().unwrap().id; let area = if layer { Area::Layer { map, id } } else { Area::Selection { map } }; @@ -245,13 +253,50 @@ mod tests { } } + /// A pick made in a project since replaced is refused, though the new one's map has the same + /// name: its layer ids and selection are other ones. + #[test] + fn a_pick_from_a_replaced_project_is_refused() { + let mut app = app(); + let map = app.session.map().name.clone(); + let owner = MapOwner::of(&app.session); + let areas = [Area::Layer { map: owner.clone(), id: 1 }, Area::Selection { map: owner }]; + app.run("project.new", json!({})).unwrap(); + app.run("map.rename", json!({"name": map})).unwrap(); + assert_eq!(app.session.map().name, map); + for area in areas { + let said = area_extent(&app.session, &area).unwrap_err(); + assert!(said.starts_with("The map was switched or renamed"), "{area:?}: {said}"); + } + } + + /// A long layer name is cut to the list's width, inside the window at its smallest; a layer + /// picked and then removed reads as (none). + #[test] + fn the_layer_list_stays_in_the_window_and_names_a_layer_gone() { + let mut app = app(); + open(&mut app); + let long = "A layer with a very long name ".repeat(6); + app.run("layer.rename", json!({"layer": "Cities", "name": long})).unwrap(); + let map = MapOwner::of(&app.session); + let id = app.session.map().layers.first().unwrap().id; + let d = app.dialogs.publication.as_mut().unwrap(); + (d.area, d.step) = (Area::Layer { map, id }, Step::Map); + let mut h = harness_sized(app, egui::vec2(420.0, 600.0)); + let list = h.get_by_role(Role::ComboBox).rect(); + assert!(list.right() <= 420.0, "the list runs to {}", list.right()); + h.state_mut().run("layer.remove", json!({"layer": id})).unwrap(); + h.run_steps(4); + assert_eq!(h.get_by_role(Role::ComboBox).accesskit_node().value().as_deref(), Some("(none)")); + } + /// Create frames the layer picked and names the layout as typed; a figure takes both too. #[test] fn create_frames_the_area_and_names_the_layout() { for size in ["a4", "figure-1col"] { let mut app = app(); open(&mut app); - let map = app.session.map().name.clone(); + let map = MapOwner::of(&app.session); app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); let [w, s, e, n] = framed(app.session.map().selection_extent()).unwrap(); { @@ -279,7 +324,7 @@ mod tests { fn create_with_the_area_gone_is_said_and_makes_nothing() { let mut app = app(); open(&mut app); - let map = app.session.map().name.clone(); + let map = MapOwner::of(&app.session); { let d = app.dialogs.publication.as_mut().unwrap(); d.area = Area::Selection { map }; diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 66b987502d..f6dc065770 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -51,13 +51,13 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu active map to the field the cursor was last in there (the note or the sources, where it was in none). The map extent is the view, one layer (as **Zoom To Layer** frames it, hidden or not) or the selected features (a point or a straight line is widened to 0.01°; one gone by Create, or - picked before the map was switched or renamed, is said); without a name the layout is - `Publication`. A figure goes from its size to its map and the review, as it takes no style, - texts or accent. A field left empty is left out (for the credit line, the reference and the - headings, the command's default applies); the title is the exception: empty, it means no title. - A layout the command refuses is said, and the wizard stays open. The window can be resized. Its - steps are listed on the left, and a click goes to one; a narrow screen leaves the list out, and - the heading still says which step this is. + picked before the map or the project was switched or the map renamed, is said); without a name + the layout is `Publication`. A figure goes from its size to its map and the review, as it takes + no style, texts or accent. A field left empty is left out (for the credit line, the reference + and the headings, the command's default applies); the title is the exception: empty, it means no + title. A layout the command refuses is said, and the wizard stays open. The window can be + resized. Its steps are listed on the left, and a click goes to one; a narrow screen leaves the + list out, and the heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From f2497edafa7bba7fc67cadb21d6eee45a419d432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 15:17:44 -0500 Subject: [PATCH 06/11] docs(ui): say what box the wizard's layer extent sends and how its list is ordered --- crates/ui-egui/src/publicationwizard/map.rs | 5 ++--- docs/user-guide/layouts.md | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index 5779ff6b58..cf4cab3018 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -7,8 +7,7 @@ use crate::dialogs::MapOwner; pub enum Area { /// The view, left to `layout.publication`. View, - /// A layer's features, as Zoom To Layer frames them (hidden or not): the layer's id, in the - /// map it was picked in. + /// The features a layer shows (hidden or not): the layer's id, in the map it was picked in. Layer { map: MapOwner, id: u32 }, /// The selected features of the map it was picked in. Selection { map: MapOwner }, @@ -23,7 +22,7 @@ const MIN_SIDE: f64 = 0.01; /// The map step: the area the map frame shows and the layout's name. pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { let map = s.map(); - // Top first, as Contents lists them. A layer's kept extent here; the one it shows is read at + // In the map's layer order, top first. A layer's kept extent here; the one it shows is read at // Create, as it walks the rows under a definition query. let framable = || map.layers.iter().filter(|l| !l.extent().is_empty()); egui::Grid::new("publication_wizard_map").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index f6dc065770..d38d815018 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -49,15 +49,15 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu left out) and the accent colour, then shows what was picked; **Create** makes the layout as the menu does. **Insert Statistic**, on the texts and sources steps, adds a layer figure of the active map to the field the cursor was last in there (the note or the sources, where it was in - none). The map extent is the view, one layer (as **Zoom To Layer** frames it, hidden or not) or - the selected features (a point or a straight line is widened to 0.01°; one gone by Create, or - picked before the map or the project was switched or the map renamed, is said); without a name - the layout is `Publication`. A figure goes from its size to its map and the review, as it takes - no style, texts or accent. A field left empty is left out (for the credit line, the reference - and the headings, the command's default applies); the title is the exception: empty, it means no - title. A layout the command refuses is said, and the wizard stays open. The window can be - resized. Its steps are listed on the left, and a click goes to one; a narrow screen leaves the - list out, and the heading still says which step this is. + none). The map extent is the view, the features one layer shows (hidden or not, in their + longitude/latitude box) or the selected features (a point or a straight line is widened to + 0.01°; one gone by Create, or picked before the map or the project was switched or the map + renamed, is said); without a name the layout is `Publication`. A figure goes from its size to + its map and the review, as it takes no style, texts or accent. A field left empty is left out + (for the credit line, the reference and the headings, the command's default applies); the title + is the exception: empty, it means no title. A layout the command refuses is said, and the wizard + stays open. The window can be resized. Its steps are listed on the left, and a click goes to + one; a narrow screen leaves the list out, and the heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From 6894907138bd61cf0cd5b9e32f1a03a1ea7b152b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 15:25:47 -0500 Subject: [PATCH 07/11] fix(ui): keep the wizard's layer pick on its own layer after Undo reuses the id --- crates/ui-egui/src/publicationwizard/map.rs | 82 +++++++++++++-------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index cf4cab3018..7ac4e6608d 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -1,14 +1,17 @@ //! The wizard's map step. use super::*; use crate::dialogs::MapOwner; +use rustgis_engine::map::Layer; /// Which area the map frame shows. #[derive(Clone, Debug, PartialEq, Eq)] pub enum Area { /// The view, left to `layout.publication`. View, - /// The features a layer shows (hidden or not): the layer's id, in the map it was picked in. - Layer { map: MapOwner, id: u32 }, + /// The features a layer shows (hidden or not), in the map it was picked in. The layer by its + /// [`Layer::instance_id`](rustgis_engine::map::Layer::instance_id): Undo hands its map-local + /// id to the next layer added. + Layer { map: MapOwner, layer: u64 }, /// The selected features of the map it was picked in. Selection { map: MapOwner }, } @@ -16,7 +19,8 @@ pub enum Area { /// The name `layout.publication` gives when none is: data, not translated. pub(super) const DEFAULT_NAME: &str = "Publication"; -/// A side sent for an extent with none along it (a point, a straight line), in degrees. +/// What a side with no length (a point, a straight line) is widened to, in degrees; on the ±180 or +/// ±90 edge half of it is cut off again. const MIN_SIDE: f64 = 0.01; /// The map step: the area the map frame shows and the layout's name. @@ -35,31 +39,31 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { ui.label(""); ui.horizontal(|ui| { let picked = match &d.area { - Area::Layer { map: owner, id } if owner.holds(s) => Some(*id), + Area::Layer { map: owner, layer } if owner.holds(s) => Some(*layer), _ => None, }; - let top = framable().next().map(|l| l.id); - let layer = ui.add_enabled(top.is_some(), egui::RadioButton::new(picked.is_some(), tl!("Layer"))); - if layer.clicked() - && let Some(id) = picked.or(top) + let top = framable().next().map(Layer::instance_id); + let radio = ui.add_enabled(top.is_some(), egui::RadioButton::new(picked.is_some(), tl!("Layer"))); + if radio.clicked() + && let Some(layer) = picked.or(top) { - d.area = Area::Layer { map: MapOwner::of(s), id }; + d.area = Area::Layer { map: MapOwner::of(s), layer }; } - if let Some(id) = picked { - let shown = framable().find(|l| l.id == id).map_or_else(|| tl!("(none)").to_string(), |l| l.name.clone()); + if let Some(picked) = picked { + let shown = framable().find(|l| l.instance_id() == picked).map_or_else(|| tl!("(none)").to_string(), |l| l.name.clone()); egui::ComboBox::from_id_salt("publication_wizard_map_layer") .selected_text(shown) .width(ui.available_width().min(180.0)) .truncate() .show_ui(ui, |ui| { for l in framable() { - if ui.selectable_label(l.id == id, l.name.as_str()).clicked() { - d.area = Area::Layer { map: MapOwner::of(s), id: l.id }; + if ui.selectable_label(l.instance_id() == picked, l.name.as_str()).clicked() { + d.area = Area::Layer { map: MapOwner::of(s), layer: l.instance_id() }; } } }) .response - .labelled_by(layer.id); + .labelled_by(radio.id); } }); ui.end_row(); @@ -86,11 +90,11 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { pub(super) fn area_label(s: &Session, area: &Area) -> String { match area { Area::View => tl!("The view").to_string(), - Area::Layer { map, id } => s + Area::Layer { map, layer } => s .map() .layers .iter() - .find(|l| l.id == *id && map.holds(s)) + .find(|l| l.instance_id() == *layer && map.holds(s)) .map_or_else(|| tl!("(none)").to_string(), |l| i18n::fmt("Layer: {layer}", &[("layer", &l.name)])), Area::Selection { map } if map.holds(s) => tl!("Selected features").to_string(), Area::Selection { .. } => tl!("(none)").to_string(), @@ -123,10 +127,10 @@ pub(super) fn area_extent(s: &Session, area: &Area) -> Result, Area::Layer { map: owner, .. } | Area::Selection { map: owner } if !owner.holds(s) => { return Err(tl!("The map was switched or renamed since the map extent was picked: pick it again.").to_string()); } - Area::Layer { id, .. } => map + Area::Layer { layer, .. } => map .layers .iter() - .find(|l| l.id == *id) + .find(|l| l.instance_id() == *layer) .ok_or_else(|| tl!("The layer picked is no longer in the map: pick the map extent again.").to_string())? .shown_extent(), Area::Selection { .. } => { @@ -174,10 +178,10 @@ mod tests { app.run("layer.definitionQuery", json!({"layer": "Cities", "where": "pop_max > 10000000"})).unwrap(); let (id, shown, all) = { let l = app.session.map().layers.iter().find(|l| l.name == "Cities").unwrap(); - (l.id, l.shown_extent(), l.extent()) + (l.instance_id(), l.shown_extent(), l.extent()) }; assert_ne!(shown, all, "the query narrows it"); - assert_eq!(area_extent(&app.session, &Area::Layer { map: map.clone(), id }), Ok(framed(shown))); + assert_eq!(area_extent(&app.session, &Area::Layer { map: map.clone(), layer: id }), Ok(framed(shown))); app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); let selected = app.session.map().selection_extent(); let got = area_extent(&app.session, &Area::Selection { map }).unwrap(); @@ -191,8 +195,8 @@ mod tests { fn an_area_gone_is_refused() { let mut app = app(); let map = MapOwner::of(&app.session); - let id = app.session.map().layers.iter().find(|l| l.name == "Rivers").unwrap().id; - let layer = Area::Layer { map: map.clone(), id }; + let id = app.session.map().layers.iter().find(|l| l.name == "Rivers").unwrap().instance_id(); + let layer = Area::Layer { map: map.clone(), layer: id }; let selection = Area::Selection { map }; assert_eq!(area_extent(&app.session, &selection), Err("Nothing is selected: pick the map extent again.".to_string())); app.run("layer.remove", json!({"layer": "Rivers"})).unwrap(); @@ -219,9 +223,9 @@ mod tests { assert!(h.get_by_role_and_label(Role::RadioButton, "Selection").accesskit_node().is_disabled()); h.get_by_role_and_label(Role::RadioButton, "Layer").click(); h.run_steps(4); - let top = h.state().session.map().layers.first().unwrap().id; + let top = h.state().session.map().layers.first().unwrap().instance_id(); assert_eq!(h.state().session.map().layers[0].name, "Cities", "the layer drawn on top"); - assert!(matches!(area(&h), Area::Layer { id, .. } if id == top), "{:?}", area(&h)); + assert!(matches!(area(&h), Area::Layer { layer, .. } if layer == top), "{:?}", area(&h)); h.state_mut().run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); h.run_steps(2); h.get_by_role_and_label(Role::RadioButton, "Selection").click(); @@ -238,8 +242,8 @@ mod tests { open(&mut app); let map = MapOwner::of(&app.session); app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); - let id = app.session.map().layers.last().unwrap().id; - let area = if layer { Area::Layer { map, id } } else { Area::Selection { map } }; + let id = app.session.map().layers.last().unwrap().instance_id(); + let area = if layer { Area::Layer { map, layer: id } } else { Area::Selection { map } }; app.run("map.rename", json!({"name": "Renamed"})).unwrap(); assert_eq!(area_label(&app.session, &area), "(none)", "layer: {layer}"); let d = app.dialogs.publication.as_mut().unwrap(); @@ -259,7 +263,7 @@ mod tests { let mut app = app(); let map = app.session.map().name.clone(); let owner = MapOwner::of(&app.session); - let areas = [Area::Layer { map: owner.clone(), id: 1 }, Area::Selection { map: owner }]; + let areas = [Area::Layer { map: owner.clone(), layer: 1 }, Area::Selection { map: owner }]; app.run("project.new", json!({})).unwrap(); app.run("map.rename", json!({"name": map})).unwrap(); assert_eq!(app.session.map().name, map); @@ -278,9 +282,9 @@ mod tests { let long = "A layer with a very long name ".repeat(6); app.run("layer.rename", json!({"layer": "Cities", "name": long})).unwrap(); let map = MapOwner::of(&app.session); - let id = app.session.map().layers.first().unwrap().id; + let (id, instance) = app.session.map().layers.first().map(|l| (l.id, l.instance_id())).unwrap(); let d = app.dialogs.publication.as_mut().unwrap(); - (d.area, d.step) = (Area::Layer { map, id }, Step::Map); + (d.area, d.step) = (Area::Layer { map, layer: instance }, Step::Map); let mut h = harness_sized(app, egui::vec2(420.0, 600.0)); let list = h.get_by_role(Role::ComboBox).rect(); assert!(list.right() <= 420.0, "the list runs to {}", list.right()); @@ -289,6 +293,26 @@ mod tests { assert_eq!(h.get_by_role(Role::ComboBox).accesskit_node().value().as_deref(), Some("(none)")); } + /// Undo gives a layer's id to the next one added: a pick of the layer undone is refused, not + /// moved to the new one. + #[test] + fn a_pick_isnt_passed_to_a_layer_that_reuses_its_id() { + let mut app = app(); + app.run("layer.copy", json!({"layer": "Rivers"})).unwrap(); + app.run("layer.paste", json!({})).unwrap(); + let (id, layer) = (app.session.map().layers[0].id, app.session.map().layers[0].instance_id()); + let area = Area::Layer { map: MapOwner::of(&app.session), layer }; + app.run("edit.undo", Value::Null).unwrap(); + app.run("layer.copy", json!({"layer": "Lakes"})).unwrap(); + app.run("layer.paste", json!({})).unwrap(); + assert_eq!(app.session.map().layers[0].id, id, "the id is reused"); + assert_eq!(area_label(&app.session, &area), "(none)"); + assert_eq!( + area_extent(&app.session, &area), + Err("The layer picked is no longer in the map: pick the map extent again.".to_string()) + ); + } + /// Create frames the layer picked and names the layout as typed; a figure takes both too. #[test] fn create_frames_the_area_and_names_the_layout() { From f12eed13fd35a9e5ef328944f3f16611001f630c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 15:41:37 -0500 Subject: [PATCH 08/11] fix(ui): say on the wizard's review a cleared selection and a name that will be numbered --- crates/ui-egui/src/publicationwizard/map.rs | 38 ++++++++++++++++++- .../ui-egui/src/publicationwizard/review.rs | 4 +- docs/user-guide/layouts.md | 13 ++++--- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index 7ac4e6608d..0b0f136648 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -17,7 +17,7 @@ pub enum Area { } /// The name `layout.publication` gives when none is: data, not translated. -pub(super) const DEFAULT_NAME: &str = "Publication"; +const DEFAULT_NAME: &str = "Publication"; /// What a side with no length (a point, a straight line) is widened to, in degrees; on the ±180 or /// ±90 edge half of it is cut off again. @@ -86,6 +86,17 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { }); } +/// How the review names the layout: as typed, or as the command names one given no name, saying +/// when it numbers it because a layout has that name. +pub(super) fn name_label(s: &Session, name: &str) -> String { + let name = Some(name.trim()).filter(|n| !n.is_empty()).unwrap_or(DEFAULT_NAME); + if s.project.layouts.iter().any(|l| l.name.eq_ignore_ascii_case(name)) { + i18n::fmt("{name} (numbered: a layout has that name)", &[("name", name)]) + } else { + name.to_string() + } +} + /// How the review names the area. pub(super) fn area_label(s: &Session, area: &Area) -> String { match area { @@ -96,7 +107,7 @@ pub(super) fn area_label(s: &Session, area: &Area) -> String { .iter() .find(|l| l.instance_id() == *layer && map.holds(s)) .map_or_else(|| tl!("(none)").to_string(), |l| i18n::fmt("Layer: {layer}", &[("layer", &l.name)])), - Area::Selection { map } if map.holds(s) => tl!("Selected features").to_string(), + Area::Selection { map } if map.holds(s) && s.map().selection_count() > 0 => tl!("Selected features").to_string(), Area::Selection { .. } => tl!("(none)").to_string(), } } @@ -313,6 +324,29 @@ mod tests { ); } + /// The review names what Create will make: a selection cleared since reads as none, and a name + /// another layout has (the default's too, case aside) is said to be numbered. + #[test] + fn the_review_says_a_cleared_selection_and_a_taken_name() { + let mut app = app(); + open(&mut app); + app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); + let d = app.dialogs.publication.as_mut().unwrap(); + (d.area, d.step) = (Area::Selection { map: MapOwner::of(&app.session) }, Step::Review); + let mut h = harness(app); + assert!(h.query_by_label("Selected features").is_some()); + assert!(h.query_by_label("Publication").is_some()); + h.state_mut().run("select.clear", Value::Null).unwrap(); + h.state_mut().run("layout.new", json!({"name": "publication"})).unwrap(); + h.state_mut().dialogs.open = Some("publicationWizard"); + h.run_steps(4); + assert!(h.query_by_label("Selected features").is_none()); + assert!(h.query_by_label("Publication (numbered: a layout has that name)").is_some()); + h.state_mut().dialogs.publication.as_mut().unwrap().name = " Publication ".into(); + h.run_steps(4); + assert!(h.query_by_label("Publication (numbered: a layout has that name)").is_some()); + } + /// Create frames the layer picked and names the layout as typed; a figure takes both too. #[test] fn create_frames_the_area_and_names_the_layout() { diff --git a/crates/ui-egui/src/publicationwizard/review.rs b/crates/ui-egui/src/publicationwizard/review.rs index ea3027d0c6..b9cc236678 100644 --- a/crates/ui-egui/src/publicationwizard/review.rs +++ b/crates/ui-egui/src/publicationwizard/review.rs @@ -1,5 +1,5 @@ //! The wizard's review step. -use super::map::{DEFAULT_NAME, area_label}; +use super::map::{area_label, name_label}; use super::*; /// The review step: what was picked, step by step. @@ -15,7 +15,7 @@ pub(super) fn review_step(ui: &mut egui::Ui, s: &Session, d: &Draft) { }; row(tl!("Size"), size_label(&d.size)); row(tl!("Map extent"), area_label(s, &d.area)); - row(tl!("Name"), if d.name.trim().is_empty() { DEFAULT_NAME.to_string() } else { d.name.trim().to_string() }); + row(tl!("Name"), name_label(s, &d.name)); if d.figure() { return; } diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index d38d815018..0d1316896b 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -52,12 +52,13 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu none). The map extent is the view, the features one layer shows (hidden or not, in their longitude/latitude box) or the selected features (a point or a straight line is widened to 0.01°; one gone by Create, or picked before the map or the project was switched or the map - renamed, is said); without a name the layout is `Publication`. A figure goes from its size to - its map and the review, as it takes no style, texts or accent. A field left empty is left out - (for the credit line, the reference and the headings, the command's default applies); the title - is the exception: empty, it means no title. A layout the command refuses is said, and the wizard - stays open. The window can be resized. Its steps are listed on the left, and a click goes to - one; a narrow screen leaves the list out, and the heading still says which step this is. + renamed, is said); without a name the layout is `Publication`; the review says when a layout has + that name, so the new one is numbered. A figure goes from its size to its map and the review, as + it takes no style, texts or accent. A field left empty is left out (for the credit line, the + reference and the headings, the command's default applies); the title is the exception: empty, + it means no title. A layout the command refuses is said, and the wizard stays open. The window + can be resized. Its steps are listed on the left, and a click goes to one; a narrow screen + leaves the list out, and the heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city), From 081c8b1be433d29afe002189e9edfc6b0875351d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 15:54:42 -0500 Subject: [PATCH 09/11] perf(ui): don't walk a layer's places each frame to list it in the wizard's Map step --- crates/ui-egui/src/publicationwizard/map.rs | 31 +++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index 0b0f136648..1d820648f6 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -26,9 +26,10 @@ const MIN_SIDE: f64 = 0.01; /// The map step: the area the map frame shows and the layout's name. pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { let map = s.map(); - // In the map's layer order, top first. A layer's kept extent here; the one it shows is read at - // Create, as it walks the rows under a definition query. - let framable = || map.layers.iter().filter(|l| !l.extent().is_empty()); + // In the map's layer order, top first, by what costs nothing a frame: whether it has rows, a + // raster or a source. Its places are read at Create ([`Layer::extent`] walks every + // longitude/latitude row each time), where one with none to frame is refused. + let framable = || map.layers.iter().filter(|l| !l.dataset.features.is_empty() || l.raster.is_some() || l.source.is_some()); egui::Grid::new("publication_wizard_map").num_columns(2).spacing(egui::vec2(8.0, 8.0)).show(ui, |ui| { // A row for each choice, so the label sits beside the first one. ui.label(tl!("Map extent")); @@ -129,8 +130,7 @@ fn framed(e: Extent) -> Option<[f64; 4]> { /// The `extent` to send for `area`, none for the view; an area that is gone since it was picked is /// an error rather than another one framed. Read once, at Create, on the UI thread where -/// `layout.publication` runs next: a layer under a definition query is walked whole, as is the -/// selection. +/// `layout.publication` runs next: it may walk the whole layer, or the whole selection. pub(super) fn area_extent(s: &Session, area: &Area) -> Result, String> { let map = s.map(); let extent = match area { @@ -160,6 +160,7 @@ mod tests { use super::*; use egui::accesskit::Role; use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::data::{Dataset, GeometryType}; fn close(got: Option<[f64; 4]>, want: [f64; 4]) { let got = got.expect("an extent"); @@ -347,6 +348,26 @@ mod tests { assert!(h.query_by_label("Publication (numbered: a layout has that name)").is_some()); } + /// A layer is offered for having rows, its places left unread until Create: one with none to + /// frame is refused there; a layer with no rows isn't offered. + #[test] + fn a_layer_is_offered_by_its_rows_and_its_places_read_at_create() { + let mut app = app(); + open(&mut app); + let mut unplaced = Dataset::new("No places", GeometryType::Point, vec![]); + unplaced.push(None, vec![]); + app.session.map_mut().add_dataset(unplaced); + app.session.map_mut().add_dataset(Dataset::new("No rows", GeometryType::Point, vec![])); + app.dialogs.publication.as_mut().unwrap().step = Step::Map; + let mut h = harness(app); + h.get_by_role_and_label(Role::RadioButton, "Layer").click(); + h.run_steps(4); + let state = h.state(); + let area = state.dialogs.publication.as_ref().unwrap().area.clone(); + assert_eq!(area_label(&state.session, &area), "Layer: No places"); + assert_eq!(area_extent(&state.session, &area), Err("There is nothing to frame there: pick another map extent.".to_string())); + } + /// Create frames the layer picked and names the layout as typed; a figure takes both too. #[test] fn create_frames_the_area_and_names_the_layout() { From a3a4789261e42b9cfb8b305b56fe018b4b351c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 16:00:49 -0500 Subject: [PATCH 10/11] refactor(ui): one check for whether the wizard's map extent pick still holds --- crates/ui-egui/src/publicationwizard/map.rs | 238 +++++++++----------- 1 file changed, 110 insertions(+), 128 deletions(-) diff --git a/crates/ui-egui/src/publicationwizard/map.rs b/crates/ui-egui/src/publicationwizard/map.rs index 1d820648f6..7b9c3fc77d 100644 --- a/crates/ui-egui/src/publicationwizard/map.rs +++ b/crates/ui-egui/src/publicationwizard/map.rs @@ -23,6 +23,33 @@ const DEFAULT_NAME: &str = "Publication"; /// ±90 edge half of it is cut off again. const MIN_SIDE: f64 = 0.01; +/// What a pick names in the session now. +enum Held<'a> { + View, + Layer(&'a Layer), + Selection, +} + +/// What `area` names now, or why it no longer holds: the one check the step, the review and Create +/// share, so a stale pick reads the same in the three. It reads no places, as it runs every frame. +fn held<'a>(s: &'a Session, area: &Area) -> Result, &'static str> { + let map = s.map(); + match area { + Area::View => Ok(Held::View), + Area::Layer { map: owner, .. } | Area::Selection { map: owner } if !owner.holds(s) => { + Err(tl!("The map was switched or renamed since the map extent was picked: pick it again.")) + } + Area::Layer { layer, .. } => map + .layers + .iter() + .find(|l| l.instance_id() == *layer) + .map(Held::Layer) + .ok_or_else(|| tl!("The layer picked is no longer in the map: pick the map extent again.")), + Area::Selection { .. } if map.selection_count() == 0 => Err(tl!("Nothing is selected: pick the map extent again.")), + Area::Selection { .. } => Ok(Held::Selection), + } +} + /// The map step: the area the map frame shows and the layout's name. pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { let map = s.map(); @@ -38,27 +65,28 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { } ui.end_row(); ui.label(""); + // A pick that no longer holds marks nothing. + let held = held(s, &d.area); ui.horizontal(|ui| { - let picked = match &d.area { - Area::Layer { map: owner, layer } if owner.holds(s) => Some(*layer), + let picked = match held { + Ok(Held::Layer(l)) => Some(l), _ => None, }; let top = framable().next().map(Layer::instance_id); let radio = ui.add_enabled(top.is_some(), egui::RadioButton::new(picked.is_some(), tl!("Layer"))); if radio.clicked() - && let Some(layer) = picked.or(top) + && let Some(layer) = picked.map(Layer::instance_id).or(top) { d.area = Area::Layer { map: MapOwner::of(s), layer }; } if let Some(picked) = picked { - let shown = framable().find(|l| l.instance_id() == picked).map_or_else(|| tl!("(none)").to_string(), |l| l.name.clone()); egui::ComboBox::from_id_salt("publication_wizard_map_layer") - .selected_text(shown) + .selected_text(picked.name.as_str()) .width(ui.available_width().min(180.0)) .truncate() .show_ui(ui, |ui| { for l in framable() { - if ui.selectable_label(l.instance_id() == picked, l.name.as_str()).clicked() { + if ui.selectable_label(l.instance_id() == picked.instance_id(), l.name.as_str()).clicked() { d.area = Area::Layer { map: MapOwner::of(s), layer: l.instance_id() }; } } @@ -69,9 +97,7 @@ pub(super) fn map_step(ui: &mut egui::Ui, s: &Session, d: &mut Draft) { }); ui.end_row(); ui.label(""); - // A pick made in another map or project, or before this map was renamed, marks nothing. - let selected = matches!(&d.area, Area::Selection { map: owner } if owner.holds(s)); - let selection = egui::RadioButton::new(selected, tl!("Selection")); + let selection = egui::RadioButton::new(matches!(held, Ok(Held::Selection)), tl!("Selection")); if ui .add_enabled(map.selection_count() > 0, selection) .on_hover_text(tl!("The selected features.")) @@ -100,16 +126,11 @@ pub(super) fn name_label(s: &Session, name: &str) -> String { /// How the review names the area. pub(super) fn area_label(s: &Session, area: &Area) -> String { - match area { - Area::View => tl!("The view").to_string(), - Area::Layer { map, layer } => s - .map() - .layers - .iter() - .find(|l| l.instance_id() == *layer && map.holds(s)) - .map_or_else(|| tl!("(none)").to_string(), |l| i18n::fmt("Layer: {layer}", &[("layer", &l.name)])), - Area::Selection { map } if map.holds(s) && s.map().selection_count() > 0 => tl!("Selected features").to_string(), - Area::Selection { .. } => tl!("(none)").to_string(), + match held(s, area) { + Ok(Held::View) => tl!("The view").to_string(), + Ok(Held::Layer(l)) => i18n::fmt("Layer: {layer}", &[("layer", &l.name)]), + Ok(Held::Selection) => tl!("Selected features").to_string(), + Err(_) => tl!("(none)").to_string(), } } @@ -128,28 +149,14 @@ fn framed(e: Extent) -> Option<[f64; 4]> { Some([west, south, east, north]) } -/// The `extent` to send for `area`, none for the view; an area that is gone since it was picked is -/// an error rather than another one framed. Read once, at Create, on the UI thread where +/// The `extent` to send for `area`, none for the view; a pick that no longer holds is an error +/// rather than another area framed. Read once, at Create, on the UI thread where /// `layout.publication` runs next: it may walk the whole layer, or the whole selection. pub(super) fn area_extent(s: &Session, area: &Area) -> Result, String> { - let map = s.map(); - let extent = match area { - Area::View => return Ok(None), - Area::Layer { map: owner, .. } | Area::Selection { map: owner } if !owner.holds(s) => { - return Err(tl!("The map was switched or renamed since the map extent was picked: pick it again.").to_string()); - } - Area::Layer { layer, .. } => map - .layers - .iter() - .find(|l| l.instance_id() == *layer) - .ok_or_else(|| tl!("The layer picked is no longer in the map: pick the map extent again.").to_string())? - .shown_extent(), - Area::Selection { .. } => { - if map.selection_count() == 0 { - return Err(tl!("Nothing is selected: pick the map extent again.").to_string()); - } - map.selection_extent() - } + let extent = match held(s, area)? { + Held::View => return Ok(None), + Held::Layer(l) => l.shown_extent(), + Held::Selection => s.map().selection_extent(), }; framed(extent).map(Some).ok_or_else(|| tl!("There is nothing to frame there: pick another map extent.").to_string()) } @@ -201,27 +208,6 @@ mod tests { assert!(got.is_some_and(|[w, s, e, n]| w < e && s < n), "one point, framed: {got:?}"); } - /// A layer removed, a selection cleared or another map (or the same one renamed) since the - /// area was picked is refused, saying so, rather than framing something else. - #[test] - fn an_area_gone_is_refused() { - let mut app = app(); - let map = MapOwner::of(&app.session); - let id = app.session.map().layers.iter().find(|l| l.name == "Rivers").unwrap().instance_id(); - let layer = Area::Layer { map: map.clone(), layer: id }; - let selection = Area::Selection { map }; - assert_eq!(area_extent(&app.session, &selection), Err("Nothing is selected: pick the map extent again.".to_string())); - app.run("layer.remove", json!({"layer": "Rivers"})).unwrap(); - assert_eq!( - area_extent(&app.session, &layer), - Err("The layer picked is no longer in the map: pick the map extent again.".to_string()) - ); - app.run("map.new", json!({})).unwrap(); - let other = Err("The map was switched or renamed since the map extent was picked: pick it again.".to_string()); - assert_eq!(area_extent(&app.session, &layer), other); - assert_eq!(area_extent(&app.session, &selection), other); - } - /// The step starts on the view; Layer picks one from the list; Selection is off with nothing /// selected. #[test] @@ -245,84 +231,20 @@ mod tests { assert!(matches!(area(&h), Area::Selection { .. }), "{:?}", area(&h)); } - /// A pick made in another map, or before the map was renamed, shows as no pick: neither radio - /// marked, the review naming none. + /// A long layer name is cut to the list's width, inside the window at its smallest. #[test] - fn a_pick_from_a_renamed_map_shows_as_none() { - for layer in [true, false] { - let mut app = app(); - open(&mut app); - let map = MapOwner::of(&app.session); - app.run("select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})).unwrap(); - let id = app.session.map().layers.last().unwrap().instance_id(); - let area = if layer { Area::Layer { map, layer: id } } else { Area::Selection { map } }; - app.run("map.rename", json!({"name": "Renamed"})).unwrap(); - assert_eq!(area_label(&app.session, &area), "(none)", "layer: {layer}"); - let d = app.dialogs.publication.as_mut().unwrap(); - (d.area, d.step) = (area, Step::Map); - let h = harness(app); - for name in ["View", "Layer", "Selection"] { - let radio = h.get_by_role_and_label(Role::RadioButton, name); - assert_ne!(radio.accesskit_node().toggled(), Some(egui::accesskit::Toggled::True), "{name}, layer: {layer}"); - } - } - } - - /// A pick made in a project since replaced is refused, though the new one's map has the same - /// name: its layer ids and selection are other ones. - #[test] - fn a_pick_from_a_replaced_project_is_refused() { - let mut app = app(); - let map = app.session.map().name.clone(); - let owner = MapOwner::of(&app.session); - let areas = [Area::Layer { map: owner.clone(), layer: 1 }, Area::Selection { map: owner }]; - app.run("project.new", json!({})).unwrap(); - app.run("map.rename", json!({"name": map})).unwrap(); - assert_eq!(app.session.map().name, map); - for area in areas { - let said = area_extent(&app.session, &area).unwrap_err(); - assert!(said.starts_with("The map was switched or renamed"), "{area:?}: {said}"); - } - } - - /// A long layer name is cut to the list's width, inside the window at its smallest; a layer - /// picked and then removed reads as (none). - #[test] - fn the_layer_list_stays_in_the_window_and_names_a_layer_gone() { + fn the_layer_list_stays_in_the_window() { let mut app = app(); open(&mut app); let long = "A layer with a very long name ".repeat(6); app.run("layer.rename", json!({"layer": "Cities", "name": long})).unwrap(); let map = MapOwner::of(&app.session); - let (id, instance) = app.session.map().layers.first().map(|l| (l.id, l.instance_id())).unwrap(); + let instance = app.session.map().layers[0].instance_id(); let d = app.dialogs.publication.as_mut().unwrap(); (d.area, d.step) = (Area::Layer { map, layer: instance }, Step::Map); - let mut h = harness_sized(app, egui::vec2(420.0, 600.0)); + let h = harness_sized(app, egui::vec2(420.0, 600.0)); let list = h.get_by_role(Role::ComboBox).rect(); assert!(list.right() <= 420.0, "the list runs to {}", list.right()); - h.state_mut().run("layer.remove", json!({"layer": id})).unwrap(); - h.run_steps(4); - assert_eq!(h.get_by_role(Role::ComboBox).accesskit_node().value().as_deref(), Some("(none)")); - } - - /// Undo gives a layer's id to the next one added: a pick of the layer undone is refused, not - /// moved to the new one. - #[test] - fn a_pick_isnt_passed_to_a_layer_that_reuses_its_id() { - let mut app = app(); - app.run("layer.copy", json!({"layer": "Rivers"})).unwrap(); - app.run("layer.paste", json!({})).unwrap(); - let (id, layer) = (app.session.map().layers[0].id, app.session.map().layers[0].instance_id()); - let area = Area::Layer { map: MapOwner::of(&app.session), layer }; - app.run("edit.undo", Value::Null).unwrap(); - app.run("layer.copy", json!({"layer": "Lakes"})).unwrap(); - app.run("layer.paste", json!({})).unwrap(); - assert_eq!(app.session.map().layers[0].id, id, "the id is reused"); - assert_eq!(area_label(&app.session, &area), "(none)"); - assert_eq!( - area_extent(&app.session, &area), - Err("The layer picked is no longer in the map: pick the map extent again.".to_string()) - ); } /// The review names what Create will make: a selection cleared since reads as none, and a name @@ -368,6 +290,66 @@ mod tests { assert_eq!(area_extent(&state.session, &area), Err("There is nothing to frame there: pick another map extent.".to_string())); } + /// A pick that no longer holds reads the same everywhere: no choice marked on the step, + /// "(none)" in the review, and Create says why instead of framing something else. + #[test] + fn a_pick_that_no_longer_holds_reads_the_same_everywhere() { + const SWITCHED: &str = "The map was switched or renamed since the map extent was picked: pick it again."; + const GONE: &str = "The layer picked is no longer in the map: pick the map extent again."; + const CLEARED: &str = "Nothing is selected: pick the map extent again."; + type Change = fn(&mut RustGisApp); + fn run(app: &mut RustGisApp, id: &str, p: Value) { + app.run(id, p).unwrap(); + } + let cases: [(&str, bool, Change, &str); 9] = [ + ("another map, layer", true, |a| run(a, "map.new", json!({})), SWITCHED), + ("another map, selection", false, |a| run(a, "map.new", json!({})), SWITCHED), + ("map renamed, layer", true, |a| run(a, "map.rename", json!({"name": "Renamed"})), SWITCHED), + ("map renamed, selection", false, |a| run(a, "map.rename", json!({"name": "Renamed"})), SWITCHED), + ("project replaced, layer", true, |a| replace_project(a), SWITCHED), + ("project replaced, selection", false, |a| replace_project(a), SWITCHED), + ("layer removed", true, |a| run(a, "layer.remove", json!({"layer": "Rivers copy"})), GONE), + ( + "paste undone, its id reused", + true, + |a| { + run(a, "edit.undo", Value::Null); + run(a, "layer.copy", json!({"layer": "Lakes"})); + run(a, "layer.paste", json!({})); + }, + GONE, + ), + ("selection cleared", false, |a| run(a, "select.clear", Value::Null), CLEARED), + ]; + for (case, layer, change, why) in cases { + let mut app = app(); + run(&mut app, "select.byAttributes", json!({"layer": "Cities", "where": "name = 'Tokyo'"})); + run(&mut app, "layer.copy", json!({"layer": "Rivers"})); + run(&mut app, "layer.paste", json!({})); + let map = MapOwner::of(&app.session); + let area = if layer { Area::Layer { map, layer: app.session.map().layers[0].instance_id() } } else { Area::Selection { map } }; + change(&mut app); + assert_eq!(area_label(&app.session, &area), "(none)", "{case}"); + assert_eq!(area_extent(&app.session, &area), Err(why.to_string()), "{case}"); + open(&mut app); + let d = app.dialogs.publication.as_mut().unwrap(); + (d.area, d.step) = (area, Step::Map); + let h = harness(app); + for name in ["View", "Layer", "Selection"] { + let radio = h.get_by_role_and_label(Role::RadioButton, name); + assert_ne!(radio.accesskit_node().toggled(), Some(egui::accesskit::Toggled::True), "{case}: {name}"); + } + assert!(h.query_by_role(Role::ComboBox).is_none(), "{case}: no layer list"); + } + } + + /// A project opened over this one, its map named as the old one was. + fn replace_project(app: &mut RustGisApp) { + let name = app.session.map().name.clone(); + app.run("project.new", json!({})).unwrap(); + app.run("map.rename", json!({"name": name})).unwrap(); + } + /// Create frames the layer picked and names the layout as typed; a figure takes both too. #[test] fn create_frames_the_area_and_names_the_layout() { From 129130ce621863a5c83ac225ce7d0be57ec9a2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Fri, 27 Nov 2026 16:06:39 -0500 Subject: [PATCH 11/11] docs: say the wizard's map extent is cut to the world and what is refused --- docs/user-guide/layouts.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 0d1316896b..d3aa07e0eb 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -51,14 +51,15 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu active map to the field the cursor was last in there (the note or the sources, where it was in none). The map extent is the view, the features one layer shows (hidden or not, in their longitude/latitude box) or the selected features (a point or a straight line is widened to - 0.01°; one gone by Create, or picked before the map or the project was switched or the map - renamed, is said); without a name the layout is `Publication`; the review says when a layout has - that name, so the new one is numbered. A figure goes from its size to its map and the review, as - it takes no style, texts or accent. A field left empty is left out (for the credit line, the - reference and the headings, the command's default applies); the title is the exception: empty, - it means no title. A layout the command refuses is said, and the wizard stays open. The window - can be resized. Its steps are listed on the left, and a click goes to one; a narrow screen - leaves the list out, and the heading still says which step this is. + 0.01°, and what lies past ±180° or ±90° is left out of the frame; an area with nothing to frame, + one gone by Create, or one picked before the map or the project was switched or the map renamed, + is said and nothing is made); without a name the layout is `Publication`; the review says when a + layout has that name, so the new one is numbered. A figure goes from its size to its map and the + review, as it takes no style, texts or accent. A field left empty is left out (for the credit + line, the reference and the headings, the command's default applies); the title is the + exception: empty, it means no title. A layout the command refuses is said, and the wizard stays + open. The window can be resized. Its steps are listed on the left, and a click goes to one; a + narrow screen leaves the list out, and the heading still says which step this is. - **The map**: the `extent` given (or the view) fitted north-up, without tilt, at a round scale, two significant figures, rounded up so it still fits within the strips the graticule's labels take inside the frame. A graticule's step follows the extent (2° for a state, 15′ for a city),