Maintains expanded state, selection, keyboard navigation, and a flat projection of visible rows ready to drive VirtualList.
More...
#include <FlatTreeModel.hpp>
|
|
using | Row = FlatTreeRow<NodeT, KeyT> |
|
using | KeyFn = std::function<KeyT(const NodeT &)> |
|
using | ChildVisitor = std::function<bool(const NodeT &)> |
|
using | ChildrenInvoker = std::function<void(const NodeT &, const ChildVisitor &)> |
|
| template<typename KeyFnT, typename ChildrenFnT> |
| | FlatTreeModel (KeyFnT &&keyFn, ChildrenFnT &&childrenFn) |
| | Construct a model from a key extractor and a children range accessor.
|
| template<typename Range> |
| void | setRoots (const Range &roots, bool notify=true) |
| | Set root nodes from any iterable range of NodeT or pointers to NodeT.
|
|
void | rebuild (bool notify=true) |
| | Re-project the flat row list from the current roots and expanded set.
|
|
size_t | count () const noexcept |
|
bool | empty () const noexcept |
|
const Row & | at (size_t index) const |
|
const std::vector< Row > & | rows () const noexcept |
|
int | findRowByKey (const KeyT &key) const |
| | Index of key in the current flat projection, or -1 if hidden/absent.
|
|
bool | isExpanded (const KeyT &key) const |
| bool | setExpanded (const KeyT &key, bool expanded, bool notify=true) |
| | Expand or collapse key.
|
|
bool | toggle (const KeyT &key, bool notify=true) |
| | Toggle the expanded state of key.
|
|
void | expandAll (bool notify=true) |
| | Expand every branch reachable from the current roots.
|
|
void | collapseAll (bool notify=true) |
| | Collapse every branch.
|
|
void | select (const KeyT &key, bool notify=true) |
|
void | clearSelection (bool notify=true) |
|
bool | isSelected (const KeyT &key) const |
|
const std::optional< KeyT > & | selectedKey () const noexcept |
|
int | selectedRowIndex () const |
| | Flat index of the selected row, or -1 if nothing is selected or it is collapsed.
|
| bool | handleKey (int key) |
| | Handle standard tree navigation keys (Up, Down, Left, Right, Home, End, Enter).
|
|
|
std::function< void()> | onChanged |
|
std::function< void(const std::optional< KeyT > &)> | onSelectionChanged |
|
std::function< void(const Row &)> | onItemActivated |
|
std::function< void(const KeyT &, bool)> | onItemToggled |
template<typename NodeT, typename KeyT>
class ZenitUI::UI::FlatTreeModel< NodeT, KeyT >
Maintains expanded state, selection, keyboard navigation, and a flat projection of visible rows ready to drive VirtualList.
- Template Parameters
-
| NodeT | User-defined tree node type (never copied). |
| KeyT | Hashable, equality-comparable stable node identifier. |
- Examples
- 14_desktop_workspace/main.cpp.
◆ FlatTreeModel()
template<typename NodeT, typename KeyT>
template<typename KeyFnT, typename ChildrenFnT>
Construct a model from a key extractor and a children range accessor.
- Parameters
-
| keyFn | KeyT(const NodeT &) returning a stable unique key per node. |
| childrenFn | Returns any iterable range of NodeT, NodeT *, unique_ptr<NodeT>, or shared_ptr<NodeT>. |
◆ handleKey()
template<typename NodeT, typename KeyT>
Handle standard tree navigation keys (Up, Down, Left, Right, Home, End, Enter).
- Returns
- true if the key was consumed.
◆ setExpanded()
template<typename NodeT, typename KeyT>
◆ setRoots()
template<typename NodeT, typename KeyT>
template<typename Range>
Set root nodes from any iterable range of NodeT or pointers to NodeT.
Preserves existing expanded/selected keys across data refreshes.
- Examples
- 14_desktop_workspace/main.cpp.
The documentation for this class was generated from the following file: