Skip to main content

LiveModel

Struct LiveModel 

Source
pub struct LiveModel { /* private fields */ }
Expand description

A densa_data::LiveTable as the model of a grid widget (densa_widgets::DataGrid): one view of the table, sorted when the user clicks a column title and filtered by the app, with rows keyed by their record so a selection follows its row as the data changes.

Change the table through table_mut; the view follows each change incrementally. Cells are formatted as in ArrowTable, from formatters brought up to date by GridModel::prepare, which the grid calls before it paints; until then, rows from batches added since show empty cells rather than stale values. Columns are sized from the first rows to arrive and widened when later numbers no longer fit, and the grid takes in new sizes by itself (GridModel::columns_revision), keeping widths the user dragged.

Costs: a frame without changes allocates nothing; one after upserts allocates a formatter per new batch, and after a compaction rebuilds them all. Sorting or filtering builds a new view, O(n log n) in the table’s rows.

Implementations§

Source§

impl LiveModel

Source

pub fn new(table: LiveTable) -> Result<Self, DataError>

A model showing every row of table, unsorted (in row-id order: the order keys arrived, until deleted keys’ places are reused).

§Errors

Those of LiveTable::add_view; none for a view of every row, unsorted.

Source

pub fn table(&self) -> &LiveTable

The table.

Source

pub fn table_mut(&mut self) -> &mut LiveTable

The table, to upsert, delete or compact; the view follows. Another table put in its place is shown from the next paint, filtered and sorted the same way where its columns allow, and the grid starts over (no selection, its columns read again).

Source

pub fn view(&self) -> Option<View<'_>>

The rows shown, in order (None only between replacing the table and the next paint).

Source

pub fn record(&self, index: usize) -> Option<RecordId>

The record of the row at index, as shown.

Source

pub fn filter(&self) -> Option<&Filter>

The filter rows are shown by.

Source

pub fn set_filter(&mut self, filter: Option<Filter>) -> Result<(), DataError>

Shows only the rows filter keeps (all of them for None), in the same sort. A selected row the filter hides is no longer selected.

§Errors

Those of LiveTable::add_view for the filter (an unknown column, a comparison with a value of another type); the model is unchanged then.

Source

pub fn set_decimals( &mut self, column: usize, decimals: Option<usize>, ) -> Result<(), TableError>

As ArrowTable::set_decimals; the grid takes in the new width.

§Errors

TableError::NoSuchColumn if there is no such column.

Source

pub fn set_column_chars( &mut self, column: usize, chars: usize, ) -> Result<(), TableError>

As ArrowTable::set_column_chars; the grid takes in the new width.

§Errors

TableError::NoSuchColumn if there is no such column.

Trait Implementations§

Source§

impl Debug for LiveModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl GridModel for LiveModel

Source§

fn columns(&self) -> &[Column]

The columns, left to right.
Source§

fn rows(&self) -> usize

How many rows there are.
Source§

fn cell( &self, row: usize, column: usize, text: &mut CellText, palette: &Palette, ) -> CellStyle

Writes the text of the cell at row, column into text (empty on entry) and returns its style, in the grid’s colors (palette, which follows the theme).
Source§

fn prepare(&mut self)

Brings the model up to date before the grid paints (taking in data that arrived, for example). It may allocate when the data changed; it should not otherwise. It runs only when the grid paints, not while it is hidden (an inactive tab): feed a model that must keep up while hidden from the application, through DataGrid::model_mut.
Source§

fn sort(&mut self, column: usize, order: SortOrder) -> bool

Sorts the rows by column (an index into columns) in order, when the user asks for it (a click on its title); false if the model does not sort by that column, which leaves the order alone.
Source§

fn sort_state(&self) -> Option<(usize, SortOrder)>

The column and order the rows are sorted by now, if the model knows (a model sorted before the user clicked, or one that sorts itself); the grid shows it and reverses it on the next click.
Source§

fn row_key(&self, row: usize) -> Option<u64>

A value identifying the record at row while rows are added, removed or sorted (a database key, an instrument id). With it, a selection follows its record; without it (None, the default), a selection is a position and is cleared by sorting.
Source§

fn row_of_key(&self, key: u64) -> Option<usize>

Where the record row_key gave key for is now, if it is still shown. Asked once a frame while a row is selected: make it fast for large models. None (the record was removed, or is filtered out) clears the selection.
Source§

fn columns_revision(&self) -> u64

Changes whenever columns changes (another schema, new widths): the grid then reads the columns again, keeping the widths the user dragged if the column titles are the same as before. Checked each frame after prepare.
Source§

fn generation(&self) -> u64

Changes when the rows were replaced wholesale (another table), so that keys from before mean nothing: the grid then clears its selection and scrolls to the top. Checked each frame after prepare.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.