pub struct PagedModel { /* private fields */ }Expand description
A grid model (for densa_widgets::DataGrid) of rows fetched a page at a time from a
PageSource: a table too large to hold, such as a query engine’s result over files of
billions of rows. The grid shows only some rows, and the model fetches their pages and one
on each side, on a thread of its own, so the window never waits; rows not yet fetched show
empty until they arrive.
A click on a column title asks the source for its rows in that order. Cells are formatted
as in ArrowTable; columns are sized by the first rows and widened
when later numbers no longer fit. Rows have no keys: a selection is a position. A copy of
selected rows holds those among them that are held (GridModel::copy_rows): selecting all
of a billion rows copies those held, which can be runs far apart. On a 32-bit target, rows
past usize::MAX are not shown.
Costs: a frame whose pages are held allocates nothing; one that asks for pages or takes them in does. Dropping the model ends its thread once the source’s current call returns.
Implementations§
Source§impl PagedModel
impl PagedModel
Sourcepub fn new(
schema: SchemaRef,
source: impl PageSource,
wake: impl Fn() + Send + 'static,
) -> Result<Self>
pub fn new( schema: SchemaRef, source: impl PageSource, wake: impl Fn() + Send + 'static, ) -> Result<Self>
A model of the rows source gives, with schema (every page’s columns), fetched on a
thread of its own in pages of 256 rows.
wake is called on that thread each time it sends something back (rows, a count, a
failure), and possibly once after the model is dropped: give it
move || { waker.wake(); } with a densa_window::Waker, so the window paints what
came. If wake panics, the thread stops (FetchError::Stopped).
§Errors
The thread could not be started.
Sourcepub fn with_options(
schema: SchemaRef,
source: impl PageSource,
wake: impl Fn() + Send + 'static,
options: PageOptions,
) -> Result<Self>
pub fn with_options( schema: SchemaRef, source: impl PageSource, wake: impl Fn() + Send + 'static, options: PageOptions, ) -> Result<Self>
Sourcepub fn row_count(&self) -> Option<u64>
pub fn row_count(&self) -> Option<u64>
How many rows there are, once the source counted them: None until then, and after a
count failed.
Sourcepub fn error(&self) -> Option<&FetchError>
pub fn error(&self) -> Option<&FetchError>
Sourcepub fn is_fetched(&self, row: usize) -> bool
pub fn is_fetched(&self, row: usize) -> bool
Whether row’s page is held as the source gives it now (not one kept from before a
refresh until it is fetched again).
Sourcepub fn pages_held(&self) -> usize
pub fn pages_held(&self) -> usize
How many pages are held.
Sourcepub fn retry(&mut self)
pub fn retry(&mut self)
Asks again for what failed: the pages shown that the source failed to give, or the count (not one on its way). Pages held stay.
Sourcepub fn refresh(&mut self)
pub fn refresh(&mut self)
Counts the rows and fetches the pages shown again: for when the source’s data changed. The rows held are shown until their pages are back, and the count until the new one is. Sorting fetches the pages of the new order by itself.
Sourcepub fn set_decimals(
&mut self,
column: usize,
decimals: Option<usize>,
) -> Result<(), TableError>
pub fn set_decimals( &mut self, column: usize, decimals: Option<usize>, ) -> Result<(), TableError>
As ArrowTable::set_decimals: floating-point values
of column with decimals fixed decimal places (None: the shortest exact form). A
column sized by the pages is sized again from those held, as now printed; the grid
takes in the new width.
§Errors
TableError::NoSuchColumn if there is no such column.
Sourcepub fn set_column_chars(
&mut self,
column: usize,
chars: usize,
) -> Result<(), TableError>
pub fn set_column_chars( &mut self, column: usize, chars: usize, ) -> Result<(), TableError>
As ArrowTable::set_column_chars: column is
chars characters wide (1 to CELL_BYTES), longer text cut to fit ending in …, and
pages no longer size it; the grid takes in the new width.
§Errors
TableError::NoSuchColumn if there is no such column.
Trait Implementations§
Source§impl Debug for PagedModel
impl Debug for PagedModel
Source§impl GridModel for PagedModel
impl GridModel for PagedModel
Source§fn copy_rows(&self, rows: Range<usize>) -> Vec<Range<usize>>
fn copy_rows(&self, rows: Range<usize>) -> Vec<Range<usize>>
The rows of rows held, in runs: a copy holds no rows not fetched.
Source§fn sort(&mut self, column: usize, order: SortOrder) -> bool
fn sort(&mut self, column: usize, order: SortOrder) -> bool
Asks the source for its rows sorted by column; false for a column the schema does
not have, whose name an earlier column has (the source sorts by name), or that the
source cannot sort by (PageSource::can_sort).
Source§fn cell(
&self,
row: usize,
column: usize,
text: &mut CellText,
palette: &Palette,
) -> CellStyle
fn cell( &self, row: usize, column: usize, text: &mut CellText, palette: &Palette, ) -> CellStyle
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)
fn prepare(&mut self)
DataGrid::model_mut.Source§fn showing(&mut self, rows: Range<usize>)
fn showing(&mut self, rows: Range<usize>)
prepare. A model that fetches its rows, from a
database or a query engine, asks for these and those around them; it should not
allocate while it has them. Does nothing by default.Source§fn sort_state(&self) -> Option<(usize, SortOrder)>
fn sort_state(&self) -> Option<(usize, SortOrder)>
Source§fn columns_revision(&self) -> u64
fn columns_revision(&self) -> u64
Source§fn row_key(&self, row: usize) -> Option<u64>
fn row_key(&self, row: usize) -> Option<u64>
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>
fn row_of_key(&self, key: u64) -> Option<usize>
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 generation(&self) -> u64
fn generation(&self) -> u64
prepare.