forms: a display unit and decimals for a plain double member (FieldMeta::unit / ::decimals) - #808
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ta::unit / ::decimals)
A DTO whose readings are plain `double`s -- the common shape for an app that
already has its own persistence types -- had no way to tell a renderer
"kg/m³, three decimals". That knowledge lived only in `Quantity`'s type, so a
host rendering such a form got a bare text field with no unit and no entry
precision, and a slot registered for it was handed neither.
`FieldMeta` gains two presentation members, applied by the one
`annotateBasicMemberProperty` implementation and therefore at every nesting
depth:
- `unit` is emitted as the property's `ExtUnits`
(`{"unitAscii": unit, "unitUnicode": unit}`), the key a `Quantity` already
carries. Nothing on the reading side changes: DynamicForm's unit suffix,
`SlotRegistry.byUnit` and a view's `v-columns` entry all read `ExtUnits`
off the property node already.
- `decimals` (`std::optional<math::DecimalPlaces>`) is emitted as the new
`x-displayDecimals`, deliberately **not** `x-decimalPlaces`: the latter
wins over `"type": "number"` and switches the property to the exact
`{num,den,dp}` encoding, which a `double` member cannot decode.
Both are ignored on a `Quantity` member (its unit and declared precision are
part of its type, and a second declaration could only disagree) and a
`decimals` above `kMaxDecimalPlaces` is ignored, as a non-positive
`multipleOf` is. `withUnit()` / `withDecimals()` join the fluent builders.
DynamicForm reads `x-displayDecimals` only for a `"number"` with no
`x-decimalPlaces`. It keeps the JSON-number encoding, refuses an entry with
more fraction digits than declared (the rule a `Quantity` entry already
follows: refused, never rounded), spells the placeholder from it, and puts
`decimals` / `decimalsDeclared` / `displayDecimals` on the field descriptor a
slot receives.
Tests: tests/test_forms_display_unit.cpp (8 cases: emission, omission, the
Quantity exclusion, the kMax guard, a std::vector<Row> element, the builders,
and an untouched wire) and src/qt/forms/tests/tst_DynamicFormDisplayUnit.qml
(11 cases, each asserting the submitted body). Mutation-checked: commenting
out the emission reddens 4 of the 8 C++ cases; disabling the renderer's entry
limit reddens the 2 QML cases that pin it. Full suites on MSVC 14.51 / Qt
6.11.1: morph_tests 1584 cases green, forms_qml_logic 328 green.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- annotateDisplayUnit becomes a template that is a no-op for a Quantity, so
annotateBasicMemberProperty gains a plain call and no cognitive-complexity
increment on a changed line; its operator[] writes sit in the same
NOLINTBEGIN block emitDeclaredBound uses for the glaze DOM.
- FieldMeta::unit / ::decimals keep their {} like every sibling member, with
the redundant-member-init suppression saying why.
- The test's $ref helper returns a copy and takes (dom, name, items), so it
neither returns a reference to a parameter nor takes two swappable DOM
references; schemaJson's const& result is bound by reference.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…an array of x under Clang/GCC
The clang-tidy follow-up rewrote the display-unit test's $ref helper and
spelled one copy as `glz::generic_u64{node["items"]}`. That is
list-initialisation: MSVC picks the copy constructor, Clang and GCC pick the
initializer_list one and build a one-element array, so every lookup below it
threw `std::get: wrong index for variant`. CI reported it on gcc-debug,
clang-tsan, clang-ubsan, Qt6 WebSockets and clangcl-debug; reproduced locally
with clang-cl (4 of 46 assertions failing) and green after this change.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Yaraslaut
force-pushed
the
feature/forms-field-unit-decimals
branch
from
September 25, 2026 06:54
4280aac to
16811b3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A DTO holding lab readings as plain
doubles had no way to tell a renderer "kg/m³, three decimals" — that lived only inQuantity's type — so a host slot rendering the field got neither.FieldMetamemberunit(string_view)ExtUnits{unitAscii, unitUnicode}Quantityalready carries: DynamicForm's suffix label,SlotRegistry.byUnitand view columns read it unchangeddecimals(optional<math::DecimalPlaces>)x-displayDecimalsx-decimalPlaces, which wins over"type":"number"and switches to the{num,den,dp}encoding adoublecannot decodeQuantitymember, and adecimalsabovekMaxDecimalPlacesis ignored. They apply at any nesting depth (oneannotateBasicMemberPropertyimplementation).withUnit()/withDecimals()builders added.Quantity: refused, never rounded), derives the placeholder from it, and addsdecimals/decimalsDeclared/displayDecimalsto the field descriptor slots receive.docs/spec/forms/forms.md— new "Display unit and decimals for a plain member" subsection, emitted-keys and renderer-contract tables, plain-number section.Tests (MSVC 14.51, Qt 6.11.1, Release):
tests/test_forms_display_unit.cpp(8 cases) andsrc/qt/forms/tests/tst_DynamicFormDisplayUnit.qml(11 cases, asserting submitted bodies). Mutation-checked: removing the emission reddens 4 C++ cases; disabling the entry limit reddens the 2 QML cases that pin it. Fullmorph_tests(1584 cases) andforms_qml_logic(328) green.🤖 Generated with Claude Code