Skip to main content

Module data_change

Module data_change 

Source
Expand description

DataChange — change notifications for flat collections.

Describes the mutations that crate::ListModel (and crate::ListDataSource implementors) emit to their subscribers. Consumers such as ListView, TableView, and SortFilterListModel receive a DataChange through their observer and update their internal state (measured row heights, selection indices, sort projections) incrementally rather than rebuilding from scratch.

Most variants carry index ranges so that observers can perform O(affected) work. Reset is the fallback when the change cannot be expressed incrementally; consumers must discard all cached state and re-query the source.

Also provided: map_index_after_move, a pure function that maps a single index through an ItemsMoved operation — used by crate::CheckedModel and crate::SelectionModel to keep index-based state in sync after reorders.

// An insertion at row 2 shifts index 5 to 6.
let change = DataChange::ItemsInserted { range: 2..3 };
// map_index_after_move: move row 0 to position 2 (post-removal index).
let new_idx = map_index_after_move(0, 0, 2, 1);
assert_eq!(new_idx, 2);

Enums§

DataChange
Describes a mutation to a flat list. Emitted by crate::ListModel automatically and by crate::ListDataSource implementors manually.

Functions§

adjust_single_index_for_change
Map a single index anchor (not a selection set) through a DataChange, or None if the row the anchor pointed at no longer exists (it was removed, or the whole list was reset).
map_index_after_move
Map an index through a DataChange::ItemsMoved { from, to, count }.