Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4836604
feat(qgis): import a QGIS project's print layouts as layouts (#882 pi…
pick2510 Nov 30, 2026
77503f3
fix(qgis): say what a layout import cuts, and keep pages and labels a…
pick2510 Nov 30, 2026
45379e2
fix(qgis): say when an imported map frame's scale is brought within a…
pick2510 Nov 30, 2026
dcb77c0
Merge remote-tracking branch 'upstream/main' into qgis-layouts-a
pick2510 Nov 30, 2026
35b15ca
fix(qgis): fill more_extents after the main merge; count oversized it…
pick2510 Nov 30, 2026
faba60a
fix(map): QGIS layouts: pages by their saved place, own papers, older…
pick2510 Nov 30, 2026
01e59d9
Merge remote-tracking branch 'upstream/main' into qgis-layouts-a
pick2510 Nov 30, 2026
31c3f74
fix(map): QGIS layouts: label sizes past a text's said, numbered name…
pick2510 Nov 30, 2026
02a06cb
fix(map): QGIS layouts: a label's own braces as parentheses; @project…
pick2510 Nov 30, 2026
f64ba38
fix(map): QGIS layouts: pages and written-out titles bounded over the…
pick2510 Nov 30, 2026
c048186
fix(qgis): layout names written out within the import's budget; pictu…
pick2510 Nov 30, 2026
dc2235f
QGIS layouts: charge a layout name for the part a label keeps; inline…
pick2510 Dec 1, 2026
0d88b15
QGIS layouts: an attachment with a login isn't named; a full worker c…
pick2510 Dec 1, 2026
ff2cb57
QGIS layouts: failed picture reads bounded and said; merged closing n…
pick2510 Dec 1, 2026
6f46039
QGIS layouts: items under 0.05 mm said; a failed picture's read charg…
pick2510 Dec 1, 2026
722b4e5
Say labels whose margins leave their text no room
pick2510 Dec 1, 2026
6275aaf
Say margin widening per side; count title labels, not expressions
pick2510 Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
513 changes: 506 additions & 7 deletions crates/engine/src/cmd/qgis.rs

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5516,7 +5516,9 @@ fn qgis_import_codes_only_the_notes_that_lose_data() {
layer("Arcs", "memory", "CompoundCurve?crs=EPSG:4326&field=a:string"),
]
.concat();
let text = format!(r#"<qgis><projectlayers>{layers}</projectlayers><Layouts><Layout name="page"/></Layouts></qgis>"#);
let text = format!(
r#"<qgis><projectlayers>{layers}</projectlayers><Layouts><Layout name="page"><LayoutItem type="65642" position="1,1,mm" size="5,5,mm"/></Layout></Layouts></qgis>"#
);
let mark = s.notice_mark();
let result = s.run("project.importQgis", &json!({"text": text})).unwrap();
let notes = result["notes"].as_array().unwrap();
Expand All @@ -5528,7 +5530,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"), Some(None), "a layout is drawing, not data: no code");
assert_eq!(json_loss("", "print layouts' legends"), 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::<Vec<_>>();
assert!(with(LossCode::DroppedFeature)[0].text.contains("Unsupported"), "{said:?}");
Expand Down Expand Up @@ -44662,6 +44664,7 @@ mod ogc_server;
mod ogc_dataset;

mod qgis_import_ahead;
mod qgis_layouts;
mod qgis_services;

#[path = "../../../tests/support/esripbf.rs"]
Expand Down
4 changes: 3 additions & 1 deletion crates/engine/src/tests/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ pub(super) fn long_commands(boundaries: bool) {
<layer-tree-layer id="Place" checked="Qt::Checked"/><layer-tree-layer id="Table" checked="Qt::Checked"/></layer-tree-group><projectlayers>
<maplayer type="vector"><id>Place</id><datasource>./place.geojson</datasource><layername>Place</layername><provider>ogr</provider></maplayer>
<maplayer type="vector"><id>Table</id><datasource>file:./place.csv?type=csv&amp;xField=x&amp;yField=y</datasource><layername>Table</layername><provider>delimitedtext</provider></maplayer>
</projectlayers></qgis>"#;
</projectlayers>
<Layouts><Layout name="Sheet"><PageCollection><LayoutItem type="65638" position="0,0,mm" size="210,297,mm"/></PageCollection>
<LayoutItem type="65641" labelText="Sheet" position="10,10,mm" size="100,10,mm"/></Layout></Layouts></qgis>"#;
std::fs::write(out("import.qgs"), project).unwrap();
read(&s, "project.importQgis", &json!({"path": out("import.qgs")}));

Expand Down
219 changes: 219 additions & 0 deletions crates/engine/src/tests/qgis_layouts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
//! A QGIS project's print layouts imported as layouts of the project (piece 12a of #882): their
//! map frames showing the map the import makes, where QGIS's map items show it; their pictures
//! read; Undo taking them away with the map; and the same from an import run on a copy.

use super::{Project, Session};
use rustgis_analysis::control::Control;
use rustgis_map::layout::ElementKind;
use serde_json::json;

fn sheets() -> serde_json::Value {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../map/testdata/qgis/generated/qgs/layout-sheets.qgs");
json!({"path": path.display().to_string()})
}

/// The A4 sheet's map frame: the map it shows, its centre and scale.
fn frame(s: &Session, layout: &str) -> (String, rustgis_geom::Coord, f64, f64) {
let l = s.project.layouts.iter().find(|l| l.name == layout).unwrap();
l.elements
.iter()
.find_map(|e| match &e.kind {
ElementKind::MapFrame { map, center, scale, bearing, .. } => Some((map.clone(), *center, *scale, *bearing)),
_ => None,
})
.unwrap()
}

#[test]
fn a_qgis_projects_layouts_come_in_showing_its_map() {
let mut s = Session::new(Project::default());
let layouts = s.project.layouts.len();
let answer = s.run("project.importQgis", &sheets()).unwrap();
assert_eq!(answer["layouts"], json!(["Sheet A4", "Sheet A4 (page 2)", "Sheet Letter"]));
assert_eq!(s.project.layouts.len(), layouts + 3);
// Within a layout's limits as read: nothing brought within them.
let notes = answer["notes"].as_array().unwrap();
assert!(
!notes.iter().any(|n| n["text"].as_str().is_some_and(|t| t.contains("brought within") || t.contains("past what a layout holds"))),
"{notes:?}"
);
let (map, center, scale, bearing) = frame(&s, "Sheet A4");
assert_eq!(map, "Sheets");
// The item shows 1,700 m of LV95 across 200 mm: 1:8,500, centred on its extent's centre.
let back = rustgis_data::raster::crs::Crs::parse("EPSG:2056")
.unwrap()
.transformer()
.unwrap()
.to_lonlat(rustgis_geom::Coord::new(2697150.0, 1261837.5))
.unwrap();
assert!((center.x - back.x).abs() < 1e-6 && (center.y - back.y).abs() < 1e-6, "{center:?} {back:?}");
// 1:8,500 on LV95's grid; the frame shows the same 1,700 m of it across its 200 mm.
let m = s.project.maps.iter().find(|m| m.name == "Sheets").unwrap();
let cam = rustgis_map::layout::frame_camera(m, center, scale, 0.0, 0.0);
let across = cam.res * 200.0 * rustgis_map::layout::PT_PER_MM;
assert!((across - 1700.0).abs() < 1e-3, "{across} ({scale})");
assert!((bearing + 10.0).abs() < 1e-9);
// Its picture read from its file.
let a4 = s.project.layouts.iter().find(|l| l.name == "Sheet A4").unwrap();
let picture = a4.elements.iter().find_map(|e| match &e.kind {
ElementKind::Picture { image, source } => Some((image.clone(), source.clone())),
_ => None,
});
let (image, source) = picture.unwrap();
assert!(!image.is_empty());
assert!(source.is_some_and(|s| s.replace('\\', "/").ends_with("data/picture.png")));
// One Undo step takes the map and its layouts away.
s.run("edit.undo", &json!({})).unwrap();
assert_eq!(s.project.layouts.len(), layouts);
}

/// A layout name the project has already is numbered, as a new layout's is; its frame shows the
/// map the import made.
#[test]
fn an_imported_layout_named_as_one_there_is_numbered() {
let mut s = Session::new(Project::default());
s.run("project.importQgis", &sheets()).unwrap();
let answer = s.run("project.importQgis", &sheets()).unwrap();
assert_eq!(answer["map"], "Sheets2");
assert_eq!(answer["layouts"], json!(["Sheet A4 2", "Sheet A4 (page 2) 2", "Sheet Letter 2"]));
assert_eq!(frame(&s, "Sheet A4 2").0, "Sheets2");
assert_eq!(frame(&s, "Sheet A4").0, "Sheets");
}

/// Run on a copy (the desktop app's way), the layouts land with the map, named as the session
/// has them then, their frames showing the map by its name here.
#[test]
fn an_import_on_a_copy_lands_its_layouts_with_its_map() {
let mut here = Session::new(Project::default());
let inline = here.run("project.importQgis", &sheets()).unwrap();
let mut s = Session::new(Project::default());
let read = crate::cmd::reads::read_ahead(&mut s, "project.importQgis", &sheets()).unwrap();
assert!(read.reads());
let done = read.run(&Control::new()).unwrap();
let answer = crate::cmd::reads::read_land(&mut s, done).unwrap();
assert_eq!(answer, inline);
assert!(s.project.layouts == here.project.layouts);
// Meanwhile, a map took its name and a layout one of its layouts' names.
let mut s = Session::new(Project::default());
let read = crate::cmd::reads::read_ahead(&mut s, "project.importQgis", &sheets()).unwrap();
let done = read.run(&Control::new()).unwrap();
s.map_mut().name = "Sheets".into();
s.project.layouts.push(rustgis_map::layout::Layout::new("Sheet Letter", 210.0, 297.0));
let answer = crate::cmd::reads::read_land(&mut s, done).unwrap();
assert_eq!(answer["map"], "Sheets2");
assert_eq!(answer["layouts"], json!(["Sheet A4", "Sheet A4 (page 2)", "Sheet Letter 2"]));
assert_eq!(frame(&s, "Sheet A4").0, "Sheets2");
s.run("edit.undo", &json!({})).unwrap();
assert_eq!(s.project.layouts.len(), 1);
}

/// A layout that had a QGIS layout's name when the copy started, renamed to that name numbered by
/// the time it lands, leaves the name free: the QGIS layout takes it, numbered from its own name.
#[test]
fn an_import_on_a_copy_numbers_from_the_qgis_names() {
let mut s = Session::new(Project::default());
s.project.layouts.push(rustgis_map::layout::Layout::new("Sheet A4", 210.0, 297.0));
let read = crate::cmd::reads::read_ahead(&mut s, "project.importQgis", &sheets()).unwrap();
let done = read.run(&Control::new()).unwrap();
if let Some(l) = s.project.layouts.iter_mut().find(|l| l.name == "Sheet A4") {
l.name = "Sheet A4 2".into();
}
let answer = crate::cmd::reads::read_land(&mut s, done).unwrap();
assert_eq!(answer["layouts"], json!(["Sheet A4", "Sheet A4 (page 2)", "Sheet Letter"]));
}

/// A project that holds as many layouts as it can by the time the copy's import lands takes none
/// of its layouts, says so, and answers none.
#[test]
fn an_import_landing_on_a_full_project_answers_no_layouts() {
let mut s = Session::new(Project::default());
let read = crate::cmd::reads::read_ahead(&mut s, "project.importQgis", &sheets()).unwrap();
let done = read.run(&Control::new()).unwrap();
while s.project.layouts.len() < crate::project::MAX_LAYOUTS {
let n = s.project.layouts.len();
s.project.layouts.push(rustgis_map::layout::Layout::new(format!("L{n}"), 210.0, 297.0));
}
let mark = s.notice_mark();
let answer = crate::cmd::reads::read_land(&mut s, done).unwrap();
assert!(answer.get("layouts").is_none(), "{answer}");
assert_eq!(s.project.layouts.len(), crate::project::MAX_LAYOUTS);
assert!(s.notices_since(mark).iter().any(|n| n.text.contains("3 of the QGIS project's print layouts left out")));
// In the answer's notes too.
let notes = answer["notes"].as_array().unwrap();
assert!(
notes.iter().any(|n| n["text"].as_str().is_some_and(|t| t.contains("print layouts past the 200 a project holds (3)"))),
"{notes:?}"
);
}

/// What a layout keeps changes an imported one (a page smaller than 20 mm): said.
#[test]
fn an_imported_layout_brought_within_limits_is_said() {
let text = r#"<qgis><title>T</title><Layouts><Layout name="Tiny"><PageCollection><LayoutItem type="65638" position="0,0,mm" size="10,10,mm"/></PageCollection></Layout></Layouts></qgis>"#;
let mut s = Session::new(Project::default());
let answer = s.run("project.importQgis", &json!({"text": text})).unwrap();
let l = s.project.layouts.iter().find(|l| l.name == "Tiny").unwrap();
assert!((l.width - 20.0).abs() < 1e-9);
let notes = answer["notes"].as_array().unwrap();
assert!(
notes.iter().any(|n| n["text"].as_str().is_some_and(|t| t.contains("pages or papers brought within what a layout takes"))),
"{notes:?}"
);
}

/// A map item showing more or less than a frame's scales reach is shown at the nearest, said.
#[test]
fn a_map_item_past_a_frames_scales_is_said() {
let text = r#"<qgis><title>T</title><projectCrs><spatialrefsys><authid>EPSG:2056</authid></spatialrefsys></projectCrs>
<Layouts><Layout name="Close"><PageCollection><LayoutItem type="65638" position="0,0,mm" size="210,297,mm"/></PageCollection>
<LayoutItem type="65639" position="10,10,mm" size="100,100,mm"><Extent xmin="2600000" ymin="1200000" xmax="2600000.00001" ymax="1200000.00001"/></LayoutItem>
</Layout></Layouts></qgis>"#;
let mut s = Session::new(Project::default());
let answer = s.run("project.importQgis", &json!({"text": text})).unwrap();
assert!((frame(&s, "Close").2 - rustgis_map::layout::MIN_FRAME_SCALE).abs() < 1e-12);
let notes = answer["notes"].as_array().unwrap();
assert!(
notes.iter().any(|n| n["text"]
.as_str()
.is_some_and(|t| t.contains("map items whose scale was brought within a frame's range") && t.ends_with("(1)"))),
"{notes:?}"
);
}

/// A layout whose name is as long as a name goes, imported where it is taken, is numbered with
/// its page's number kept whole and the cut said, inline and from a copy.
#[test]
fn a_long_layout_name_numbered_keeps_its_page_and_says_the_cut() {
let long = "N".repeat(200);
let text = format!(
r#"<qgis><title>T</title><Layouts><Layout name="{long}"><PageCollection><LayoutItem type="65638" position="0,0,mm" size="210,297,mm"/><LayoutItem type="65638" position="0,307,mm" size="210,297,mm"/></PageCollection></Layout></Layouts></qgis>"#
);
let mut s = Session::new(Project::default());
s.run("project.importQgis", &json!({"text": text})).unwrap();
let answer = s.run("project.importQgis", &json!({"text": text})).unwrap();
let names: Vec<String> = serde_json::from_value(answer["layouts"].clone()).unwrap();
assert!(names[0].ends_with("N 2") && names[0].chars().count() == 200, "{names:?}");
assert!(names[1].ends_with("N (page 2) 2") && names[1].chars().count() == 200, "{names:?}");
let said = |answer: &serde_json::Value| {
answer["notes"]
.as_array()
.unwrap()
.iter()
.any(|n| n["text"].as_str().is_some_and(|t| t.contains("names cut to fit the number") && t.ends_with("(2)")))
};
assert!(said(&answer), "{answer}");
// From a copy: numbered where it lands, said there.
let read = crate::cmd::reads::read_ahead(&mut s, "project.importQgis", &json!({"text": text})).unwrap();
let done = read.run(&Control::new()).unwrap();
let mark = s.notice_mark();
let answer = crate::cmd::reads::read_land(&mut s, done).unwrap();
let names: Vec<String> = serde_json::from_value(answer["layouts"].clone()).unwrap();
assert!(names[1].ends_with("N (page 2) 3"), "{names:?}");
assert!(said(&answer), "{answer}");
assert!(s.notices_since(mark).iter().any(|n| n.text.contains("2 of the QGIS project's print layout names cut")));
// A name with room for its number isn't said.
let mut s = Session::new(Project::default());
s.run("project.importQgis", &sheets()).unwrap();
let answer = s.run("project.importQgis", &sheets()).unwrap();
assert!(!said(&answer), "{answer}");
}
4 changes: 2 additions & 2 deletions crates/map/src/qgis/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,13 @@ fn text_graphic(item: Node, geometry: Geometry, align: TextAlign, layer: &str, r

/// A font family that only names a kind of font (QGIS's default "Sans Serif"): RustGIS's is one
/// too.
fn generic(family: &str) -> bool {
pub(super) fn generic(family: &str) -> bool {
matches!(family.to_ascii_lowercase().as_str(), "sans serif" | "sans-serif" | "sans" | "ms shell dlg 2")
}

/// HTML's text without its tags, `<br>` and the ends of paragraphs as line breaks, and the common
/// entities read.
fn plain(html: &str) -> String {
pub(super) fn plain(html: &str) -> String {
// What HTML draws of `html`, as lines: tags dropped (and what's in a head, style, script or
// title), a `<` that opens no tag kept, runs of white space one space as HTML draws them,
// a line broken at `<br>` and between blocks, entities read.
Expand Down
Loading
Loading