diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 40e499f3f5..05d79d5e6a 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -5565,7 +5565,7 @@ fn qgis_import_codes_only_the_notes_that_lose_data() { // A memory layer opens empty, so its Z values and curves held no data: plain. assert_eq!(json_loss("Heights", "Z and M"), Some(None)); assert_eq!(json_loss("Arcs", "curves read as lines"), Some(None)); - assert_eq!(json_loss("", "print layouts' legends"), Some(None), "a layout is drawing, not data: no code"); + assert_eq!(json_loss("", "legends whose map isn't on their page"), Some(None), "a layout is drawing, not data: no code"); let said = s.notices_since(mark); let with = |code| said.iter().filter(|n| n.loss() == Some(code)).collect::>(); assert!(with(LossCode::DroppedFeature)[0].text.contains("Unsupported"), "{said:?}"); diff --git a/crates/engine/src/tests/qgis_layouts.rs b/crates/engine/src/tests/qgis_layouts.rs index b7ef54bdd3..814c69e294 100644 --- a/crates/engine/src/tests/qgis_layouts.rs +++ b/crates/engine/src/tests/qgis_layouts.rs @@ -254,3 +254,35 @@ fn a_layouts_surrounds_show_the_imported_frames() { crate::cmd::reads::read_land(&mut s, done).unwrap(); check(&s); } + +/// The corpus's legends come in naming the imported map's layers, showing its frame, and the +/// layout exports. +#[test] +fn a_layouts_legends_name_the_imported_layers() { + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../map/testdata/qgis/generated/qgs/layout-legends.qgs"); + let mut s = Session::new(Project::default()); + s.run("project.importQgis", &json!({"path": path.display().to_string()})).unwrap(); + let l = s.project.layouts.iter().find(|l| l.name == "Legends").unwrap(); + let map = s.project.maps.iter().find(|m| m.name == "Legends").unwrap(); + let names: Vec = map.layers.iter().map(|l| l.name.clone()).collect(); + let frame = l.first_frame().unwrap(); + let mut legends = 0; + for e in &l.elements { + if let ElementKind::Legend { frame: f, layer_order, exclude, labels, .. } = &e.kind { + legends += 1; + assert_eq!(*f, frame); + for n in layer_order.iter().chain(exclude).chain(labels.keys()) { + assert!(names.iter().any(|m| m.eq_ignore_ascii_case(n)), "{n} not in {names:?}"); + } + } + } + assert_eq!(legends, 3); + let dir = std::env::temp_dir().join(format!("rustgis-qgis-legends-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let png = dir.join("legends.png"); + let exported = s.run("layout.export", &json!({"layout": "Legends", "path": png.display().to_string(), "dpi": 36})); + let written = std::fs::metadata(&png).map(|m| m.len()).unwrap_or(0); + let _ = std::fs::remove_dir_all(&dir); + exported.unwrap(); + assert!(written > 0); +} diff --git a/crates/map/src/qgis/layout.rs b/crates/map/src/qgis/layout.rs index baac281a11..36a5e56216 100644 --- a/crates/map/src/qgis/layout.rs +++ b/crates/map/src/qgis/layout.rs @@ -4,11 +4,12 @@ //! rectangles and ellipses those shapes, and its lines and polygons straight lines along their //! edges. Items are drawn in QGIS's order (its `zValue`), placed where QGIS draws them on their //! page in millimetres, a turned label turned about its centre as QGIS turns it. Its scale bars, -//! north arrows and map overviews show their map's frame ([`surround`], piece 12b). +//! north arrows, map overviews ([`surround`]) and legends ([`legend`]) show their map's frame +//! (piece 12b). //! -//! What a RustGIS layout has no place for is noted, counted over all the layouts: legends, -//! tables, HTML and the other item kinds, map grids, the atlas, groups, blending, and settings set -//! by expressions. A QGIS 2 composer isn't read. +//! What a RustGIS layout has no place for is noted, counted over all the layouts: tables, HTML +//! and the other item kinds, map grids, the atlas, groups, blending, and settings set by +//! expressions. A QGIS 2 composer isn't read. use roxmltree::Node; @@ -73,7 +74,6 @@ pub struct LayoutPicture { /// What the layouts held that their RustGIS layouts don't carry over, counted over them all. #[derive(Default)] pub(super) struct Tally { - legends: usize, north_arrows: usize, tables: usize, html: usize, @@ -164,12 +164,45 @@ pub(super) struct Tally { /// Overviews of a map another overview of the same item already outlines, kept once. overviews_twice: usize, bar_text_styles: usize, + /// Legends as RustGIS's: text sizes past a layout's, text styles of their own, groups listed + /// flat, classes' own labels, hidden layers listed, lists past RustGIS's, columns past its, + /// symbol sizes past its, spacing or layout of their own, and those given a size. + legend_text_sizes: usize, + legend_styles: usize, + legend_groups: usize, + legend_class_labels: usize, + legend_hidden: usize, + legend_cut: usize, + legend_columns: usize, + legend_patches: usize, + legend_layout: usize, + legend_sized: usize, + /// Legends of layers some with a category for all other values and some without, the row shown for all. + legend_other: usize, + /// Legends in several columns keeping each layer whole, their columns evened. + legend_split: usize, + /// Legends whose own list gives a layer its own rows, text, symbol size or split. + legend_rows: usize, + /// Legends listing one of two layers of a name. + legend_names: usize, + /// Legends of a map not on their page, showing their page's first. + legend_far: usize, + /// Legends' titles and layer labels past a label's characters, cut. + legend_long: usize, + /// Legends' own names for a layer sharing its name with another labelled one, the first kept. + legend_labels_dropped: usize, + /// The layer names all legends keep so far, and the legends left out past + /// [`legend::MAX_LEGEND_NAMES`]. + legend_names_kept: usize, + legends_past: usize, + /// The import's layers, as a legend lists them. + layers: legend::ProjectLayers, /// Pages whose fill is more than a colour (several layers, a pattern, another kind). papers: usize, /// Scale bars drawn with a symbol of several layers, patterned, dashed or of another kind. bar_symbols: usize, linked: Vec, - /// Scale bars and north arrows whose map isn't on their page, left out; overviews of a map + /// Scale bars, north arrows and legends whose map isn't on their page, left out; overviews of a map /// not on theirs, not drawn. unlinked: usize, overviews_unlinked: usize, @@ -198,6 +231,7 @@ pub(super) struct Tally { bar_text_sizes: usize, } +mod legend; mod surround; /// `text` written into a label as it reads: its braces as parentheses, as a brace starts one of @@ -209,7 +243,12 @@ fn as_written(text: &str) -> String { /// Reads the project's print layouts (``), each page a [`ProjectLayout`], `dir` the /// project's folder (pictures named relative to it), `title` the project's title. What can't be /// carried over is noted. -pub fn read_layouts(root: Node, dir: &str, title: &str, report: &mut Report) -> Vec { +pub fn read_layouts( + root: Node, + dir: &str, + (title, layers, annotations): (&str, &[super::ProjectLayer], Option<&super::ProjectLayer>), + report: &mut Report, +) -> Vec { let composers = root.children().filter(|c| c.has_tag_name("Composer")).count(); if composers > 0 { report.skipped("", format!("its print composers of QGIS 2 ({composers})")); @@ -220,6 +259,7 @@ pub fn read_layouts(root: Node, dir: &str, title: &str, report: &mut Report) -> let cut = title.chars().nth(MAX_TEXT).is_some(); let title = Title { text: as_written(&title.chars().take(MAX_TEXT).collect::()), cut, braced: title.contains(['{', '}']) }; tally.title_len = title.text.len(); + tally.layers = legend::project_layers(layers, annotations); let mut out = Vec::new(); let mut names = Vec::new(); let all: Vec = list.children().filter(|c| c.has_tag_name("Layout")).collect(); @@ -556,10 +596,6 @@ fn read_item( let kind = item.attribute("type").unwrap_or_default(); match kind { PAGE => return, - LEGEND => { - tally.legends += 1; - return; - } GROUP => { tally.groups += 1; return; @@ -577,7 +613,7 @@ fn read_item( } return; } - MAP | PICTURE | LABEL | SHAPE | POLYGON | POLYLINE | SCALE_BAR => {} + MAP | PICTURE | LABEL | SHAPE | POLYGON | POLYLINE | SCALE_BAR | LEGEND => {} other => { tally.other += 1; if !other.is_empty() && tally.other_kinds.len() < 8 && !tally.other_kinds.iter().any(|k| k == other) { @@ -596,6 +632,9 @@ fn read_item( if kind == SCALE_BAR && !surround::bar_on_page(item, &place, tally) { return; } + if kind == LEGEND && !legend::legend_on_page(&place, tally) { + return; + } if kind != PICTURE && target.layout.elements.len() >= MAX_ELEMENTS { tally.over += elements_needed(item, kind); return; @@ -618,6 +657,7 @@ fn read_item( PICTURE => picture_item(item, &place, id, dir, fade, target, tally), SHAPE => shape_item(item, &place, id, fade, target, tally), SCALE_BAR => surround::scale_bar_item(item, &place, id, fade, target, tally), + LEGEND => legend::legend_item(item, &place, id, fade, target, tally), _ => line_item(item, kind, &place, id, fade, target, tally), } // Counted for what came in: a picture's said by the engine once its image reads. @@ -627,7 +667,11 @@ fn read_item( let oversized = place.w > MAX_SIDE || place.h > MAX_SIDE; // Narrower than an element can be across or down: widened to it (a line's edges are counted // as they are drawn). - let tiny = !matches!(kind, POLYLINE | POLYGON) && (place.w < crate::layout::MIN_ELEMENT_MM || place.h < crate::layout::MIN_ELEMENT_MM); + // A legend sized to its content (QGIS saves no size until it draws it) is given one, said as that. + let sized = kind == LEGEND && item.attribute("resizeToContents") != Some("0"); + let tiny = !matches!(kind, POLYLINE | POLYGON) + && !sized + && (place.w < crate::layout::MIN_ELEMENT_MM || place.h < crate::layout::MIN_ELEMENT_MM); // A picture's notes wait for its image (a north arrow, also a QGIS picture, is not one). let picture = target.layout.elements.get(first).is_some_and(|e| matches!(e.kind, ElementKind::Picture { .. })); let mut counted = surround::Counts::default(); @@ -660,7 +704,7 @@ fn read_item( if added && l.page == place.page && element == Some(l.element) - && matches!(l.link, surround::Link::Surround | surround::Link::Numeric) => + && matches!(l.link, surround::Link::Surround | surround::Link::Numeric | surround::Link::FirstFrame) => { l.counts.merge(counted); } @@ -1306,8 +1350,18 @@ fn edges( impl Tally { pub(super) fn say(&self, report: &mut Report) { let skipped = [ - (self.legends, "legends"), - (self.unlinked, "scale bars and north arrows whose map isn't on their page, or is left out"), + (self.unlinked, "scale bars, north arrows and legends whose map isn't on their page, or is left out"), + (self.legends_past, &format!("legends past the {} layer names an import's legends keep", legend::MAX_LEGEND_NAMES)), + (self.legend_groups, "legends' groups, their layers listed on their own"), + (self.legend_class_labels, "legends' own labels for their layers' classes, showing the layers'"), + (self.legend_hidden, "legends listing layers the map hides, which a RustGIS legend leaves out"), + ( + self.legend_cut, + &format!( + "legends' lists of layers past the {} a legend keeps, or past the entries an import reads, cut there", + crate::layout::MAX_LEGEND_EXCLUDED + ), + ), (self.overviews_unlinked, "map overviews of their own map, or of a map not on their page or left out"), (self.overviews_off, "map overviews and grids switched off"), (self.overviews_twice, "map overviews of a map their map item already outlines (kept once)"), @@ -1369,6 +1423,34 @@ impl Tally { "scale bars drawn with symbols of several layers, patterned, dashed, outlined or of another kind, in a plain colour", ), (self.papers, "pages whose fill has several layers, a pattern, an outline or is of another kind, drawn as a plain colour"), + (self.legend_text_sizes, "legends' text sizes outside 4 to 100 pt, drawn at the nearest"), + ( + self.legend_styles, + "legends' title, group and layer texts in sizes, faces or fonts of their own, in RustGIS's proportion to their rows", + ), + (self.legend_columns, &format!("legends' columns brought within RustGIS's (1 to {})", crate::layout::MAX_LEGEND_COLUMNS)), + (self.legend_patches, "legends' symbol sizes brought within RustGIS's"), + ( + self.legend_layout, + "legends' spacing, alignment, wrapping, symbol size limits, even columns or atlas filter, as RustGIS draws a legend", + ), + ( + self.legend_other, + "legends of layers drawn by categories, some with one for all other values and some without, showing that row for all", + ), + (self.legend_split, "legends in several columns keeping each layer whole, their columns evened, a layer split between them"), + ( + self.legend_rows, + "legends giving a layer rows of its own (classes left out or reordered), a text by an expression, a symbol size or a split, as RustGIS lists a layer", + ), + (self.legend_names, "legends listing one of two layers of a name, which RustGIS's legend lists both of"), + ( + self.legend_long, + &format!("legends' titles and layer labels longer than {} characters, cut there", crate::layout::MAX_LEGEND_LABEL_CHARS), + ), + (self.legend_labels_dropped, "legends' own names for a layer sharing its name with another they name, the first kept"), + (self.legend_far, "legends of a map not on their page (or not read), showing their page's first map"), + (self.legend_sized, "legends sized to their content that QGIS hasn't sized yet, given room for a row a layer"), (self.bar_text_styles, "scale bars' text bold, italic, underlined, buffered or shadowed, drawn plain"), (self.numeric_formats, "numeric scale bars, printing the scale in RustGIS's format (1:25,000)"), (self.numeric_sizes, "numeric scale bars' text sizes outside 1 to 400 pt, drawn at the nearest"), @@ -1500,3 +1582,9 @@ fn unit_mm(unit: &str, dpi: f64) -> Option { pub(super) fn surround_hairline() -> f64 { surround::HAIRLINE_PT } + +/// The layer names all of an import's legends keep, for tests. +#[cfg(test)] +pub(super) fn legend_names_limit() -> usize { + legend::MAX_LEGEND_NAMES +} diff --git a/crates/map/src/qgis/layout/legend.rs b/crates/map/src/qgis/layout/legend.rs new file mode 100644 index 0000000000..5350a7abf8 --- /dev/null +++ b/crates/map/src/qgis/layout/legend.rs @@ -0,0 +1,363 @@ +//! A QGIS layout's legends (piece 12b of #882), each linked like the other surrounds to the +//! frame its map item became on its page ([`super::surround::link`]): the layers it lists (all +//! the project's, or those its own list names, in that order and under their own names), every +//! class or only what its map draws, and its text's size and colour. What a RustGIS legend draws +//! otherwise is said. + +use super::surround::{Counts, Link, Linked}; +use super::*; +use crate::layout::{ + LAYOUT_TEXT_SIZE, LEGEND_PATCH_HEIGHT_RANGE, LEGEND_PATCH_WIDTH_RANGE, LEGEND_TEXT_PT, LayerNames, LegendFit, MAX_LEGEND_COLUMNS, + MAX_LEGEND_EXCLUDED, MAX_LEGEND_LABEL_CHARS, +}; + +/// A layer of the import, as a legend lists it. +pub(super) struct LegendLayer { + name: String, + /// The map shows it (its box and every group's above it checked). + shown: bool, + /// Drawn by Unique Values (its categories or rules), whether it draws all other values (a QGIS + /// category of an empty value, an ELSE rule): a RustGIS legend's `` row. + other: Option, + /// Of several rows (any renderer but a single symbol), which a column could split. + several: bool, +} + +/// The import's layers as legends list them: in the project's order, by QGIS id, and by name as +/// RustGIS's legend matches one (any ASCII case); and the main annotation layer's name, which a +/// QGIS legend never lists. +#[derive(Default)] +pub(super) struct ProjectLayers { + layers: Vec, + by_id: std::collections::HashMap, + by_name: std::collections::HashMap>, + /// Each name's first layer, by its name in ASCII lowercase, in the project's order. + distinct: Vec<(String, usize)>, + annotations: Option, + /// Over all its layers, once (what a legend of the project's layers lists): one hidden, one + /// with all other values and one without, one of several rows. + hidden: bool, + with_other: bool, + without_other: bool, + several: bool, +} + +/// The most layer names (left out, in order, labelled) all of an import's legends keep: past it +/// a legend is left out, said, so a file of many legends can't hold a name list each. +pub(super) const MAX_LEGEND_NAMES: usize = 100_000; + +/// The most entries of a legend's own list walked: as many as the layer tree reader takes. +const MAX_ENTRIES: usize = super::super::MAX_LAYERS * 4; + +/// The import's layers (`layers`, as read, in the project's order, and its main annotation +/// layer) as legends list them: what each is drawn by is what the import made of it. +pub(super) fn project_layers(layers: &[super::super::ProjectLayer], annotations: Option<&super::super::ProjectLayer>) -> ProjectLayers { + let mut out = ProjectLayers { annotations: annotations.map(|a| a.name.clone()), ..ProjectLayers::default() }; + for l in layers { + let (other, several) = match &l.style.renderer { + // As the renderer reader found it, whatever the rest's symbol (one transparent or + // switched off still has its row in QGIS's legend). + Some(crate::symbology::Renderer::Unique { .. }) => (Some(l.style.other_values), true), + Some(crate::symbology::Renderer::Single(_)) | None => (None, false), + Some(_) => (None, true), + }; + let i = out.layers.len(); + out.by_id.entry(l.id.clone()).or_insert(i); + let named = out.by_name.entry(l.name.to_ascii_lowercase()).or_default(); + if named.is_empty() { + out.distinct.push((l.name.to_ascii_lowercase(), i)); + } + named.push(i); + // What a legend shows of it: only a layer the map shows (RustGIS's legend lists no other). + let on = l.visible; + (out.hidden, out.several) = (out.hidden || !on, out.several || (on && several)); + (out.with_other, out.without_other) = + (out.with_other || (on && other == Some(true)), out.without_other || (on && other == Some(false))); + out.layers.push(LegendLayer { name: l.name.clone(), shown: l.visible, other, several }); + } + out +} + +/// Whether a map comes in on a legend's page (its own, or another it shows instead): one on a +/// page without is left out, said, and nothing else of it counted. +pub(super) fn legend_on_page(place: &Placed, tally: &mut Tally) -> bool { + let on = tally.known.iter().any(|(_, page)| *page == place.page); + tally.unlinked += usize::from(!on); + on +} + +/// A legend, linked to its map's frame (or with none named, the first on its page). +pub(super) fn legend_item( + item: Node, + place: &Placed, + id: Option, + fade: impl Fn(Rgba) -> Rgba, + target: &mut ProjectLayout, + tally: &mut Tally, +) { + let mut counts = Counts::default(); + let map = item.attribute("map_uuid").map(str::trim).unwrap_or_default().to_string(); + // Its map's frame; naming none, the first on its page (QGIS lists every layer's classes then, + // filtering by none); naming one not on its page, the first on its page instead, said. + let far = !map.is_empty() && !super::surround::on_page(tally, &map, place.page); + counts.legend_far += usize::from(far); + let link = if map.is_empty() || far { Link::FirstFrame } else { Link::Surround }; + // Its rows' text (`symbolLabel`), as RustGIS draws all of a legend's text in proportion to it. + let styles = child(item, "styles"); + let style = |name: &str| styles.and_then(|s| s.children().find(|c| c.has_tag_name("style") && c.attribute("name") == Some(name))); + let text = style("symbolLabel").and_then(|s| child(s, "text-style")); + let (size, color) = match text { + Some(t) => { + let unit = t.attribute("fontSizeUnit").unwrap_or("Point"); + let size = labels::points(num(t, "fontSize").unwrap_or(12.0), unit, "legend text sizes", "", &mut counts.notes); + let opacity = num(t, "textOpacity").unwrap_or(1.0).clamp(0.0, 1.0); + let c = t.attribute("textColor").and_then(color).unwrap_or(Rgba::rgb(0, 0, 0)); + (size, c.with_alpha((f64::from(c.a()) * opacity).round() as u8)) + } + None => (12.0, Rgba::rgb(0, 0, 0)), + }; + let text_size = size.clamp(*LAYOUT_TEXT_SIZE.start(), *LAYOUT_TEXT_SIZE.end()); + counts.legend_text_sizes += usize::from(text_size != size); + // Its title's, groups' and layers' text in QGIS's sizes (16, 14 and 12 pt) and plain, in an + // installed family or a sans: RustGIS's, in proportion to its rows'. Others said. + let default_sizes = [("title", 16.0), ("group", 14.0), ("subgroup", 12.0), ("symbolLabel", 12.0)]; + let styled = default_sizes.iter().any(|(name, pt)| { + style(name).and_then(|s| child(s, "text-style")).is_some_and(|t| { + let (bold, italic) = labels::bold_italic(t); + num(t, "fontSize").is_some_and(|v| (v - pt).abs() > 1e-9) + || (bold && *name != "title") + || italic + || t.attribute("fontFamily").map(str::trim).is_some_and(|f| !f.is_empty() && !annotation::generic(f)) + || child(t, "text-buffer").is_some_and(|n| n.attribute("bufferDraw") == Some("1")) + }) + }); + counts.legend_styles += usize::from(styled); + // The layers it lists, as indices into the import's: its own list, or the project's. + let tree = child(item, "layer-tree-group"); + let own = tree.is_some() && item.attribute("syncMode").is_none_or(|m| m == "Manual"); + let project = &tally.layers; + let mut listed: Vec = Vec::new(); + let mut on_list = std::collections::HashSet::new(); + let mut labels_of = std::collections::BTreeMap::new(); + // What each name (as RustGIS's legend matches one, any ASCII case) shows: its first listed + // layer's own name for it, or its name. RustGIS shows one text a name. + let mut shows: std::collections::HashMap = std::collections::HashMap::new(); + if own && let Some(tree) = tree { + let (mut groups, mut classes, mut own_rows) = (0usize, 0usize, 0usize); + // Its entries in order, its groups' flattened (said); no more than the tree reader takes, + // the rest said. + let entry = |c: &Node| c.has_tag_name("layer-tree-layer") || c.has_tag_name("layer-tree-group"); + let mut stack = vec![tree.children().filter(entry).collect::>().into_iter()]; + let mut seen = 0usize; + while let Some(level) = stack.last_mut() { + let Some(c) = level.next() else { + stack.pop(); + continue; + }; + seen += 1; + if seen > MAX_ENTRIES { + counts.legend_cut += 1; + break; + } + if c.has_tag_name("layer-tree-group") { + groups += 1; + stack.push(c.children().filter(entry).collect::>().into_iter()); + continue; + } + let Some(&i) = c.attribute("id").and_then(|id| project.by_id.get(id)) else { continue }; + if !on_list.insert(i) { + continue; + } + listed.push(i); + let Some(layer) = project.layers.get(i) else { continue }; + let option = |key: &str| c.descendants().find(|d| d.has_tag_name("Option") && d.attribute("name") == Some(key)); + // Its own name for it: a title label, else its entry's name where not the layer's. + let label = + option("legend/title-label").and_then(|o| o.attribute("value")).or(c.attribute("name")).map(str::trim).unwrap_or_default(); + let text = if label.is_empty() { layer.name.as_str() } else { label }; + match shows.get(&layer.name.to_ascii_lowercase()) { + // A second of its name showing other text: the first's shown, said. + Some(first) => counts.legend_labels_dropped += usize::from(first != text), + None => { + shows.insert(layer.name.to_ascii_lowercase(), text.to_string()); + if text != layer.name { + counts.legend_long += usize::from(text.chars().nth(MAX_LEGEND_LABEL_CHARS).is_some()); + labels_of.insert(layer.name.clone(), text.chars().take(MAX_LEGEND_LABEL_CHARS).collect::()); + } + } + } + // Its classes' own labels (`legend/label-N`): RustGIS's, said. + classes += usize::from( + c.descendants().any(|d| d.has_tag_name("Option") && d.attribute("name").is_some_and(|n| n.starts_with("legend/label-"))), + ); + // Its own rows (classes left out or reordered), a text made by an expression, a symbol + // size or a split of its own: as RustGIS lists a layer, said. + own_rows += usize::from( + option("legend/node-order").is_some() + || c.attribute("legend_exp").is_some_and(|e| !e.trim().is_empty()) + || c.attribute("patch_size").is_some_and(|p| p.trim() != "-1,-1") + || c.attribute("legend_split_behavior").is_some_and(|b| b.trim() != "0"), + ); + } + counts.legend_groups += usize::from(groups > 0); + counts.legend_class_labels += usize::from(classes > 0); + counts.legend_rows += usize::from(own_rows > 0); + } + let layer = |i: &usize| project.layers.get(*i); + // What it lists, from its own list, or for the project's layers from what the import read of + // them once: one hidden, with all other values or without, of several rows. + let (any_hidden, with_other, without_other, several) = if own { + // Of those the map shows, as RustGIS's legend lists them. + let kinds: Vec = listed.iter().filter_map(|i| layer(i).filter(|l| l.shown).and_then(|l| l.other)).collect(); + ( + listed.iter().any(|i| layer(i).is_some_and(|l| !l.shown)), + kinds.contains(&true), + kinds.contains(&false), + listed.iter().any(|i| layer(i).is_some_and(|l| l.shown && l.several)), + ) + } else { + (project.hidden, project.with_other, project.without_other, project.several) + }; + // QGIS lists a layer the map hides, unless filtered by its map or listing the map's visible + // layers; RustGIS's legend lists what the map shows, said. + let filtered = item.attribute("legendFilterByMap") == Some("1") && !map.is_empty() && !far; + let unfiltered_list = item.attribute("legendFilterByMap") != Some("1") && item.attribute("syncMode") != Some("VisibleLayers"); + counts.legend_hidden += usize::from(unfiltered_list && any_hidden); + // QGIS draws a row for all other values only where a layer has one; RustGIS's legend shows + // that row for all its Unique Values layers or none: none unless one has it, and where some + // have it and others don't, all, said. + let hide_other = !with_other; + counts.legend_other += usize::from(with_other && without_other); + // RustGIS names a legend's layers, in any ASCII case: two of one name are one to it. One + // listed beside another of its name left out lists both, said. Its listed layers by name, + // counted once (its own list's; the project's lists every name). + let mut listed_names: std::collections::HashMap = std::collections::HashMap::new(); + for l in listed.iter().filter_map(&layer) { + *listed_names.entry(l.name.to_ascii_lowercase()).or_default() += 1; + } + let all_of = |key: &str| project.by_name.get(key).map_or(0, Vec::len); + counts.legend_names += usize::from(own && listed_names.iter().any(|(key, n)| *n < all_of(key))); + // The names it keeps (left out, in order, labelled), counted before any list is made: within + // what all legends keep, else left out, said, and nothing else of it counted (so a file of + // many legends costs little past it). + let annotations = project + .annotations + .as_ref() + .filter(|a| !project.by_name.contains_key(&a.to_ascii_lowercase())) + .filter(|a| !listed_names.contains_key(&a.to_ascii_lowercase())); + let left_out = if own { project.by_name.len().saturating_sub(listed_names.len()) } else { 0 } + usize::from(annotations.is_some()); + let names = left_out.min(MAX_LEGEND_EXCLUDED) + listed_names.len().min(MAX_LEGEND_EXCLUDED) + labels_of.len(); + if tally.legend_names_kept.saturating_add(names) > MAX_LEGEND_NAMES { + tally.legends_past += 1; + return; + } + tally.legend_names_kept += names; + let project = &tally.layers; + // Those it leaves out, by name, as a RustGIS legend leaves them out (a name a listed layer + // has is listed); the main annotation layer, which a QGIS legend never lists, always. + let mut exclude: Vec = Vec::new(); + if own { + // Each name none of whose layers it lists, by its first layer's spelling: as many steps + // as the names it keeps. + for (key, first) in &project.distinct { + if !listed_names.contains_key(key) + && let Some(l) = project.layers.get(*first) + { + exclude.push(l.name.clone()); + } + } + } + if let Some(a) = annotations { + exclude.push(a.clone()); + } + counts.legend_cut += usize::from(exclude.len() > MAX_LEGEND_EXCLUDED || listed.len() > MAX_LEGEND_EXCLUDED); + let exclude: Vec = exclude.into_iter().take(MAX_LEGEND_EXCLUDED).collect(); + // Its order by name, each once (RustGIS's legend orders a name once, any ASCII case; two + // layers of one name are one to it, said above). + let mut ordered = std::collections::HashSet::new(); + let layer_order: Vec = if own { + listed + .iter() + .filter_map(|i| project.layers.get(*i)) + .filter(|l| ordered.insert(l.name.to_ascii_lowercase())) + .take(MAX_LEGEND_EXCLUDED) + .map(|l| l.name.clone()) + .collect() + } else { + Vec::new() + }; + let rows = if own { listed.len() } else { project.layers.len() }; + // Its columns, within RustGIS's. + let wanted = num(item, "columnCount").map_or(1.0, f64::trunc); + let columns = wanted.clamp(1.0, MAX_LEGEND_COLUMNS as f64) as usize; + counts.legend_columns += usize::from(columns as f64 != wanted); + // In several columns QGIS keeps each layer's rows together (unless `splitLayer`); RustGIS + // evens its columns, splitting a layer: said. + counts.legend_split += usize::from(columns > 1 && several && item.attribute("splitLayer") != Some("1")); + // Its symbols' size (mm, 7 × 4 by default), as a patch in points at RustGIS's default text + // size: RustGIS grows it with its text. + let patch = |k: &str, default: f64, range: &std::ops::RangeInclusive| { + let mm = num(item, k).unwrap_or(default); + let pt = mm * crate::layout::PT_PER_MM * LEGEND_TEXT_PT / text_size; + (pt.clamp(*range.start(), *range.end()), !range.contains(&pt)) + }; + let (patch_width, wide) = patch("symbolWidth", 7.0, &LEGEND_PATCH_WIDTH_RANGE); + let (patch_height, tall) = patch("symbolHeight", 4.0, &LEGEND_PATCH_HEIGHT_RANGE); + counts.legend_patches += usize::from(wide || tall); + // Its spacing, alignment, wrapping, symbol size limits or columns of one width: as RustGIS + // draws a legend. + let other = |k: &str, default: f64| num(item, k).is_some_and(|v| (v - default).abs() > 1e-9); + counts.legend_layout += usize::from( + other("boxSpace", 2.0) + || other("columnSpace", 2.0) + || other("titleAlignment", 1.0) + || other("maxSymbolSize", 0.0) + || other("minSymbolSize", 0.0) + || other("equalColumnWidth", 0.0) + || item.attribute("wrapChar").is_some_and(|w| !w.is_empty()), + ); + // Its layers filtered by the atlas's feature (12c), as RustGIS's by its map's. + counts.legend_layout += usize::from(other("legendFilterByAtlas", 0.0)); + let title = item.attribute("title").unwrap_or_default(); + counts.legend_long += usize::from(title.chars().nth(MAX_LEGEND_LABEL_CHARS).is_some()); + let kind = ElementKind::Legend { + frame: 0, + title: title.chars().take(MAX_LEGEND_LABEL_CHARS).collect(), + // Filtered by its map, what the map draws; else (or with no map of its own) every class, + // as QGIS lists them. + all_classes: !filtered, + hide_other, + show_no_data: false, + exclude, + layer_order, + column_breaks: Vec::new(), + one_row: false, + columns, + labels: labels_of, + color: Some(fade(color)), + text_size, + fit: LegendFit::Manual, + show_layer_names: LayerNames::Shown, + class_labels: Default::default(), + show_counts: Default::default(), + subtitle: String::new(), + sizes: Default::default(), + patch_width, + patch_height, + }; + // Sized to its content (QGIS sizes it as it draws it): one not drawn yet has no size, and is + // given room for its title and a row a layer, said. + let fits = item.attribute("resizeToContents") != Some("0"); + let (w, h) = if fits && (place.w < 1.0 || place.h < 1.0) { + counts.legend_sized += 1; + let line = text_size * 0.3528 * 1.6; + (50.0f64.max(place.w), (2.0 * line + rows.max(1) as f64 * line).min(MAX_SIDE)) + } else { + (place.w, place.h) + }; + let element = target.layout.add(name_or(id, "Legend"), (place.x, place.y, w, h), kind); + if let Some(e) = target.layout.element_mut(element) { + e.background = backdrop(item, true, place.dpi, &fade); + } + tally.linked.push(Linked { page: place.page, element, map, link, counts }); +} diff --git a/crates/map/src/qgis/layout/surround.rs b/crates/map/src/qgis/layout/surround.rs index 733f4a2940..3fe8f564df 100644 --- a/crates/map/src/qgis/layout/surround.rs +++ b/crates/map/src/qgis/layout/surround.rs @@ -14,8 +14,10 @@ pub(super) const HAIRLINE_PT: f64 = 1.0; /// What an element links to its map item as. pub(super) enum Link { - /// A scale bar or a north arrow: its `frame`. + /// A scale bar, a north arrow or a legend: its `frame`. Surround, + /// A legend naming no map: the first frame on its page, as QGIS lists the project's layers then. + FirstFrame, /// A numeric scale bar, a text printing `{scale}`: the layout's first frame's scale. Numeric, /// A map overview on the element (a frame): an extent indicator of its map's frame. @@ -74,6 +76,23 @@ counts!( bar_text_sizes, bar_text_styles, bar_symbols, + legend_text_sizes, + legend_styles, + legend_groups, + legend_class_labels, + legend_hidden, + legend_cut, + legend_columns, + legend_patches, + legend_layout, + legend_sized, + legend_other, + legend_split, + legend_rows, + legend_names, + legend_far, + legend_long, + legend_labels_dropped, cut_texts, braces, overview_fills, @@ -98,7 +117,9 @@ pub(super) fn known_maps(items: &[(f64, usize, Node)], pages: &Pages, dpi: f64) // As `map_item` reads it: one whose extent doesn't read doesn't come in. .filter(|n| n.attribute("type") == Some(MAP) && map_extent(*n).is_some()) .filter_map(|n| { - let uuid = n.attribute("uuid").map(str::trim).filter(|u| !u.is_empty())?; + // One without an id is known too (a legend naming no map shows it), and no surround + // names it. + let uuid = n.attribute("uuid").map(str::trim).unwrap_or_default(); // Where it lands, counted nowhere: its own reading counts it. let place = placed(n, pages, dpi, &mut Tally::default())?; Some((uuid.to_string(), place.page)) @@ -107,7 +128,7 @@ pub(super) fn known_maps(items: &[(f64, usize, Node)], pages: &Pages, dpi: f64) } /// Whether map item `uuid` comes in on layout `page`. -fn on_page(tally: &Tally, uuid: &str, page: usize) -> bool { +pub(super) fn on_page(tally: &Tally, uuid: &str, page: usize) -> bool { !uuid.is_empty() && tally.known.contains(&(uuid.to_string(), page)) } @@ -136,7 +157,8 @@ pub(super) fn link(layouts: &mut [ProjectLayout], tally: &mut Tally) { (Link::Overview { .. }, _) => tally.overviews_unlinked += 1, (Link::Surround, Some(of)) => { if let Some(e) = target.layout.element_mut(l.element) - && let ElementKind::ScaleBar { frame, .. } | ElementKind::NorthArrow { frame, .. } = &mut e.kind + && let ElementKind::ScaleBar { frame, .. } | ElementKind::NorthArrow { frame, .. } | ElementKind::Legend { frame, .. } = + &mut e.kind { *frame = of; } @@ -147,6 +169,36 @@ pub(super) fn link(layouts: &mut [ProjectLayout], tally: &mut Tally) { tally.numeric_other += usize::from(target.layout.first_frame() != Some(of)); counts.add_to(tally); } + (Link::FirstFrame, _) => match target.layout.first_frame() { + Some(of) => { + if let Some(e) = target.layout.element_mut(l.element) + && let ElementKind::Legend { frame, .. } = &mut e.kind + { + *frame = of; + } + counts.add_to(tally); + } + None => { + target.layout.remove(l.element); + tally.unlinked += 1; + } + }, + // A legend whose map a full layout left out: its page's first map instead, every class + // listed, said (QGIS lists the legend's layers still). + (Link::Surround, None) + if target.layout.element_mut(l.element).is_some_and(|e| matches!(e.kind, ElementKind::Legend { .. })) + && target.layout.first_frame().is_some() => + { + let first = target.layout.first_frame(); + if let Some(e) = target.layout.element_mut(l.element) + && let (ElementKind::Legend { frame, all_classes, .. }, Some(of)) = (&mut e.kind, first) + { + (*frame, *all_classes) = (of, true); + } + let mut counts = counts; + counts.legend_far += 1; + counts.add_to(tally); + } (Link::Surround | Link::Numeric, None) => { target.layout.remove(l.element); tally.unlinked += 1; diff --git a/crates/map/src/qgis/layout_legend_tests.rs b/crates/map/src/qgis/layout_legend_tests.rs new file mode 100644 index 0000000000..f255c211b9 --- /dev/null +++ b/crates/map/src/qgis/layout_legend_tests.rs @@ -0,0 +1,574 @@ +//! A QGIS layout's legends (piece 12b of #882), written in the shapes QGIS 4.4 writes them: the +//! layers they list, their classes, their look, and what a RustGIS legend draws otherwise. + +use super::*; +use crate::layout::{ElementKind, MAX_LEGEND_COLUMNS}; + +fn read(text: &str, report: &mut Report) -> Project { + super::read_project(text, "/data/proj", &mut |_, _| Err((super::IMAGE_UNOPENED, false)), report).unwrap() +} + +fn said(report: &Report, part: &str) -> bool { + report.notes.iter().any(|n| n.text.contains(part)) +} + +/// A renderer's symbols `0` and `1`: red and blue markers. +const SYMBOLS: &str = r#""#; + +/// The layout notes (not the layers' own). +fn layout_notes(report: &Report) -> Vec<&str> { + report.notes.iter().map(|n| n.text.as_str()).filter(|t| t.contains("print layouts'")).collect() +} + +/// A project of three memory layers (Places, Roads, and Parks, hidden when `hidden`) and a page +/// with a map `{m}` and `items`. +fn project(hidden: bool, items: &str) -> String { + let layer = |id: &str, name: &str, geom: &str| { + format!( + r#"{id}{name}{geom}?crs=EPSG:2056memory"# + ) + }; + let parks = if hidden { "Qt::Unchecked" } else { "Qt::Checked" }; + format!( + r#"TEPSG:2056 + + {}{}{} + + + {items}"#, + layer("places_1", "Places", "Point"), + layer("roads_1", "Roads", "LineString"), + layer("parks_1", "Parks", "Polygon") + ) +} + +/// A legend of map `{m}` with these attributes and children, 40 × 50 mm. +fn legend(attrs: &str, children: &str) -> String { + format!( + r#"{children}"# + ) +} + +/// QGIS's default styles, the rows' at `size` and `color`. +fn styles(size: f64, color: &str) -> String { + let style = |name: &str, pt: f64, c: &str| { + format!( + r#""# + ) + }; + format!( + "{}{}{}{}", + style("title", 16.0, "0,0,0,255"), + style("group", 14.0, "0,0,0,255"), + style("subgroup", 12.0, "0,0,0,255"), + style("symbolLabel", size, color) + ) +} + +fn legend_of(p: &Project) -> Option<(&crate::layout::Element, u32)> { + let l = &p.layouts[0].layout; + Some((l.elements.iter().find(|e| matches!(e.kind, ElementKind::Legend { .. }))?, l.first_frame()?)) +} + +/// A legend following the project's layers lists every class of all of them, showing its map's +/// frame, at its rows' size and colour, with nothing said. +#[test] +fn a_legend_of_the_projects_layers_comes_in_showing_its_maps_frame() { + let mut report = Report::default(); + let p = read(&project(false, &legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "40,40,120,255"))), &mut report); + let (e, frame) = legend_of(&p).unwrap(); + let ElementKind::Legend { frame: f, title, all_classes, exclude, layer_order, columns, text_size, color, labels, .. } = &e.kind else { + panic!("not a legend") + }; + assert_eq!((*f, title.as_str(), *all_classes, *columns), (frame, "Key", true, 1)); + assert!(exclude.is_empty() && layer_order.is_empty() && labels.is_empty()); + assert!((text_size - 12.0).abs() < 1e-9); + assert_eq!(*color, Some(Rgba::rgb(40, 40, 120))); + assert!((e.w - 40.0).abs() < 1e-9 && (e.h - 50.0).abs() < 1e-9); + assert!(layout_notes(&report).is_empty(), "{:?}", report.notes); +} + +/// A legend filtered by its map's content lists what the map draws, as RustGIS's does. +#[test] +fn a_legend_filtered_by_its_map_lists_what_it_draws() { + let p = read( + &project(false, &legend(r#"syncMode="AllProjectLayers" legendFilterByMap="1""#, &styles(12.0, "0,0,0,255"))), + &mut Report::default(), + ); + assert!(matches!(legend_of(&p).unwrap().0.kind, ElementKind::Legend { all_classes: false, .. })); +} + +/// A legend's own list of layers gives their order, the project's others left out, and their own +/// names; its groups are listed flat and its classes' own labels shown as the layers', said. +#[test] +fn a_legends_own_list_gives_its_layers_and_names() { + let tree = r#" + + + + + "#; + let mut report = Report::default(); + let p = read(&project(false, &legend("", &(styles(12.0, "0,0,0,255") + tree))), &mut report); + let ElementKind::Legend { all_classes, exclude, layer_order, labels, .. } = &legend_of(&p).unwrap().0.kind else { + panic!("not a legend") + }; + assert!(*all_classes); + assert_eq!(layer_order, &["Roads", "Places"]); + assert_eq!(exclude, &["Parks"]); + assert_eq!(labels.get("Roads").map(String::as_str), Some("Main roads")); + assert_eq!(labels.get("Places").map(String::as_str), Some("Towns")); + assert_eq!( + layout_notes(&report), + [ + "its print layouts' legends' groups, their layers listed on their own (1)", + "its print layouts' legends' own labels for their layers' classes, showing the layers' (1)" + ] + ); +} + +/// A legend listing a layer the map hides says so (RustGIS's lists what the map shows); one whose +/// own list leaves it out doesn't. +#[test] +fn a_legend_listing_a_hidden_layer_is_said() { + let mut report = Report::default(); + read(&project(true, &legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255"))), &mut report); + assert!(said(&report, "legends listing layers the map hides, which a RustGIS legend leaves out (1)"), "{:?}", report.notes); + let tree = r#""#; + let mut report = Report::default(); + read(&project(true, &legend("", &(styles(12.0, "0,0,0,255") + tree))), &mut report); + assert!(layout_notes(&report).is_empty(), "{:?}", report.notes); +} + +/// A legend naming no map shows the first frame on its page; one on a page without a map is left +/// out, said as only that. +#[test] +fn a_legend_naming_no_map_shows_the_pages_first_frame() { + let item = legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255")).replace(r#"map_uuid="{m}""#, r#"map_uuid="""#); + let mut report = Report::default(); + let p = read(&project(false, &item), &mut report); + let (e, frame) = legend_of(&p).unwrap(); + assert!(matches!(e.kind, ElementKind::Legend { frame: f, .. } if f == frame)); + assert!(layout_notes(&report).is_empty(), "{:?}", report.notes); + // A page without a map (its item one of another kind). + let no_map = project(false, &item).replace(r#"type="65639""#, r#"type="99999""#); + let mut report = Report::default(); + let p = read(&no_map, &mut report); + assert!(legend_of(&p).is_none()); + assert!(said(&report, "scale bars, north arrows and legends whose map isn't on their page, or is left out (1)"), "{:?}", report.notes); +} + +/// A legend QGIS hasn't sized yet (it sizes one to its content as it draws it) is given room for a +/// row a layer, said. +#[test] +fn an_unsized_legend_is_given_room() { + let item = legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255")).replace(r#"size="40,50,mm""#, r#"size="0,0,mm""#); + let mut report = Report::default(); + let p = read(&project(false, &item), &mut report); + let (e, _) = legend_of(&p).unwrap(); + assert!(e.w >= 50.0 && e.h > 10.0, "{e:?}"); + assert_eq!( + layout_notes(&report), + ["its print layouts' legends sized to their content that QGIS hasn't sized yet, given room for a row a layer (1)"] + ); +} + +/// A legend's columns past RustGIS's, its text styles and spacing of its own, are said. +#[test] +fn a_legends_settings_past_rustgis_are_said() { + let item = legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255").replace(r#"fontSize="16""#, r#"fontSize="22""#)) + .replace(r#"columnCount="1""#, r#"columnCount="9""#) + .replace(r#"wrapChar="""#, r#"wrapChar="|""#); + let mut report = Report::default(); + let p = read(&project(false, &item), &mut report); + assert!(matches!(legend_of(&p).unwrap().0.kind, ElementKind::Legend { columns, .. } if columns == MAX_LEGEND_COLUMNS)); + for part in [ + "legends' columns brought within RustGIS's (1 to 6) (1)", + "legends' title, group and layer texts in sizes, faces or fonts of their own, in RustGIS's proportion to their rows (1)", + "legends' spacing, alignment, wrapping, symbol size limits, even columns or atlas filter, as RustGIS draws a legend (1)", + ] { + assert!(said(&report, part), "{part}: {:?}", report.notes); + } +} + +/// A legend's `` row is shown only where a layer drawn by categories has one; +/// where some have it and others don't, it is shown for all, said. +#[test] +fn a_legends_other_values_row_follows_qgis() { + let categorized = |id: &str, name: &str, values: &[&str]| { + let cats: String = values.iter().map(|v| format!(r#""#)).collect(); + format!( + r#"{id}{name}Point?crs=EPSG:2056&field=kind:stringmemory{cats}{SYMBOLS}"# + ) + }; + let with_layers = |layers: &str| { + project(false, &legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255"))) + .replace("", &format!("{layers}")) + }; + let other = |p: &Project| match legend_of(p).unwrap().0.kind { + ElementKind::Legend { hide_other, .. } => !hide_other, + _ => false, + }; + let mut report = Report::default(); + assert!(!other(&read(&with_layers(&categorized("c1", "Kinds", &["a", "b"])), &mut report))); + assert!(!said(&report, "all other values"), "{:?}", report.notes); + let mut report = Report::default(); + assert!(other(&read(&with_layers(&categorized("c1", "Kinds", &["a", ""])), &mut report))); + assert!(!said(&report, "all other values"), "{:?}", report.notes); + let both = categorized("c1", "Kinds", &["a", ""]) + &categorized("c2", "Sorts", &["x", "y"]); + let mut report = Report::default(); + assert!(other(&read(&with_layers(&both), &mut report))); + assert!(said(&report, "some with one for all other values and some without, showing that row for all (1)"), "{:?}", report.notes); +} + +/// The corpus's legends, as QGIS 4.4 wrote them: each shows the map's frame; the project's layers +/// with every class, its own list (a layer renamed, another left out, two columns), and what the +/// map draws. +#[test] +fn the_corpus_legends_come_in() { + let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("testdata/qgis/generated/qgs"); + let text = std::fs::read_to_string(root.join("layout-legends.qgs")).unwrap(); + let mut report = Report::default(); + let p = super::read_project(&text, &root.to_string_lossy(), &mut |_, _| Err((super::IMAGE_UNOPENED, false)), &mut report).unwrap(); + let l = &p.layouts[0].layout; + let frame = l.first_frame().unwrap(); + let legend = |title: &str| { + l.elements.iter().find_map(|e| match &e.kind { + ElementKind::Legend { title: t, frame: f, all_classes, layer_order, exclude, labels, columns, hide_other, .. } + if t == title => + { + assert_eq!(*f, frame); + assert!(*hide_other, "{title}: no layer has a category for all other values"); + Some((*all_classes, layer_order.clone(), exclude.clone(), labels.clone(), *columns)) + } + _ => None, + }) + }; + let (all, order, exclude, _, columns) = legend("All layers").unwrap(); + assert!(all && order.is_empty() && exclude.is_empty() && columns == 1); + let (all, order, exclude, labels, columns) = legend("Own list").unwrap(); + assert!(all); + assert_eq!(order, ["points", "lines"]); + assert_eq!(exclude, ["polygons"]); + assert_eq!(labels.get("lines").map(String::as_str), Some("Paths")); + assert_eq!(columns, 2); + let (all, ..) = legend("On the map").unwrap(); + assert!(!all); + // Only its two columns, kept whole in QGIS, evened here. + assert_eq!( + layout_notes(&report), + ["its print layouts' legends in several columns keeping each layer whole, their columns evened, a layer split between them (1)"] + ); +} + +/// A categorized layer inside a cluster, and a rule-based layer, draw all other values where QGIS +/// has a category for them or an ELSE rule: the row shown then, and hidden otherwise. +#[test] +fn other_values_follow_rules_and_wrapped_renderers() { + let rules = |id: &str, name: &str, with_else: bool| { + let else_rule = if with_else { r#""# } else { "" }; + format!( + r#"{id}{name}Point?crs=EPSG:2056&field=kind:stringmemory{else_rule}{SYMBOLS}"# + ) + }; + let wrapped = format!( + r#"w1ClusteredPoint?crs=EPSG:2056&field=kind:stringmemory{SYMBOLS}"# + ); + let with_layers = |layers: &str| { + project(false, &legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255"))) + .replace("", &format!("{layers}")) + }; + let shows_other = |text: &str, report: &mut Report| match legend_of(&read(text, report)).unwrap().0.kind { + ElementKind::Legend { hide_other, .. } => !hide_other, + _ => false, + }; + let mut report = Report::default(); + assert!(shows_other(&with_layers(&rules("r1", "Ruled", true)), &mut report)); + assert!(!said(&report, "all other values"), "{:?}", report.notes); + assert!(!shows_other(&with_layers(&rules("r1", "Ruled", false)), &mut Report::default())); + assert!(shows_other(&with_layers(&wrapped), &mut Report::default())); + let mut report = Report::default(); + assert!(shows_other(&with_layers(&(rules("r1", "Ruled", false) + &wrapped)), &mut report)); + assert!(said(&report, "showing that row for all (1)"), "{:?}", report.notes); +} + +/// A legend filtered by its map lists none of the layers the map hides, as RustGIS's: nothing +/// said; one of a map on another page shows its page's first map and lists every class, said. +#[test] +fn filtered_and_far_legends() { + let mut report = Report::default(); + read(&project(true, &legend(r#"syncMode="AllProjectLayers" legendFilterByMap="1""#, &styles(12.0, "0,0,0,255"))), &mut report); + assert!(layout_notes(&report).is_empty(), "{:?}", report.notes); + let far = legend(r#"syncMode="AllProjectLayers" legendFilterByMap="1""#, &styles(12.0, "0,0,0,255")) + .replace(r#"map_uuid="{m}""#, r#"map_uuid="{elsewhere}""#); + let mut report = Report::default(); + let p = read(&project(false, &far), &mut report); + let (e, frame) = legend_of(&p).unwrap(); + assert!(matches!(e.kind, ElementKind::Legend { frame: f, all_classes: true, .. } if f == frame)); + assert_eq!( + layout_notes(&report), + ["its print layouts' legends of a map not on their page (or not read), showing their page's first map (1)"] + ); +} + +/// A legend's own rows for a layer (classes left out or reordered), and one of two layers of a +/// name, are said; a plain entry isn't. +#[test] +fn own_rows_and_shared_names_are_said() { + let entry = |id: &str, extra: &str| { + format!( + r#"{extra}"# + ) + }; + let ordered = + r#""#; + let one = |tree: &str, text: String| { + let mut report = Report::default(); + read(&text.replace("TREE", tree), &mut report); + layout_notes(&report).into_iter().map(str::to_string).collect::>() + }; + let base = || project(false, &legend("", &(styles(12.0, "0,0,0,255") + "TREE"))); + assert!(!one(&entry("roads_1", ""), base()).iter().any(|n| n.contains("rows of its own"))); + assert!(one(&entry("roads_1", ordered), base()).iter().any(|n| n.contains("rows of its own"))); + // Two layers named Roads: one listed, the other not. + let twins = base().replace(r#"Parks"#, r#"roads"#); + let notes = one(&entry("roads_1", ""), twins); + assert!(notes.iter().any(|n| n.contains("listing one of two layers of a name")), "{notes:?}"); +} + +/// A legend's text size, symbol size and title past RustGIS's are brought within it, said. +#[test] +fn a_legends_sizes_past_rustgis_are_said() { + let long = "T".repeat(300); + let item = legend(r#"syncMode="AllProjectLayers" symbolWidth="200""#, &styles(150.0, "0,0,0,255")) + .replace(r#"symbolWidth="7" "#, "") + .replace(r#"title="Key""#, &format!(r#"title="{long}""#)); + let mut report = Report::default(); + let p = read(&project(false, &item), &mut report); + let ElementKind::Legend { text_size, title, .. } = &legend_of(&p).unwrap().0.kind else { panic!("not a legend") }; + assert!((text_size - 100.0).abs() < 1e-9); + assert_eq!(title.chars().count(), crate::layout::MAX_LEGEND_LABEL_CHARS); + for part in [ + "legends' text sizes outside 4 to 100 pt, drawn at the nearest (1)", + "legends' symbol sizes brought within RustGIS's (1)", + "legends' titles and layer labels longer than 200 characters, cut there (1)", + ] { + assert!(said(&report, part), "{part}: {:?}", report.notes); + } +} + +/// An ELSE rule under a rule with a filter is a class of the import, not all other values: no +/// `` row. +#[test] +fn a_nested_else_rule_is_no_other_values_row() { + let nested = format!( + r#"n1NestedPoint?crs=EPSG:2056&field=kind:stringmemory{SYMBOLS}"# + ); + let text = project(false, &legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255"))) + .replace("", &format!("{nested}")); + let p = read(&text, &mut Report::default()); + assert!(matches!(legend_of(&p).unwrap().0.kind, ElementKind::Legend { hide_other: true, .. })); +} + +/// Each of a layer's own legend settings is said; a legend listing the map's visible layers says +/// nothing of a hidden one; one in several columns of single rows says no split; a filtered +/// legend naming no map lists every class. +#[test] +fn own_settings_visible_layers_columns_and_no_map() { + let notes = |text: String| { + let mut report = Report::default(); + read(&text, &mut report); + layout_notes(&report).into_iter().map(str::to_string).collect::>() + }; + for attr in [r#"legend_exp="upper(@layer_name)""#, r#"patch_size="10,5""#, r#"legend_split_behavior="1""#] { + let tree = format!(r#""#); + let n = notes(project(false, &legend("", &(styles(12.0, "0,0,0,255") + &tree)))); + assert!(n.iter().any(|t| t.contains("rows of its own")), "{attr}: {n:?}"); + } + let visible = notes(project(true, &legend(r#"syncMode="VisibleLayers""#, &styles(12.0, "0,0,0,255")))); + assert!(visible.is_empty(), "{visible:?}"); + let columns = legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255")).replace(r#"columnCount="1""#, r#"columnCount="2""#); + let n = notes(project(false, &columns)); + assert!(!n.iter().any(|t| t.contains("several columns")), "{n:?}"); + let no_map = legend(r#"syncMode="AllProjectLayers" legendFilterByMap="1""#, &styles(12.0, "0,0,0,255")) + .replace(r#"map_uuid="{m}""#, r#"map_uuid="""#); + let p = read(&project(false, &no_map), &mut Report::default()); + assert!(matches!(legend_of(&p).unwrap().0.kind, ElementKind::Legend { all_classes: true, .. })); +} + +/// A legend's own list naming one of two layers of a name leaves neither out (RustGIS names +/// them as one), said; the main annotation layer, which a QGIS legend never lists, is left out. +#[test] +fn shared_names_and_the_annotation_layer() { + let tree = r#""#; + let text = project(false, &legend("", &(styles(12.0, "0,0,0,255") + tree))) + .replace("Parks", "ROADS") + .replace("", r#""#); + let mut report = Report::default(); + let p = read(&text, &mut report); + let ElementKind::Legend { exclude, .. } = &legend_of(&p).unwrap().0.kind else { panic!("not a legend") }; + assert!(!exclude.iter().any(|e| e.eq_ignore_ascii_case("roads")), "{exclude:?}"); + assert!(exclude.iter().any(|e| e == "Places"), "{exclude:?}"); + assert!(p.main_annotations.is_some()); + assert!(exclude.iter().any(|e| e == "Annotations"), "{exclude:?}"); + assert!(said(&report, "legends listing one of two layers of a name, which RustGIS's legend lists both of (1)"), "{:?}", report.notes); +} + +/// A legend's own list past the entries the layer tree reader takes is cut there, said. +#[test] +fn a_legends_list_past_the_readers_is_said() { + let entries: String = (0..4001).map(|_| r#""#).collect(); + let tree = format!("{entries}"); + let mut report = Report::default(); + read(&project(false, &legend("", &(styles(12.0, "0,0,0,255") + &tree))), &mut report); + assert!( + said(&report, "legends' lists of layers past the 1000 a legend keeps, or past the entries an import reads, cut there (1)"), + "{:?}", + report.notes + ); +} + +/// A category for all other values with a transparent or switched-off symbol still has its row +/// in QGIS's legend: shown. +#[test] +fn a_transparent_or_switched_off_catch_all_keeps_its_row() { + for category in + [r#""#, r#""#] + { + let symbols = SYMBOLS.replace("", r#""#); + let ml = format!( + r#"c1KindsPoint?crs=EPSG:2056&field=kind:stringmemory{category}{symbols}"# + ); + let text = project(false, &legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255"))) + .replace("", &format!("{ml}")); + let p = read(&text, &mut Report::default()); + assert!(matches!(legend_of(&p).unwrap().0.kind, ElementKind::Legend { hide_other: false, .. }), "{category}"); + } +} + +/// Two listed layers of one name can't both keep their own names in a RustGIS legend: the first +/// kept, said. +#[test] +fn two_labels_for_one_name_keep_the_first() { + let tree = + r#""#; + let text = project(false, &legend("", &(styles(12.0, "0,0,0,255") + tree))) + .replace("Parks", "Roads"); + let mut report = Report::default(); + let p = read(&text, &mut report); + let ElementKind::Legend { labels, .. } = &legend_of(&p).unwrap().0.kind else { panic!("not a legend") }; + assert_eq!(labels.get("Roads").map(String::as_str), Some("Main")); + assert!( + said(&report, "legends' own names for a layer sharing its name with another they name, the first kept (1)"), + "{:?}", + report.notes + ); +} + +/// A legend naming no map on a page whose map has no id shows that map. +#[test] +fn a_mapless_legend_finds_a_map_without_an_id() { + let item = legend(r#"syncMode="AllProjectLayers""#, &styles(12.0, "0,0,0,255")).replace(r#"map_uuid="{m}""#, r#"map_uuid="""#); + let text = project(false, &item).replace(r#"uuid="{m}""#, ""); + let mut report = Report::default(); + let p = read(&text, &mut report); + let (e, frame) = legend_of(&p).unwrap(); + assert!(matches!(e.kind, ElementKind::Legend { frame: f, .. } if f == frame)); +} + +/// A legend whose map a full layout leaves out shows its page's first map, every class listed, +/// said. +#[test] +fn a_legend_whose_map_is_left_out_shows_the_first() { + let mut items = String::new(); + for i in 0..498 { + items.push_str(&format!(r#""#)); + } + let named = legend(r#"syncMode="AllProjectLayers" legendFilterByMap="1" zValue="3""#, &styles(12.0, "0,0,0,255")) + .replace(r#"map_uuid="{m}""#, r#"map_uuid="{b}""#); + items.push_str(&named); + items.push_str(r#""#); + let mut report = Report::default(); + let p = read(&project(false, &items), &mut report); + let (e, frame) = legend_of(&p).unwrap(); + assert!(matches!(e.kind, ElementKind::Legend { frame: f, all_classes: true, .. } if f == frame)); + assert!(said(&report, "legends of a map not on their page (or not read), showing their page's first map (1)"), "{:?}", report.notes); + assert!(said(&report, "elements past the 500 a layout keeps (1)"), "{:?}", report.notes); +} + +/// The layer names all of an import's legends keep are bounded: legends past it are left out, +/// said as only that. +#[test] +fn legends_past_the_names_an_import_keeps_are_left_out() { + let layers: String = (0..300).map(|i| format!(r#"l{i}L{i}Point?crs=EPSG:2056memory"#)).collect(); + let tree = r#""#; + let one = legend("", &(styles(12.0, "0,0,0,255") + tree)); + let items = one.repeat(400); + let text = project(false, &items).replace("", &format!("{layers}")); + let mut report = Report::default(); + let p = read(&text, &mut report); + let kept = p.layouts[0].layout.elements.iter().filter(|e| matches!(e.kind, ElementKind::Legend { .. })).count(); + // Each keeps 303 names (302 left out, 1 in order). + assert_eq!(kept, super::layout::legend_names_limit() / 303); + assert!(said(&report, &format!("legends past the 100000 layer names an import's legends keep ({})", 400 - kept)), "{:?}", report.notes); +} + +/// A layer of a name shown under that name, then another of it with its own: the first's text is +/// what RustGIS shows for both, the second's said. +#[test] +fn a_plain_name_first_keeps_its_text() { + let tree = + r#""#; + let text = project(false, &legend("", &(styles(12.0, "0,0,0,255") + tree))) + .replace("Parks", "Roads"); + let mut report = Report::default(); + let p = read(&text, &mut report); + let ElementKind::Legend { labels, .. } = &legend_of(&p).unwrap().0.kind else { panic!("not a legend") }; + assert!(labels.is_empty(), "{labels:?}"); + assert!(said(&report, "the first kept (1)"), "{:?}", report.notes); +} + +/// A legend listing two layers of one name, both under that name, orders it once: nothing cut by +/// the layout, nothing said. +#[test] +fn two_layers_of_one_name_are_ordered_once() { + let tree = r#""#; + let text = project(false, &legend("", &(styles(12.0, "0,0,0,255") + tree))) + .replace("Parks", "Roads"); + let mut report = Report::default(); + let mut p = read(&text, &mut report); + let ElementKind::Legend { layer_order, .. } = &legend_of(&p).unwrap().0.kind else { panic!("not a legend") }; + assert_eq!(layer_order, &["Roads"]); + // Both shown under their name, as QGIS shows them: nothing to say. + assert!(layout_notes(&report).is_empty(), "{:?}", report.notes); + // The layout keeps it as it is: nothing to cut. + let repairs = p.layouts[0].layout.clamp(); + assert_eq!(repairs.elements_cut, 0); +} + +/// A layer the map hides decides nothing of what a legend shows: its category for all other +/// values doesn't show the row for the layers shown. +#[test] +fn a_hidden_layers_catch_all_shows_no_row() { + let ml = |id: &str, name: &str, cats: &str| { + format!( + r#"{id}{name}Point?crs=EPSG:2056&field=kind:stringmemory{cats}{SYMBOLS}"# + ) + }; + let shown = ml("c1", "Kinds", r#""#); + let hidden = ml( + "c2", + "Hidden", + r#""#, + ); + let text = project(false, &legend(r#"syncMode="AllProjectLayers" legendFilterByMap="1""#, &styles(12.0, "0,0,0,255"))) + .replace("", &format!("{shown}{hidden}")) + .replace( + "", + r#""#, + ); + let mut report = Report::default(); + let p = read(&text, &mut report); + assert!(matches!(legend_of(&p).unwrap().0.kind, ElementKind::Legend { hide_other: true, .. })); + assert!(!said(&report, "all other values"), "{:?}", report.notes); +} diff --git a/crates/map/src/qgis/layout_surround_tests.rs b/crates/map/src/qgis/layout_surround_tests.rs index 11597fcfe1..1b03b273cd 100644 --- a/crates/map/src/qgis/layout_surround_tests.rs +++ b/crates/map/src/qgis/layout_surround_tests.rs @@ -217,7 +217,7 @@ fn a_surround_without_its_map_on_its_page_is_left_out() { assert!(p.layouts.iter().flat_map(|l| &l.layout.elements).all(|e| !matches!(e.kind, ElementKind::NorthArrow { .. }))); let texts: Vec<&str> = report.notes.iter().filter(|n| !n.text.starts_with("print layouts of several pages")).map(|n| n.text.as_str()).collect(); - assert_eq!(texts, ["its print layouts' scale bars and north arrows whose map isn't on their page, or is left out (3)"]); + assert_eq!(texts, ["its print layouts' scale bars, north arrows and legends whose map isn't on their page, or is left out (3)"]); } /// A north arrow's own settings are said as a north arrow's, not given to a picture: a hidden, @@ -365,7 +365,7 @@ fn a_surround_of_a_map_that_doesnt_come_in_says_only_that() { assert_eq!( texts, [ - "its print layouts' scale bars and north arrows whose map isn't on their page, or is left out (1)", + "its print layouts' scale bars, north arrows and legends whose map isn't on their page, or is left out (1)", "its print layouts' items whose place or shape doesn't read (1)" ] ); @@ -413,7 +413,7 @@ fn a_surround_whose_map_a_full_layout_leaves_out_says_only_that() { assert_eq!( texts, [ - "its print layouts' scale bars and north arrows whose map isn't on their page, or is left out (1)", + "its print layouts' scale bars, north arrows and legends whose map isn't on their page, or is left out (1)", "its print layouts' elements past the 500 a layout keeps (1)" ] ); diff --git a/crates/map/src/qgis/layout_tests.rs b/crates/map/src/qgis/layout_tests.rs index 2c512262a7..34e7861765 100644 --- a/crates/map/src/qgis/layout_tests.rs +++ b/crates/map/src/qgis/layout_tests.rs @@ -131,8 +131,8 @@ fn qgis_layout_items_without_a_place_are_noted() { let frame = l.first_frame().unwrap(); assert!(l.elements.iter().any(|e| matches!(e.kind, ElementKind::ScaleBar { frame: f, .. } if f == frame))); assert!(l.elements.iter().any(|e| matches!(e.kind, ElementKind::NorthArrow { frame: f, .. } if f == frame))); + assert!(l.elements.iter().any(|e| matches!(e.kind, ElementKind::Legend { frame: f, .. } if f == frame))); for part in [ - "legends (1)", "north arrows (pictures turned with a map), drawn as RustGIS's arrow (1)", "attribute tables (1)", "HTML frames (1)", @@ -557,7 +557,7 @@ fn a_full_layout_counts_only_pictures_that_would_come_in() { read(&qgs, &mut report); // The north arrows' map isn't in the layout: they are said as that, not counted past it. assert!(!said(&report, "elements past the 500"), "{:?}", report.notes); - assert!(said(&report, "scale bars and north arrows whose map isn't on their page, or is left out (3)"), "{:?}", report.notes); + assert!(said(&report, "scale bars, north arrows and legends whose map isn't on their page, or is left out (3)"), "{:?}", report.notes); assert!(said(&report, "pictures that can't be read (1;"), "{:?}", report.notes); // What doesn't come in isn't said as drawn otherwise. assert!(!said(&report, "blending modes"), "{:?}", report.notes); diff --git a/crates/map/src/qgis/mod.rs b/crates/map/src/qgis/mod.rs index 5ecfa5c71f..523358b7ee 100644 --- a/crates/map/src/qgis/mod.rs +++ b/crates/map/src/qgis/mod.rs @@ -15,6 +15,8 @@ mod expr; mod labels; mod layout; #[cfg(test)] +mod layout_legend_tests; +#[cfg(test)] mod layout_surround_tests; #[cfg(test)] mod layout_tests; @@ -260,6 +262,10 @@ pub struct Style { /// The scaled diagram's original classification, for checking once the destination fields /// are known. Import metadata only, not a saved diagram setting. pub diagram_by: Option, + /// Drawn by categories or rules, one of them QGIS's "all other values" (a category of an + /// empty or NULL value, an ELSE rule taken as the rest), whatever its symbol: a legend's + /// `` row. Import metadata only, not a saved setting. + pub other_values: bool, /// 0 opaque to 100 invisible. pub transparency: Option, /// The field whose dates the time slider reads (QGIS's time settings). Not applied by @@ -678,7 +684,6 @@ pub fn read_project(text: &str, dir: &str, images: &mut ReadImage, report: &mut // are checked, and their groups. let mut tree = Tree::read(root); project_notes(root, report); - project.layouts = layout::read_layouts(root, dir, &project.title, report); // The map's rotation: one that doesn't read faces north, noted. if let Some(r) = canvas.and_then(|c| child(c, "rotation")).and_then(|r| r.text()).map(str::trim).filter(|r| !r.is_empty()) { match r.parse::().ok().filter(|r| r.is_finite()) { @@ -799,6 +804,8 @@ pub fn read_project(text: &str, dir: &str, images: &mut ReadImage, report: &mut layers.sort_by_key(|(at, _)| at.unwrap_or(usize::MAX)); project.layers = layers.into_iter().map(|(_, l)| l).collect(); resolve_virtual_layers(&mut project.layers, report); + // The print layouts, after the layers: their legends list the layers as the import made them. + project.layouts = layout::read_layouts(root, dir, (&project.title, &project.layers, project.main_annotations.as_ref()), report); group_notes(&tree, &blended, &effects, report); if !unkept.is_empty() { let names = unkept.iter().take(8).map(String::as_str).collect::>().join(", "); diff --git a/crates/map/src/qgis/renderer.rs b/crates/map/src/qgis/renderer.rs index 64662b4067..b6ae5961c2 100644 --- a/crates/map/src/qgis/renderer.rs +++ b/crates/map/src/qgis/renderer.rs @@ -214,6 +214,7 @@ fn categorized(r: Node, layer: &str, style: &mut Style, report: &mut Report, sym for v in values { // An empty value is QGIS's "all other values". if v.is_empty() || v == "NULL" { + style.other_values = true; other = c.symbol; other_strokes = if c.stacked() { c.strokes.clone() } else { Vec::new() }; other_fills.clone_from(&c.fills); @@ -453,6 +454,8 @@ fn unique( other: Option<&Converted>, other_label: Option, ) { + // A rule for the rest: QGIS's "all other values". + style.other_values |= other.is_some(); let mut class_strokes = BTreeMap::new(); let mut class_fills = BTreeMap::new(); let mut class_labels = BTreeMap::new(); diff --git a/crates/map/src/qgis/tests.rs b/crates/map/src/qgis/tests.rs index e322004508..3ffaf36410 100644 --- a/crates/map/src/qgis/tests.rs +++ b/crates/map/src/qgis/tests.rs @@ -1152,7 +1152,7 @@ fn every_corpus_file_reads() { } } let projects = files("generated/qgs", &["qgs", "qgz"]); - assert_eq!(projects.len(), 40, "project corpus changed: {projects:?}"); + assert_eq!(projects.len(), 41, "project corpus changed: {projects:?}"); for path in &projects { let bytes = std::fs::read(path).unwrap(); let text = if path.extension().is_some_and(|e| e == "qgz") { diff --git a/crates/map/testdata/qgis/README.md b/crates/map/testdata/qgis/README.md index 1f0e514cf7..04e14435af 100644 --- a/crates/map/testdata/qgis/README.md +++ b/crates/map/testdata/qgis/README.md @@ -10,7 +10,7 @@ no specification of these formats, so the corpus stands in for one: `every_corpu | Folder | What | Licence | |---|---|---| | `generated/qml/` | 126 styles written through QGIS's API (4.2.3; the SVG marker ones 4.4.0), each varying one thing: every symbol layer type with its defaults, raster image markers (a PNG and a JPEG, in a file and embedded; sizes in each unit, rotation, an offset, anchor points, a fixed aspect ratio, opacity, and along a line), SVG markers (an SVG with `param(…)` colours and outline width and one without, in a file and embedded, one from QGIS's own library, which isn't copied here; colours with alpha; sizes in each unit, rotation, an offset, anchor points, a fixed aspect ratio, opacity, and along a line), every renderer (categorized and graduated by expression, rule-based with nested and else rules), every paint effect, data-defined size, angle and colour, labels (every placement, buffer, background, shadow, font, wrap, expression text, offsets, data-defined settings, scale ranges, curved labels, each callout, rule-based labels), layer settings (opacity, blend mode, scale range, reference scale, subset), diagrams (pie, by fields and expressions, a histogram, a stacked bar and a text diagram, two of them sized between two values) and raster renderers (grey, pseudocolour interpolated, discrete and exact, multiband, paletted, hillshade, contour) | Apache-2.0, like RustGIS: made by Dominik Strebel ([@pick2510](https://github.com/pick2510)) for the RustGIS project | -| `generated/qgs/` | 40 projects: one per provider (OGR, GDAL, memory, delimited text by x/y and WKT, SpatiaLite, virtual (on a file, on another layer, and grouping), WMS, WMTS, XYZ, raster MBTiles, WFS (also with a filter), OGC API Features, WCS, ArcGIS feature, map, image and vector tile services, vector tiles by address, with a MapLibre style, from MBTiles and from PMTiles, PostGIS, SQL Server, GPX waypoints and tracks); project structure (groups, a mutually exclusive group, a map theme, a bookmark, a variable, a relation, a join, a virtual field, time from a field, two styles on a layer); groups nested, hidden, collapsed, empty and drawn as one (a group layer with its opacity and blending); bookmarks (turned, in a group, in degrees), relations (on one pair of fields, on two, a composition, a polymorphic one) and time settings (a span of months; time from a field, from a field for a duration, a fixed range); a layout with every item and an atlas; `layout-sheets.qgs`, print layouts as map sheets (an A4 landscape sheet of two pages with a framed, turned map, a title and a note with an expression, a turned label with a background and frame, a picture, a rounded rectangle, a translucent ellipse, a triangle and a dashed line, items placed in mm, cm, in and pt, a hidden item, one left out of exports and two grouped; and a Letter portrait sheet in inches), written by QGIS 4.4.0; `layout-surrounds.qgs`, a sheet with the surrounds tied to a map (scale bars of a single box, ticks up and a stepped line fitted to their box, a numeric one, a north arrow following the map, and an overview map outlining its extent), written by QGIS 4.4.0; the annotation layer with every item; annotations with their settings (styled marks, lines and a polygon with a hole, text aligned, turned, in HTML and with a buffer, rectangle text with a background and frame or of a fixed size, a picture file and an SVG, text along a line, one switched off, z order, the main annotation layer); `all-styles.qgz`, every style above on its own layer (written before the diagrams were added); `raster-markers.qgs`, each raster image marker style on its own layer, its image files named relative to it; `svg-markers.qgs`, the same for each SVG marker style, written by QGIS 4.4.0 | Apache-2.0 | +| `generated/qgs/` | 41 projects: one per provider (OGR, GDAL, memory, delimited text by x/y and WKT, SpatiaLite, virtual (on a file, on another layer, and grouping), WMS, WMTS, XYZ, raster MBTiles, WFS (also with a filter), OGC API Features, WCS, ArcGIS feature, map, image and vector tile services, vector tiles by address, with a MapLibre style, from MBTiles and from PMTiles, PostGIS, SQL Server, GPX waypoints and tracks); project structure (groups, a mutually exclusive group, a map theme, a bookmark, a variable, a relation, a join, a virtual field, time from a field, two styles on a layer); groups nested, hidden, collapsed, empty and drawn as one (a group layer with its opacity and blending); bookmarks (turned, in a group, in degrees), relations (on one pair of fields, on two, a composition, a polymorphic one) and time settings (a span of months; time from a field, from a field for a duration, a fixed range); a layout with every item and an atlas; `layout-sheets.qgs`, print layouts as map sheets (an A4 landscape sheet of two pages with a framed, turned map, a title and a note with an expression, a turned label with a background and frame, a picture, a rounded rectangle, a translucent ellipse, a triangle and a dashed line, items placed in mm, cm, in and pt, a hidden item, one left out of exports and two grouped; and a Letter portrait sheet in inches), written by QGIS 4.4.0; `layout-surrounds.qgs`, a sheet with the surrounds tied to a map (scale bars of a single box, ticks up and a stepped line fitted to their box, a numeric one, a north arrow following the map, and an overview map outlining its extent), written by QGIS 4.4.0; `layout-legends.qgs`, a sheet with legends (one listing the project's layers, its points in two categories; one with its own list, a layer renamed and another left out, in two columns; one filtered by its map), written by QGIS 4.4.0; the annotation layer with every item; annotations with their settings (styled marks, lines and a polygon with a hole, text aligned, turned, in HTML and with a buffer, rectangle text with a background and frame or of a fixed size, a picture file and an SVG, text along a line, one switched off, z order, the main annotation layer); `all-styles.qgz`, every style above on its own layer (written before the diagrams were added); `raster-markers.qgs`, each raster image marker style on its own layer, its image files named relative to it; `svg-markers.qgs`, the same for each SVG marker style, written by QGIS 4.4.0 | Apache-2.0 | | `generated/data/` | The data those files use: `sample.gpkg` (layers `points`, `lines` and `polygons`, 9 made-up features each, fields `id`, `name`, `kind`, `value`, `angle`, `day`), `dem.tif` (3 bands of a linear surface), two CSVs, a GPX file, `picture.png` (a red 40 × 20 picture), `marker.png` (32 × 16, a red square and a blue bar) and `marker.jpg` (24 × 24, green with a yellow corner), the raster image markers' images; `icon.svg` (the same square and bar) and `marker.svg` (a triangle and a rectangle in `param(…)` colours), the SVG markers' images | Apache-2.0 | | `generated/generate.py`, `scrub.py` | The generator, and the step that removes the user's name and absolute paths from what QGIS writes | Apache-2.0 | | `generated/types.txt` | The element types QGIS 4.2.3 knows (symbol layers, renderers, providers, label placements, callouts, annotation and layout items, paint effects): the checklist the corpus was made from. A few have no file yet: the single-colour raster renderer, and the text table, fixed table, elevation profile and chart layout items | Apache-2.0 | @@ -40,7 +40,7 @@ QGIS 4.2.3 wrote the corpus, and 4.4.0 the SVG marker files. The command runs wh installed (here the Flathub Flatpak, whose `/tmp` is private, so it writes under `~/.cache`) and writes the whole corpus again, so copy only the files you mean to replace: for the SVG markers, `data/icon.svg`, `data/marker.svg`, `qml/symbol-svg-marker-*.qml` and `qgs/svg-markers.qgs`; for the map sheets, -`qgs/layout-sheets.qgs` and `qgs/layout-surrounds.qgs`. +`qgs/layout-sheets.qgs`, `qgs/layout-surrounds.qgs` and `qgs/layout-legends.qgs`. ```sh mkdir -p ~/.cache/qgis-corpus diff --git a/crates/map/testdata/qgis/generated/generate.py b/crates/map/testdata/qgis/generated/generate.py index b60abf7daa..2f795f0fa2 100644 --- a/crates/map/testdata/qgis/generated/generate.py +++ b/crates/map/testdata/qgis/generated/generate.py @@ -1462,6 +1462,68 @@ def layout_surrounds(): attempt("layout surrounds", layout_surrounds) + + +# A sheet with legends (piece 12b): one listing the project's layers, one with its own list (a +# layer renamed, another left out, in two columns), and one filtered by its map. QGIS sizes a +# legend as it draws it, so the sheet is exported (to `renders/`) before it is saved. +def layout_legends(): + from qgis.core import QgsLayoutItemPage, QgsLayoutItemLegend, QgsLayoutExporter, QgsMarkerSymbol + mm = Qgis.LayoutUnit.Millimeters + p = new_project() + p.relationManager().setPolymorphicRelations([]) + p.setTitle("Legends") + pts, polys, lines = layer("points"), layer("polygons"), layer("lines") + # The points in two classes, as a legend lists them. + cats = [QgsRendererCategory(v, QgsMarkerSymbol.createSimple({"color": c, "size": "3"}), v.upper()) for v, c in (("a", "200,40,40,255"), ("b", "40,40,200,255"))] + pts.setRenderer(QgsCategorizedSymbolRenderer("kind", cats)) + p.addMapLayers([pts, lines, polys]) + lay = QgsPrintLayout(p) + lay.initializeDefaults() + lay.setName("Legends") + lay.pageCollection().page(0).setPageSize("A4", QgsLayoutItemPage.Orientation.Landscape) + m = QgsLayoutItemMap(lay) + lay.addLayoutItem(m) + m.attemptMove(QgsLayoutPoint(10, 10, mm)) + m.attemptResize(QgsLayoutSize(150, 120, mm)) + m.setExtent(QgsRectangle(2696300, 1261200, 2698000, 1262475)) + m.setFrameEnabled(True) + legends = [] + auto = QgsLayoutItemLegend(lay) + lay.addLayoutItem(auto) + auto.setLinkedMap(m) + auto.setTitle("All layers") + auto.attemptMove(QgsLayoutPoint(170, 10, mm)) + legends.append(auto) + own = QgsLayoutItemLegend(lay) + lay.addLayoutItem(own) + own.setLinkedMap(m) + own.setTitle("Own list") + own.setAutoUpdateModel(False) + root = own.model().rootGroup() + root.findLayer(lines.id()).setCustomProperty("legend/title-label", "Paths") + root.removeLayer(polys) + own.setColumnCount(2) + own.attemptMove(QgsLayoutPoint(170, 90, mm)) + legends.append(own) + filt = QgsLayoutItemLegend(lay) + lay.addLayoutItem(filt) + filt.setLinkedMap(m) + filt.setTitle("On the map") + filt.setLegendFilterByMapEnabled(True) + filt.attemptMove(QgsLayoutPoint(10, 140, mm)) + legends.append(filt) + p.layoutManager().addLayout(lay) + os.makedirs(os.path.join(OUT, "renders"), exist_ok=True) + settings = QgsLayoutExporter.ImageExportSettings() + settings.dpi = 96 + QgsLayoutExporter(lay).exportToImage(os.path.join(OUT, "renders", "Legends.png"), settings) + for l in legends: + l.adjustBoxSize() + save_project(p, "layout-legends") + + +attempt("layout legends", layout_legends) attempt("all styles project", all_styles) diff --git a/crates/map/testdata/qgis/generated/qgs/layout-legends.qgs b/crates/map/testdata/qgis/generated/qgs/layout-legends.qgs new file mode 100644 index 0000000000..4797b396ab --- /dev/null +++ b/crates/map/testdata/qgis/generated/qgs/layout-legends.qgs @@ -0,0 +1,2622 @@ + + + + Legends + + + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + + + 0 + 0 + + + + + false + + + + + + + + + + + + + + + + + + + + + points_271b5f60_5fbc_4458_a390_a024315984ce + lines_da39afdf_ecd0_4c4a_b3be_e53fdf870c05 + polygons_03ceded7_21bd_40fc_a004_cce2783d99d8 + + + + + + + + + + + + + Annotations_6808c8ec_b181_4185_8989_4344efce9840 + + Annotations + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + false + + + + + + + 1 + 1 + 1 + 0 + + + + 1 + 0 + + + + + + 2696500 + 1261500 + 2697920 + 1261820 + + + 8.71934207087455881 + 47.49696217296330047 + 8.73825479670044025 + 47.50004982447759971 + + lines_da39afdf_ecd0_4c4a_b3be_e53fdf870c05 + ../data/sample.gpkg|layername=lines + lines + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + + + dataset + + + + + + + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + ogr + + + + + + + + + + 1 + 1 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + generatedlayout + + + + + + + + + + + 2696500 + 1261500 + 2697700 + 1261740 + + + 8.71934207087455881 + 47.49699490745601338 + 8.73531785937520233 + 47.49933040928209493 + + points_271b5f60_5fbc_4458_a390_a024315984ce + ../data/sample.gpkg|layername=points + points + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + + + dataset + + + + + + + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + ogr + + + + + + + + + + 1 + 1 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + generatedlayout + + + + + + + + + + + 2696500 + 1261500 + 2697820 + 1261830 + + + 8.71934207087455881 + 47.49697706140925391 + 8.73692999718656971 + 47.50013975136437949 + + polygons_03ceded7_21bd_40fc_a004_cce2783d99d8 + ../data/sample.gpkg|layername=polygons + polygons + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + + + dataset + + + + + + + + + PROJCRS["CH1903+ / LV95",BASEGEOGCRS["CH1903+",DATUM["CH1903+",ELLIPSOID["Bessel 1841",6377397.155,299.1528128,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4150]],CONVERSION["Swiss Oblique Mercator 1995",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",46.9524055555556,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",7.43958333333333,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth at projection centre",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",90,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor at projection centre",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",2600000,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",1200000,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1]],USAGE[SCOPE["Cadastre, engineering survey, topographic mapping (large and medium scale)."],AREA["Liechtenstein; Switzerland."],BBOX[45.81,5.95,47.81,10.5]],ID["EPSG",2056]] + +proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=2600000 +y_0=1200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs + 47 + 2056 + EPSG:2056 + CH1903+ / LV95 + somerc + EPSG:7004 + false + + + + + ogr + + + + + + + + + + 1 + 1 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + 0 + generatedlayout + + + + + + + + + + + + + + + + + + 0 + 0 + + + 0 + 0 + + + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 0 + 0 + 255 + 255 + 255 + 255 + + + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 0 + 0 + 255 + 255 + 255 + 255 + + + m2 + m2 + meters + meters + HorizontalMiddle + HorizontalMiddle + + + m2 + m2 + meters + meters + HorizontalMiddle + HorizontalMiddle + + + 5 + 5 + 2.5 + 2.5 + false + false + false + false + false + false + 1 + 1 + 0 + 0 + false + false + false + false + true + true + 0 + 0 + 255,0,0,255,rgb:1,0,0,1 + 255,0,0,255,rgb:1,0,0,1 + + + 5 + 5 + 2.5 + 2.5 + false + false + false + false + false + false + 1 + 1 + 0 + 0 + false + false + false + false + true + true + 0 + 0 + 255,0,0,255,rgb:1,0,0,1 + 255,0,0,255,rgb:1,0,0,1 + + + false + false + + + false + false + + + true + true + 2 + 2 + + + true + true + 2 + 2 + + + 1 + 1 + + + 1 + 1 + + + 0 + 0 + + + 0 + 0 + + + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 0 + 0 + 255 + 255 + 255 + 255 + + + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 255 + 0 + 0 + 255 + 255 + 255 + 255 + + + m2 + m2 + meters + meters + HorizontalMiddle + HorizontalMiddle + + + m2 + m2 + meters + meters + HorizontalMiddle + HorizontalMiddle + + + 5 + 5 + 2.5 + 2.5 + false + false + false + false + false + false + 1 + 1 + 0 + 0 + false + false + false + false + true + true + 0 + 0 + 255,0,0,255,rgb:1,0,0,1 + 255,0,0,255,rgb:1,0,0,1 + + + 5 + 5 + 2.5 + 2.5 + false + false + false + false + false + false + 1 + 1 + 0 + 0 + false + false + false + false + true + true + 0 + 0 + 255,0,0,255,rgb:1,0,0,1 + 255,0,0,255,rgb:1,0,0,1 + + + false + false + + + false + false + + + true + true + 2 + 2 + + + true + true + 2 + 2 + + + 1 + 1 + + + 1 + 1 + + + + + + + + + + + + + Legends + + + + + + Unknown + 2026-12-02T08:27:03 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + points_271b5f60_5fbc_4458_a390_a024315984ce + lines_da39afdf_ecd0_4c4a_b3be_e53fdf870c05 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],MEMBER["World Geodetic System 1984 (G2139)"],MEMBER["World Geodetic System 1984 (G2296)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]] + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + EPSG:7030 + true + + + + + + + diff --git a/docs/user-guide/workspace.md b/docs/user-guide/workspace.md index 078df5d9ea..139fe1b873 100644 --- a/docs/user-guide/workspace.md +++ b/docs/user-guide/workspace.md @@ -448,10 +448,16 @@ divisions, text size and unit label, each change noted; its division values chos its box, noted; a numeric scale bar as a text printing `{scale}`, the scale of the layout's first map (noted when it follows another); a north arrow (QGIS's is a picture) as RustGIS's arrow, noted; an overview as an extent indicator in its outline's colour, its fill -noted. One whose map -isn't on its page is left out, noted. Labels' and pictures' backgrounds and frames, a map's -frame, hidden items and locked ones carry over. What a layout can't hold is -noted: legends, tables, HTML and other items, map grids and +noted. A legend lists the project's layers with every class, or, filtered by its map, what the +map draws, or its own list of layers in its order (the project's others left out) under its own +names for them; it takes its rows' text size and colour, its columns and its symbols' size, and +shows `` only where a layer has that category or an ELSE rule. Its groups +(listed flat), its classes' own labels and rows, hidden layers it lists (unless filtered by its +map), one of two layers of a name, a layer kept whole across columns and text styles of its own +are noted; one QGIS hasn't sized yet is given room for a row a layer, and one of a map on another +page shows its page's first map, noted. One on a page without a map is left out, noted. Labels' and pictures' backgrounds and frames, a map's frame, +hidden items and locked ones carry over. What a layout can't hold is noted: tables, HTML and +other items, map grids and the atlas, SVG pictures, scale bars' subdivisions and other styles, groups (their items kept on their own), turned maps, shapes and pictures (drawn upright), stretched or clipped pictures, a polygon's fill, a map's background colour, label styling RustGIS's text lacks (underlines, buffers, shadows), blending, and settings set by