LeechCraft 0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
LC::Util::LazyRootMixin< Model > Class Template Reference

Defers populating the model until a view first asks for rows. More...

#include "lazyrootmixin.h"

Inheritance diagram for LC::Util::LazyRootMixin< Model >:
Collaboration diagram for LC::Util::LazyRootMixin< Model >:

Public Member Functions

template<typename... Args>
 LazyRootMixin (std::function< void()> load, Args &&... args)
 Constructs the model passing the arguments to the base constructor.
bool IsLoaded () const
 Returns whether the model has been populated.
void EnsureLoaded ()
 Populates the model if it hasn't been populated yet.
void Reload ()
 Drops the rows and populates the model anew.
bool hasChildren (const QModelIndex &parent) const override
bool canFetchMore (const QModelIndex &parent) const override
void fetchMore (const QModelIndex &parent) override

Detailed Description

template<std::derived_from< QAbstractItemModel > Model>
class LC::Util::LazyRootMixin< Model >

Defers populating the model until a view first asks for rows.

Derive from this class (or instantiate it directly), parametrizing the template by the desired base class like QStandardItemModel, and pass the function populating the model. The function is invoked when an attached view first asks the root for more rows, and on each Reload() after that, always on an empty root: the existing rows are removed first, so the base model must support removeRows() on the root.

Only views (and proxies in front of them) drive the loading: code reading the model directly sees it empty until then and should call EnsureLoaded() first.

Template Parameters
ModelThe model type to derive from.

Definition at line 37 of file lazyrootmixin.h.

Constructor & Destructor Documentation

◆ LazyRootMixin()

template<std::derived_from< QAbstractItemModel > Model>
template<typename... Args>
LC::Util::LazyRootMixin< Model >::LazyRootMixin ( std::function< void()> load,
Args &&... args )
inlineexplicit

Constructs the model passing the arguments to the base constructor.

Parameters
[in]loadThe function populating the empty model.
[in]argsThe list of parameters to pass to the constructor of the base Model.

Definition at line 50 of file lazyrootmixin.h.

References LC::Model.

Member Function Documentation

◆ canFetchMore()

template<std::derived_from< QAbstractItemModel > Model>
bool LC::Util::LazyRootMixin< Model >::canFetchMore ( const QModelIndex & parent) const
inlineoverride

Definition at line 85 of file lazyrootmixin.h.

◆ EnsureLoaded()

template<std::derived_from< QAbstractItemModel > Model>
void LC::Util::LazyRootMixin< Model >::EnsureLoaded ( )
inline

Populates the model if it hasn't been populated yet.

Definition at line 65 of file lazyrootmixin.h.

References Reload().

Here is the call graph for this function:

◆ fetchMore()

template<std::derived_from< QAbstractItemModel > Model>
void LC::Util::LazyRootMixin< Model >::fetchMore ( const QModelIndex & parent)
inlineoverride

Definition at line 90 of file lazyrootmixin.h.

References Reload().

Here is the call graph for this function:

◆ hasChildren()

template<std::derived_from< QAbstractItemModel > Model>
bool LC::Util::LazyRootMixin< Model >::hasChildren ( const QModelIndex & parent) const
inlineoverride

Definition at line 80 of file lazyrootmixin.h.

◆ IsLoaded()

template<std::derived_from< QAbstractItemModel > Model>
bool LC::Util::LazyRootMixin< Model >::IsLoaded ( ) const
inline

Returns whether the model has been populated.

Definition at line 58 of file lazyrootmixin.h.

◆ Reload()

template<std::derived_from< QAbstractItemModel > Model>
void LC::Util::LazyRootMixin< Model >::Reload ( )
inline

Drops the rows and populates the model anew.

Definition at line 73 of file lazyrootmixin.h.

Referenced by EnsureLoaded(), and fetchMore().

Here is the caller graph for this function:

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/leechcraft-doc-0.6.70+git.19214.g121e5318a7-build/leechcraft-0.6.70-19214-g121e5318a7/src/util/models/lazyrootmixin.h