pub struct PropertyModel { /* private fields */ }Expand description
Hierarchical typed property model (capability groups P1, P2, P4, P5).
Construction is additive (add_category / add_property /
insert_property), removal is by subtree, and every mutation validates
value/editor compatibility. Default expansion is expanded; collapse any
node with set_expanded(id, false). Value edits take either the
programmatic path (set_value) or the vetoable user path
(request_change → commit_change/denial); every transition is recorded
in the ordered PropertyModel::events log.
Equality compares durable state (arena, roots, id counter, collapse set, selection); the transient event log and any pending change are excluded.
Implementations§
Source§impl PropertyModel
impl PropertyModel
Sourcepub fn roots(&self) -> &[PropertyId]
pub fn roots(&self) -> &[PropertyId]
Root ids in insertion order.
Sourcepub fn get(&self, id: PropertyId) -> Option<&PropertyNode>
pub fn get(&self, id: PropertyId) -> Option<&PropertyNode>
Looks a node up by id.
Sourcepub fn value(&self, id: PropertyId) -> Option<&PropertyValue>
pub fn value(&self, id: PropertyId) -> Option<&PropertyValue>
The value of a property node, when present.
Sourcepub fn add_category(
&mut self,
parent: Option<PropertyId>,
label: impl Into<String>,
) -> PropertyResult<PropertyId>
pub fn add_category( &mut self, parent: Option<PropertyId>, label: impl Into<String>, ) -> PropertyResult<PropertyId>
Adds a category group row under parent (or at the root).
Sourcepub fn add_property(
&mut self,
parent: Option<PropertyId>,
label: impl Into<String>,
editor: PropertyEditor,
value: PropertyValue,
) -> PropertyResult<PropertyId>
pub fn add_property( &mut self, parent: Option<PropertyId>, label: impl Into<String>, editor: PropertyEditor, value: PropertyValue, ) -> PropertyResult<PropertyId>
Adds an editable property under parent (or at the root).
Rejects incompatible value/editor pairs and invalid values.
Sourcepub fn insert_property(
&mut self,
parent: Option<PropertyId>,
index: usize,
label: impl Into<String>,
editor: PropertyEditor,
value: PropertyValue,
) -> PropertyResult<PropertyId>
pub fn insert_property( &mut self, parent: Option<PropertyId>, index: usize, label: impl Into<String>, editor: PropertyEditor, value: PropertyValue, ) -> PropertyResult<PropertyId>
Inserts an editable property at index among the siblings of
parent (or among the roots).
Appends when index equals the sibling count; larger indices are the
typed InvalidIndex. Rejects incompatible value/editor pairs and
invalid values without mutating the model.
Sourcepub fn clear(&mut self) -> usize
pub fn clear(&mut self) -> usize
Drops every node, resolving dependent state first: a staged change is withdrawn, a selection is cleared, and the collapse set resets.
next_id never rewinds, so cleared ids are never reused. Returns how
many nodes were removed; Cleared is emitted only for a non-empty
model.
Sourcepub fn selected(&self) -> Option<PropertyId>
pub fn selected(&self) -> Option<PropertyId>
The model’s single selection, when one is set.
Sourcepub fn set_selected(&mut self, id: Option<PropertyId>) -> PropertyResult<()>
pub fn set_selected(&mut self, id: Option<PropertyId>) -> PropertyResult<()>
Moves the selection; None clears it.
Unknown ids are UnknownNode and hidden nodes — or nodes under a
hidden ancestor — are Hidden; an unchanged selection emits nothing.
Sourcepub fn activate(&mut self, id: PropertyId) -> PropertyResult<()>
pub fn activate(&mut self, id: PropertyId) -> PropertyResult<()>
Fires the programmatic activation signal (double-click / Enter on the
chosen row). Hidden nodes — or nodes under a hidden ancestor — are
Hidden, disabled nodes Disabled, unknown ids UnknownNode.
Sourcepub fn is_enabled(&self, id: PropertyId) -> bool
pub fn is_enabled(&self, id: PropertyId) -> bool
Whether the node accepts user edits (unknown ids read as enabled).
Sourcepub fn set_enabled(
&mut self,
id: PropertyId,
enabled: bool,
) -> PropertyResult<()>
pub fn set_enabled( &mut self, id: PropertyId, enabled: bool, ) -> PropertyResult<()>
Enables or disables user edits on a node. Disabling resolves a
staged change on that node as Withdrawn.
Whether the node is hidden from projections (unknown ids read as visible).
Hides or reveals a node and its subtree. Hiding clears a selection
inside the subtree and resolves a staged change there as Withdrawn.
Sourcepub fn is_read_only(&self, id: PropertyId) -> bool
pub fn is_read_only(&self, id: PropertyId) -> bool
Whether both edit paths reject value changes (unknown ids read as editable).
Sourcepub fn set_read_only(
&mut self,
id: PropertyId,
read_only: bool,
) -> PropertyResult<()>
pub fn set_read_only( &mut self, id: PropertyId, read_only: bool, ) -> PropertyResult<()>
Marks a node read-only (or editable again). Marking read-only
resolves a staged change on that node as Withdrawn. Read-only is
editability state, so setting the flag itself is never blocked.
Sourcepub fn ensure_visible(&mut self, id: PropertyId) -> PropertyResult<()>
pub fn ensure_visible(&mut self, id: PropertyId) -> PropertyResult<()>
Expands every ancestor of id (root-most first) so its row can
appear in a projection.
Emits one ExpansionChanged per ancestor that actually expands. A
node hidden itself — or under a hidden ancestor — is the typed
Hidden error, which names the hidden node.
Sourcepub fn validation(&self, id: PropertyId) -> Option<&str>
pub fn validation(&self, id: PropertyId) -> Option<&str>
The application-facing validation message for a node, when set.
Sourcepub fn set_validation(
&mut self,
id: PropertyId,
message: Option<String>,
) -> PropertyResult<()>
pub fn set_validation( &mut self, id: PropertyId, message: Option<String>, ) -> PropertyResult<()>
Sets or clears (None) the validation message of a node.
Emits ValidationChanged only when the message actually changes; an
unchanged message emits nothing.
Sourcepub fn is_modified(&self, id: PropertyId) -> bool
pub fn is_modified(&self, id: PropertyId) -> bool
Whether the node carries unsaved changes (unknown ids read as unmodified).
Sourcepub fn modified_count(&self) -> usize
pub fn modified_count(&self) -> usize
How many nodes carry unsaved changes.
Sourcepub fn clear_modified(&mut self, id: PropertyId) -> PropertyResult<()>
pub fn clear_modified(&mut self, id: PropertyId) -> PropertyResult<()>
Clears the dirty marker of one node.
Sourcepub fn clear_all_modified(&mut self) -> usize
pub fn clear_all_modified(&mut self) -> usize
Clears every dirty marker and reports how many were set.
Sourcepub fn request_change(
&mut self,
id: PropertyId,
proposed: PropertyValue,
) -> PropertyResult<ChangeToken>
pub fn request_change( &mut self, id: PropertyId, proposed: PropertyValue, ) -> PropertyResult<ChangeToken>
Stages a user edit and returns its one-shot ChangeToken.
Applies the user-path gates (hidden — the node itself or an ancestor,
then disabled, then read-only), the category guard, and the
compatibility/value invariants; a rejection mutates nothing and emits
nothing. On success the proposal is staged, Changing is emitted, and
exactly one decision must follow. A request staged while another is
pending resolves the first as Superseded.
Sourcepub fn pending_change(&self) -> Option<&PendingChange>
pub fn pending_change(&self) -> Option<&PendingChange>
The staged change, when one awaits a decision.
Sourcepub fn commit_change(&mut self, token: ChangeToken) -> PropertyResult<()>
pub fn commit_change(&mut self, token: ChangeToken) -> PropertyResult<()>
Applies a staged change (the Changing → Changed path).
A commit whose value already equals the stored value emits nothing;
replaying a decided or unknown token is StaleChange.
Sourcepub fn deny_change(&mut self, token: ChangeToken) -> PropertyResult<()>
pub fn deny_change(&mut self, token: ChangeToken) -> PropertyResult<()>
Vetoes a staged change; the stored value is untouched.
Sourcepub fn timeout_change(&mut self, token: ChangeToken) -> PropertyResult<()>
pub fn timeout_change(&mut self, token: ChangeToken) -> PropertyResult<()>
Resolves a staged change as timed out (default deny).
Sourcepub fn resolve_change(&mut self, token: ChangeToken) -> PropertyResult<()>
pub fn resolve_change(&mut self, token: ChangeToken) -> PropertyResult<()>
Resolves a staged change with no explicit answer (default deny).
Sourcepub fn events(&self) -> &[PropertyEvent]
pub fn events(&self) -> &[PropertyEvent]
The ordered event log (oldest first).
Sourcepub fn drain_events(&mut self) -> Vec<PropertyEvent>
pub fn drain_events(&mut self) -> Vec<PropertyEvent>
Takes every recorded event, leaving the log empty.
Sourcepub fn clear_events(&mut self)
pub fn clear_events(&mut self)
Discards the recorded events without returning them.
Sourcepub fn set_value(
&mut self,
id: PropertyId,
value: PropertyValue,
) -> PropertyResult<()>
pub fn set_value( &mut self, id: PropertyId, value: PropertyValue, ) -> PropertyResult<()>
Replaces the value of a property node — the documented programmatic edit path.
Applies immediately and is blocked only by read_only (typed
ReadOnly); categories, unknown ids, incompatible editors, and
invalid values are rejected without mutation. Exactly one Changed
event is emitted per real value change and the node is marked
modified; a no-op set emits nothing and marks nothing.
Sourcepub fn remove(&mut self, id: PropertyId) -> PropertyResult<()>
pub fn remove(&mut self, id: PropertyId) -> PropertyResult<()>
Removes a node and its whole subtree.
Dependent state resolves before the structural event: a staged change
under the subtree is Withdrawn, a selection inside it is cleared
(SelectionChanged), and one Removed event then lists every removed
id, root first.
Sourcepub fn is_expanded(&self, id: PropertyId) -> bool
pub fn is_expanded(&self, id: PropertyId) -> bool
Whether the node’s children are currently shown (default: shown).
Sourcepub fn set_expanded(
&mut self,
id: PropertyId,
expanded: bool,
) -> PropertyResult<()>
pub fn set_expanded( &mut self, id: PropertyId, expanded: bool, ) -> PropertyResult<()>
Sets the expansion state of a node.
Emits ExpansionChanged only when the state actually changes.
Sourcepub fn rows(&self, mode: ProjectionMode) -> Vec<PropertyRow<'_>>
pub fn rows(&self, mode: ProjectionMode) -> Vec<PropertyRow<'_>>
Projects the tree into display rows in document order.
Hidden nodes and their subtrees are omitted in both modes; collapsed
subtrees are skipped; CategoryFree omits category rows and surfaces
their children at the category’s depth.
Sourcepub fn validate(&self) -> PropertyResult<()>
pub fn validate(&self) -> PropertyResult<()>
Verifies every structural and value invariant.
This is the deserialization contract: duplicate ids, dangling parents, inconsistent child lists, unreachable nodes, cycles, category values, and invalid value/editor pairs are all rejected.