mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
add per-room user model
This commit is contained in:
parent
07259b9cb7
commit
a3c4fece7e
3 changed files with 53 additions and 0 deletions
|
@ -303,6 +303,7 @@ set(SRC_FILES
|
||||||
src/TrayIcon.cpp
|
src/TrayIcon.cpp
|
||||||
src/UserInfoWidget.cpp
|
src/UserInfoWidget.cpp
|
||||||
src/UserSettingsPage.cpp
|
src/UserSettingsPage.cpp
|
||||||
|
src/UsersModel.cpp
|
||||||
src/Utils.cpp
|
src/Utils.cpp
|
||||||
src/WebRTCSession.cpp
|
src/WebRTCSession.cpp
|
||||||
src/WelcomePage.cpp
|
src/WelcomePage.cpp
|
||||||
|
|
28
src/UsersModel.cpp
Normal file
28
src/UsersModel.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "UsersModel.h"
|
||||||
|
|
||||||
|
#include "Cache.h"
|
||||||
|
#include "CompletionModelRoles.h"
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
UsersModel::UsersModel(const std::string &roomId, QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
roomMembers_ = cache::getMembers(roomId, 0, 9999);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
UsersModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (hasIndex(index.row(), index.column(), index.parent())) {
|
||||||
|
switch (role) {
|
||||||
|
case CompletionModel::CompletionRole:
|
||||||
|
case CompletionModel::SearchRole:
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
return roomMembers_[index.row()].display_name;
|
||||||
|
case Avatar:
|
||||||
|
return roomMembers_[index.row()].avatar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
24
src/UsersModel.h
Normal file
24
src/UsersModel.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
class RoomMember;
|
||||||
|
|
||||||
|
class UsersModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Roles
|
||||||
|
{
|
||||||
|
Avatar = Qt::UserRole // QImage avatar
|
||||||
|
};
|
||||||
|
|
||||||
|
UsersModel(const std::string &roomId, QObject *parent = nullptr);
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override
|
||||||
|
{
|
||||||
|
return (parent == QModelIndex()) ? roomMembers_.size() : 0;
|
||||||
|
}
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<RoomMember> roomMembers_;
|
||||||
|
};
|
Loading…
Reference in a new issue