LeechCraft
0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
Toggle main menu visibility
Loading...
Searching...
No Matches
checkableproxymodel.cpp
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
#include "
checkableproxymodel.h
"
10
11
namespace
LC::Util
12
{
13
CheckableProxyModelBase::CheckableProxyModelBase
(
int
idRole, QObject *parent)
14
: QIdentityProxyModel { parent }
15
,
IdRole_
{ idRole }
16
{
17
}
18
19
Qt::ItemFlags
CheckableProxyModelBase::flags
(
const
QModelIndex& index)
const
20
{
21
auto
flags
= QIdentityProxyModel::flags (index);
22
if
(index.column () == 0)
23
flags
|= Qt::ItemIsUserCheckable;
24
return
flags
;
25
}
26
27
QVariant
CheckableProxyModelBase::data
(
const
QModelIndex& index,
int
role)
const
28
{
29
if
(role == Qt::CheckStateRole && index.column () == 0)
30
return
IsChecked
(index.data (
IdRole_
)) ? Qt::Checked : Qt::Unchecked;
31
32
return
QIdentityProxyModel::data (index, role);
33
}
34
35
bool
CheckableProxyModelBase::setData
(
const
QModelIndex& index,
const
QVariant& value,
int
role)
36
{
37
if
(role == Qt::CheckStateRole && index.column () == 0)
38
{
39
SetChecked
(index.data (
IdRole_
), value.value<Qt::CheckState> () == Qt::Checked);
40
emit
selectionChanged
();
41
emit dataChanged (index, index, { Qt::CheckStateRole });
42
return
true
;
43
}
44
45
return
QIdentityProxyModel::setData (index, value, role);
46
}
47
48
void
CheckableProxyModelBase::CheckAll
()
49
{
50
const
auto
rc = sourceModel ()->rowCount ();
51
for
(
int
i = 0; i < rc; ++i)
52
{
53
const
auto
srcIndex = sourceModel ()->index (i, 0);
54
const
auto
& idVar = srcIndex.data (
IdRole_
);
55
if
(!
IsChecked
(idVar))
56
{
57
SetChecked
(idVar,
true
);
58
const
auto
& index = mapFromSource (srcIndex);
59
emit dataChanged (index, index, { Qt::CheckStateRole });
60
}
61
}
62
63
emit
selectionChanged
();
64
}
65
66
void
CheckableProxyModelBase::CheckNone
()
67
{
68
const
auto
rc = sourceModel ()->rowCount ();
69
for
(
int
i = 0; i < rc; ++i)
70
{
71
const
auto
srcIndex = sourceModel ()->index (i, 0);
72
const
auto
& idVar = srcIndex.data (
IdRole_
);
73
if
(
IsChecked
(idVar))
74
{
75
SetChecked
(idVar,
false
);
76
const
auto
& index = mapFromSource (srcIndex);
77
emit dataChanged (index, index, { Qt::CheckStateRole });
78
}
79
}
80
81
emit
selectionChanged
();
82
}
83
}
checkableproxymodel.h
LC::Util::CheckableProxyModelBase::SetChecked
virtual void SetChecked(const QVariant &idVar, bool checked)=0
LC::Util::CheckableProxyModelBase::CheckAll
void CheckAll()
Definition
checkableproxymodel.cpp:48
LC::Util::CheckableProxyModelBase::IdRole_
const int IdRole_
Definition
checkableproxymodel.h:21
LC::Util::CheckableProxyModelBase::IsChecked
virtual bool IsChecked(const QVariant &idVar) const =0
LC::Util::CheckableProxyModelBase::data
QVariant data(const QModelIndex &index, int role) const override
Definition
checkableproxymodel.cpp:27
LC::Util::CheckableProxyModelBase::selectionChanged
void selectionChanged()
LC::Util::CheckableProxyModelBase::CheckNone
void CheckNone()
Definition
checkableproxymodel.cpp:66
LC::Util::CheckableProxyModelBase::flags
Qt::ItemFlags flags(const QModelIndex &index) const override
Definition
checkableproxymodel.cpp:19
LC::Util::CheckableProxyModelBase::setData
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Definition
checkableproxymodel.cpp:35
LC::Util::CheckableProxyModelBase::CheckableProxyModelBase
CheckableProxyModelBase(int idRole, QObject *parent=nullptr)
Definition
checkableproxymodel.cpp:13
LC::Util
Definition
icoreproxy.h:34
src
util
models
checkableproxymodel.cpp
Generated by
1.17.0