mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-02 08:24:14 +02:00
84add7b3ef
A property value that is entirely whitespace -- reported in #973 as a workaround (setting a title-block custom variable to a single space, the only way to give it a value other than blank before that bug was fixed in #989) -- did not survive a save/reload cycle. Two independent causes, both needed for the round trip to actually work: 1. DiagramContext::toXml() called .trimmed() on every stored value before writing it, unconditionally. For ordinary content this only strips accidental leading/trailing whitespace, but for a value that IS whitespace it collapses the entire thing to "", indistinguishable from a value that was never set. 2. QDomDocument::setContent(), used to parse the project file, discards a text node that is entirely whitespace by default. Confirmed in isolation, outside any QET code: parsing "<a> </a>" with the default ParseOptions gives QDomElement::text() == ""; adding ParseOption::PreserveSpacingOnlyNodes gives " ". So even once (1) stops destroying the value on save, the very next load throws it away again. Fix (1) only trims when the trimmed result isn't empty, i.e. leaves an all-whitespace value untouched. Fix (2) adds PreserveSpacingOnlyNodes to the one setContent() call that parses a project file (QETProject::readProjectXml()) -- not the other ~19 call sites in the codebase (clipboard paste, element/macro loading, translations, autonum context), which read different, narrower documents and are not implicated in this report. Blast radius of (2): every place that walks a QDomNode's children already filters on isElement() (see QET::findInDomElement()), so the extra whitespace-only text-node siblings this keeps around are inert wherever current code already expected only elements. The one place it isn't inert is exactly the bug -- calling .text() on an element whose entire content is whitespace. Verified end-to-end, not just at one stage: a single-space title-block variable now survives two successive --resave cycles unchanged (confirmed byte-for-byte in the saved XML), and renders as blank space rather than literal placeholder text or a vanished value. Re-saved all 24 shipped examples with and without this change and diffed: 23 byte-identical, the one that differs (schema_indus.qet) differs only in element uuids -- and resaving it twice with the SAME unpatched binary produces that same kind of diff, confirming it is pre-existing non-determinism in files that predate persisted uuids, unrelated to this change. Qt 6.10.2, ctest 11/11. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>