Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F325860
matrix-room-member-list-model.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
matrix-room-member-list-model.cpp
View Options
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include
<libkazv-config.hpp>
#include
<immer/config.hpp>
// https://github.com/arximboldi/immer/issues/168
#include
<cmath>
#include
<lager/lenses/optional.hpp>
#include
<cursorutil.hpp>
#include
"matrix-room-member-list-model.hpp"
#include
"matrix-room-member.hpp"
using
namespace
Kazv
;
MatrixRoomMemberListModel
::
MatrixRoomMemberListModel
(
lager
::
reader
<
Kazv
::
EventList
>
members
,
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
,
m_members
(
members
)
,
m_internalCount
(
0
)
,
LAGER_QT
(
count
)(
m_members
.
map
([](
const
auto
&
m
)
->
int
{
return
m
.
size
();
}))
{
m_internalCount
=
count
();
connect
(
this
,
&
MatrixRoomMemberListModel
::
countChanged
,
this
,
&
MatrixRoomMemberListModel
::
updateInternalCount
);
}
MatrixRoomMemberListModel
::~
MatrixRoomMemberListModel
()
=
default
;
MatrixRoomMember
*
MatrixRoomMemberListModel::at
(
int
index
)
const
{
return
new
MatrixRoomMember
(
m_members
[
index
][
lager
::
lenses
::
or_default
]);
}
int
MatrixRoomMemberListModel::rowCount
(
const
QModelIndex
&
index
)
const
{
if
(
index
.
isValid
())
{
return
0
;
}
else
{
return
count
();
}
}
QVariant
MatrixRoomMemberListModel::data
(
const
QModelIndex
&
,
int
)
const
{
return
QVariant
();
}
void
MatrixRoomMemberListModel::updateInternalCount
()
{
auto
curCount
=
count
();
auto
oldCount
=
m_internalCount
;
auto
diff
=
std
::
abs
(
curCount
-
oldCount
);
if
(
curCount
>
oldCount
)
{
beginInsertRows
(
QModelIndex
(),
0
,
diff
-
1
);
m_internalCount
=
curCount
;
endInsertRows
();
}
else
if
(
curCount
<
oldCount
)
{
beginRemoveRows
(
QModelIndex
(),
0
,
diff
-
1
);
m_internalCount
=
curCount
;
endRemoveRows
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Apr 24, 4:25 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
87047
Default Alt Text
matrix-room-member-list-model.cpp (1 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment