|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
The reactive state of one field: its draft and everything derived from it. More...
#include <form_session.hpp>
Public Member Functions | |
| FieldState (detail::engine::SessionCore &core, FieldSpec const &spec, std::string path, std::vector< std::unique_ptr< FieldState > > const *siblings, FieldState const *parent) | |
| FieldState (FieldState const &)=delete | |
| FieldState & | operator= (FieldState const &)=delete |
| FieldState (FieldState &&)=delete | |
| FieldState & | operator= (FieldState &&)=delete |
| FieldSpec const & | spec () const noexcept |
| The field's spec. | |
| std::string const & | path () const noexcept |
| The instance path. | |
| std::string const & | label () const noexcept |
| The label: the explicit key's translation, else the derived key's (top level only), else the schema's title. | |
| std::string const & | help () const noexcept |
| The help text, resolved like the label. | |
| std::string const & | placeholder () const noexcept |
| The placeholder: x-placeholder resolved like the label, else defaultPlaceholder. | |
| reactive::Signal< std::string > & | text () noexcept |
| The draft: what the control holds. Setting it is a user edit. | |
| std::string const & | draft () const |
| The draft, read-only. Tracked. | |
| reactive::Signal< std::size_t > & | unit () noexcept |
| A Decimal's or Quantity's entry unit, an index into spec().units. | |
| reactive::Signal< bool > & | engaged () noexcept |
| Whether a blank-capable field was filled once (an x-blankAs: empty text, or a collection that had rows). | |
| reactive::Computed< Encoding > const & | encoded () const noexcept |
| The draft's encoding. Tracked. | |
| reactive::Computed< std::optional< FieldError > > const & | error () const noexcept |
| Why the draft does not encode, if it does not. Tracked. | |
| reactive::Computed< bool > const & | visible () const noexcept |
| Whether the field is shown: not x-hidden, and no visibleWhen naming it is False. | |
| reactive::Computed< bool > const & | readonly () const noexcept |
| Whether the field is frozen: x-readonly, a frozen parent, or a readonlyWhen naming it that is True. | |
| reactive::Computed< bool > const & | required () const noexcept |
| Whether the field must be filled: required, or a requiredWhen naming it that is True. | |
| bool | blank () const |
| Whether nothing is entered: a blank draft, an Object whose members are all blank, a collection with no rows that was never engaged. Tracked. | |
| RuleOperand | ruleOperand () const |
| What a rule sees of this field. Tracked. | |
| std::vector< ChoiceOption > const & | options () const |
| The selectable options: an Enum's from the schema, a Choice's as last fetched for its current parents. Tracked. | |
| void | retryOptions () |
| Fetches a Choice's options again when the last fetch failed; does nothing otherwise. What opening its select runs, so options that could not be fetched when the form was built are fetched once the user asks for them. | |
| bool | optionsPending () const |
| Whether a Choice's options request is in flight. Tracked. | |
| void | switchUnit (std::size_t index) |
| Switches a Quantity's entry unit, converting the draft exactly (half away from zero to the new unit's decimals). A user action. | |
| std::span< std::unique_ptr< FieldState > const > | members () const noexcept |
| An Object's members, in x-order. | |
| FieldState * | member (std::string_view name) const noexcept |
| An Object's member by wire name. | |
| std::vector< std::shared_ptr< RowState > > const & | rows () const |
| A collection's rows, in order. Tracked. | |
| std::uint64_t | addRow () |
| Appends a blank row to a collection and engages it. A user action. | |
| void | removeRow (std::uint64_t key) |
| Removes a collection row by key. A user action. A holder of the row's shared_ptr (a mounted view) keeps its state alive until it lets go. | |
| std::string | snapshot () const |
| What the field holds, as one string: two snapshots are equal exactly when the field holds the same entry (draft, unit and engagement, and every member's and row's). Untracked. | |
| std::expected< void, std::string > | edit (detail::engine::Json const &value) |
| Replaces the draft with a wire value as the user's own edit, in one batch: a load the session does not mark programmatic, so the field counts as changed and is validated as an edit is. | |
| void | load (detail::engine::Json const *value) |
| Replaces the draft with the decoded wire value; null or absent is blank. Does not mark the change programmatic — the caller does, in the same batch. | |
| void | clear () |
| Blanks the draft, the unit, the engagement, the members and the rows. | |
| void | start () |
| Starts what needs every sibling to exist: an x-blankAs field's engagement, a Choice's options query, and every member's own. Called once, after the owner built all its fields. | |
The reactive state of one field: its draft and everything derived from it.
Definition at line 188 of file form_session.hpp.
|
inline |
| core | The session core. Borrowed: it must outlive the field. |
| spec | The field's spec. Borrowed from the core's model (or a parent's children). |
| path | The instance path (name, parent.member, rows#key.member). |
| siblings | The fields x-optionsDependsOn names are looked up among. Borrowed. |
| parent | The containing Object or ObjectArray field, or null at the top level. |
Definition at line 196 of file form_session.hpp.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
The instance path.
Definition at line 261 of file form_session.hpp.
|
inlinenodiscardnoexcept |
The label: the explicit key's translation, else the derived key's (top level only), else the schema's title.
Definition at line 266 of file form_session.hpp.
|
inlinenodiscardnoexcept |
The help text, resolved like the label.
Definition at line 270 of file form_session.hpp.
|
inlinenodiscardnoexcept |
The placeholder: x-placeholder resolved like the label, else defaultPlaceholder.
Definition at line 274 of file form_session.hpp.
|
inlinenodiscardnoexcept |
The draft: what the control holds. Setting it is a user edit.
Definition at line 278 of file form_session.hpp.
|
inlinenodiscard |
The draft, read-only. Tracked.
Definition at line 282 of file form_session.hpp.
|
inlinenodiscardnoexcept |
A Decimal's or Quantity's entry unit, an index into spec().units.
Definition at line 286 of file form_session.hpp.
|
inlinenodiscardnoexcept |
Whether a blank-capable field was filled once (an x-blankAs: empty text, or a collection that had rows).
Definition at line 291 of file form_session.hpp.
|
inlinenodiscardnoexcept |
The draft's encoding. Tracked.
Definition at line 295 of file form_session.hpp.
|
inlinenodiscardnoexcept |
Why the draft does not encode, if it does not. Tracked.
Definition at line 299 of file form_session.hpp.
|
inlinenodiscardnoexcept |
Whether the field is shown: not x-hidden, and no visibleWhen naming it is False.
Definition at line 303 of file form_session.hpp.
|
inlinenodiscardnoexcept |
Whether the field is frozen: x-readonly, a frozen parent, or a readonlyWhen naming it that is True.
Definition at line 308 of file form_session.hpp.
|
inlinenodiscardnoexcept |
Whether the field must be filled: required, or a requiredWhen naming it that is True.
Definition at line 312 of file form_session.hpp.
|
inlinenodiscard |
Whether nothing is entered: a blank draft, an Object whose members are all blank, a collection with no rows that was never engaged. Tracked.
Definition at line 318 of file form_session.hpp.
|
inlinenodiscard |
What a rule sees of this field. Tracked.
Definition at line 337 of file form_session.hpp.
|
inlinenodiscard |
The selectable options: an Enum's from the schema, a Choice's as last fetched for its current parents. Tracked.
Definition at line 351 of file form_session.hpp.
|
inline |
Fetches a Choice's options again when the last fetch failed; does nothing otherwise. What opening its select runs, so options that could not be fetched when the form was built are fetched once the user asks for them.
Definition at line 361 of file form_session.hpp.
|
inlinenodiscard |
Whether a Choice's options request is in flight. Tracked.
Definition at line 369 of file form_session.hpp.
|
inline |
Switches a Quantity's entry unit, converting the draft exactly (half away from zero to the new unit's decimals). A user action.
| index | The new unit, an index into spec().units. |
Definition at line 374 of file form_session.hpp.
|
inlinenodiscardnoexcept |
An Object's members, in x-order.
Definition at line 391 of file form_session.hpp.
|
inlinenodiscardnoexcept |
An Object's member by wire name.
| name | The wire name. |
Definition at line 396 of file form_session.hpp.
|
inlinenodiscard |
A collection's rows, in order. Tracked.
Definition at line 404 of file form_session.hpp.
|
inline |
Appends a blank row to a collection and engages it. A user action.
Definition at line 408 of file form_session.hpp.
|
inline |
Removes a collection row by key. A user action. A holder of the row's shared_ptr (a mounted view) keeps its state alive until it lets go.
| key | The row's key. |
Definition at line 425 of file form_session.hpp.
|
inlinenodiscard |
What the field holds, as one string: two snapshots are equal exactly when the field holds the same entry (draft, unit and engagement, and every member's and row's). Untracked.
Definition at line 432 of file form_session.hpp.
|
inline |
Replaces the draft with a wire value as the user's own edit, in one batch: a load the session does not mark programmatic, so the field counts as changed and is validated as an edit is.
| value | The wire value; null is blank. |
Definition at line 443 of file form_session.hpp.
|
inline |
Replaces the draft with the decoded wire value; null or absent is blank. Does not mark the change programmatic — the caller does, in the same batch.
| value | The wire value, or null. |
Definition at line 461 of file form_session.hpp.
|
inline |
Blanks the draft, the unit, the engagement, the members and the rows.
Definition at line 505 of file form_session.hpp.
|
inline |
Starts what needs every sibling to exist: an x-blankAs field's engagement, a Choice's options query, and every member's own. Called once, after the owner built all its fields.
Definition at line 519 of file form_session.hpp.