14#include <QAbstractItemModel>
36 template<std::derived_from<QAbstractItemModel> Model>
39 const std::function<void ()> Load_;
49 template<
typename... Args>
51 :
Model { std::forward<Args> (args)... }
52 , Load_ { std::move (load) }
76 this->removeRows (0, this->rowCount ());
82 return IsUnloadedRoot (parent) || Model::hasChildren (parent);
87 return IsUnloadedRoot (parent) || Model::canFetchMore (parent);
92 if (IsUnloadedRoot (parent))
95 Model::fetchMore (parent);
98 bool IsUnloadedRoot (
const QModelIndex& parent)
const
100 return !parent.isValid () && !Loaded_;
bool IsLoaded() const
Returns whether the model has been populated.
bool canFetchMore(const QModelIndex &parent) const override
void fetchMore(const QModelIndex &parent) override
void EnsureLoaded()
Populates the model if it hasn't been populated yet.
bool hasChildren(const QModelIndex &parent) const override
LazyRootMixin(std::function< void()> load, Args &&... args)
Constructs the model passing the arguments to the base constructor.
void Reload()
Drops the rows and populates the model anew.
@ Model
The human-readable name of the device model (QString).