LeechCraft
0.6.70-19214-g121e5318a7
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
lazyrootmixin.h
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#pragma once
10
11
#include <concepts>
12
#include <functional>
13
#include <utility>
14
#include <QAbstractItemModel>
15
16
namespace
LC::Util
17
{
36
template
<std::derived_from<QAbstractItemModel> Model>
37
class
LazyRootMixin
:
public
Model
38
{
39
const
std::function<void ()> Load_;
40
bool
Loaded_ =
false
;
41
public
:
49
template
<
typename
... Args>
50
explicit
LazyRootMixin
(std::function<
void
()> load, Args&&... args)
51
:
Model
{ std::forward<Args> (args)... }
52
, Load_ { std::move (load) }
53
{
54
}
55
58
bool
IsLoaded
()
const
59
{
60
return
Loaded_;
61
}
62
65
void
EnsureLoaded
()
66
{
67
if
(!Loaded_)
68
Reload
();
69
}
70
73
void
Reload
()
74
{
75
Loaded_ =
true
;
76
this->removeRows (0, this->rowCount ());
77
Load_ ();
78
}
79
80
bool
hasChildren
(
const
QModelIndex& parent)
const override
81
{
82
return
IsUnloadedRoot (parent) || Model::hasChildren (parent);
83
}
84
85
bool
canFetchMore
(
const
QModelIndex& parent)
const override
86
{
87
return
IsUnloadedRoot (parent) || Model::canFetchMore (parent);
88
}
89
90
void
fetchMore
(
const
QModelIndex& parent)
override
91
{
92
if
(IsUnloadedRoot (parent))
93
Reload
();
94
else
95
Model::fetchMore (parent);
96
}
97
private
:
98
bool
IsUnloadedRoot (
const
QModelIndex& parent)
const
99
{
100
return
!parent.isValid () && !Loaded_;
101
}
102
};
103
}
LC::Util::LazyRootMixin::IsLoaded
bool IsLoaded() const
Returns whether the model has been populated.
Definition
lazyrootmixin.h:58
LC::Util::LazyRootMixin::canFetchMore
bool canFetchMore(const QModelIndex &parent) const override
Definition
lazyrootmixin.h:85
LC::Util::LazyRootMixin::fetchMore
void fetchMore(const QModelIndex &parent) override
Definition
lazyrootmixin.h:90
LC::Util::LazyRootMixin::EnsureLoaded
void EnsureLoaded()
Populates the model if it hasn't been populated yet.
Definition
lazyrootmixin.h:65
LC::Util::LazyRootMixin::hasChildren
bool hasChildren(const QModelIndex &parent) const override
Definition
lazyrootmixin.h:80
LC::Util::LazyRootMixin::LazyRootMixin
LazyRootMixin(std::function< void()> load, Args &&... args)
Constructs the model passing the arguments to the base constructor.
Definition
lazyrootmixin.h:50
LC::Util::LazyRootMixin::Reload
void Reload()
Drops the rows and populates the model anew.
Definition
lazyrootmixin.h:73
LC::Util
Definition
icoreproxy.h:34
LC::Model
@ Model
The human-readable name of the device model (QString).
Definition
deviceroles.h:107
src
util
models
lazyrootmixin.h
Generated by
1.18.0