27#include <unordered_set>
31namespace morph::table {
70 .message =
"pruneOnFilter is not available in server mode"});
87 if (_keys.insert(key).second) {
88 _order.push_back(std::move(key));
99 if (_keys.erase(key) == 0) {
102 std::erase(_order, key);
114 return select(std::move(key));
130 .message =
"select all needs multiple selection over client rows"});
132 for (std::size_t row = 0; row < engine.
viewRowCount(); ++row) {
142 if (!_options.pruneOnFilter) {
145 std::erase_if(_order, [&](
RowId const& key) {
156 void setActiveKey(std::optional<RowId> key) { _active = std::move(key); }
160 [[nodiscard]] std::optional<RowId>
const&
activeKey() const noexcept {
return _active; }
165 [[nodiscard]]
bool contains(
RowId const& key)
const {
return _keys.contains(key); }
169 [[nodiscard]] std::size_t
selectedCount() const noexcept {
return _keys.size(); }
173 [[nodiscard]] std::vector<RowId>
const&
keys() const noexcept {
return _order; }
185 std::function<
void(
RowId const&)>
const& onActivate) {
190 onActivate(engine.
rowIdAt(viewRow));
198 SelectionOptions _options;
199 std::unordered_set<RowId> _keys;
200 std::vector<RowId> _order;
201 std::optional<RowId> _active;
Sorts, filters and maps the view of one table.
std::size_t sourceRowCount() const
Rows in the source the view was computed from.
std::optional< std::size_t > viewRowOfKey(RowId const &key) const
The view row of the row keyed id.
RowId rowIdAt(std::size_t viewRow) const
The key of the row at a view row.
std::size_t viewRowCount() const noexcept
Rows in the view.
A table's selected keys and active key.
void viewChanged(Engine const &engine)
Brings the selection up to date after the view changed: with pruneOnFilter, drops selected rows no lo...
bool contains(RowId const &key) const
Whether a row is selected.
void clear()
Deselects every row.
void setActiveKey(std::optional< RowId > key)
Moves the cursor.
static bool activate(Engine const &engine, std::size_t viewRow, std::function< void(RowId const &)> const &onActivate)
Activates the row at a view row: reports it and changes no selection.
bool deselect(RowId key)
Deselects a row.
std::size_t selectedCount() const noexcept
Selected rows.
std::optional< RowId > const & activeKey() const noexcept
The row with the cursor.
SelectionOptions const & options() const noexcept
The configuration.
std::vector< RowId > const & keys() const noexcept
The selected keys, in the order they were selected.
bool toggle(RowId key)
Selects an unselected row, or deselects a selected one.
bool select(RowId key)
Selects a row; in Single mode it replaces the selection.
static std::expected< Selection, TableError > create(SelectionOptions options)
Builds a selection.
std::expected< void, TableError > selectAll(Engine const &engine)
Selects every row in the engine's view.
The rows a table engine reads, and the services it is given.
@ Unavailable
An operation the table's mode does not offer.
std::variant< std::int64_t, std::string > RowId
A row's identity: the table's key, stable across reloads.
The table engine: sort, filter and view mapping, on and off the owner.
SelectionMode
How many rows a selection may hold.
@ None
Rows cannot be selected.
@ Multiple
Any number of rows.
TableCounts counts(Engine const &engine, Selection const &selection)
A table's counts.
TableMode
Where a table's rows are sorted and filtered.
@ Client
The client holds every row and the engine sorts and filters them.
@ Server
The server sorts and filters; the client holds fetched pages.
@ Hybrid
A server search whose result the client engine sorts and filters.
A selection's configuration.
TableMode tableMode
The table's mode; Server rules out select-all and pruning.
bool pruneOnFilter
Drop selected rows that leave the view.
SelectionMode mode
How many rows may be selected.
The counts a status line shows.
std::size_t selectedCount
Selected rows.
std::size_t viewCount
Rows in the view.
std::size_t sourceCount
Rows in the source.
The error every fallible table call returns.