Skip to content

forms: a display unit and decimals for a plain double member (FieldMeta::unit / ::decimals) - #808

Merged
Yaraslaut merged 4 commits into
masterfrom
feature/forms-field-unit-decimals
Sep 25, 2026
Merged

Yaraslaut merged 4 commits into
masterfrom
feature/forms-field-unit-decimals

Conversation

@Yaraslaut

Copy link
Copy Markdown
Member

A DTO holding lab readings as plain doubles had no way to tell a renderer "kg/m³, three decimals" — that lived only in Quantity's type — so a host slot rendering the field got neither.

FieldMeta member Emitted as Why this key
unit (string_view) property-level ExtUnits {unitAscii, unitUnicode} the key a Quantity already carries: DynamicForm's suffix label, SlotRegistry.byUnit and view columns read it unchanged
decimals (optional<math::DecimalPlaces>) new x-displayDecimals not x-decimalPlaces, which wins over "type":"number" and switches to the {num,den,dp} encoding a double cannot decode
  • Both are ignored on a Quantity member, and a decimals above kMaxDecimalPlaces is ignored. They apply at any nesting depth (one annotateBasicMemberProperty implementation). withUnit() / withDecimals() builders added.
  • DynamicForm keeps the JSON-number encoding, refuses an entry with more fraction digits than declared (same rule as a Quantity: refused, never rounded), derives the placeholder from it, and adds decimals / decimalsDeclared / displayDecimals to the field descriptor slots receive.
  • Spec: 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) and src/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. Full morph_tests (1584 cases) and forms_qml_logic (328) green.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
include/morph/forms/forms.hpp 55.55% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

Yaraslaut and others added 3 commits September 25, 2026 08:19
…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
Yaraslaut force-pushed the feature/forms-field-unit-decimals branch from 4280aac to 16811b3 Compare September 25, 2026 06:54
@Yaraslaut
Yaraslaut merged commit 48f6892 into master Sep 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant