2020-09-07 11:51:28 +02:00
|
|
|
#include "UsersModel.h"
|
|
|
|
|
|
|
|
#include "Cache.h"
|
|
|
|
#include "CompletionModelRoles.h"
|
|
|
|
|
|
|
|
UsersModel::UsersModel(const std::string &roomId, QObject *parent)
|
|
|
|
: QAbstractListModel(parent)
|
2020-11-20 02:38:08 +01:00
|
|
|
, room_id(roomId)
|
|
|
|
{
|
|
|
|
roomMembers_ = cache::roomMembers(roomId);
|
|
|
|
}
|
|
|
|
|
|
|
|
QHash<int, QByteArray>
|
|
|
|
UsersModel::roleNames() const
|
2020-09-07 11:51:28 +02:00
|
|
|
{
|
2020-11-20 02:38:08 +01:00
|
|
|
return {
|
|
|
|
{CompletionModel::CompletionRole, "completionRole"},
|
|
|
|
{CompletionModel::SearchRole, "searchRole"},
|
|
|
|
{CompletionModel::SearchRole2, "searchRole2"},
|
|
|
|
{Roles::DisplayName, "displayName"},
|
|
|
|
{Roles::AvatarUrl, "avatarUrl"},
|
|
|
|
};
|
2020-09-07 11:51:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2020-11-20 02:38:08 +01:00
|
|
|
case Roles::DisplayName:
|
|
|
|
return QString::fromStdString(
|
|
|
|
cache::displayName(room_id, roomMembers_[index.row()]));
|
|
|
|
case CompletionModel::SearchRole2:
|
|
|
|
return QString::fromStdString(roomMembers_[index.row()]);
|
|
|
|
case Roles::AvatarUrl:
|
|
|
|
return cache::avatarUrl(QString::fromStdString(room_id),
|
|
|
|
QString::fromStdString(roomMembers_[index.row()]));
|
2020-09-07 11:51:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|