Cleanup userlistmodel
This commit is contained in:
@@ -55,7 +55,7 @@ QVariant CompletionModel::data(const QModelIndex &index, int role) const
|
|||||||
return m_filterModel->data(filterIndex, UserListModel::NameRole);
|
return m_filterModel->data(filterIndex, UserListModel::NameRole);
|
||||||
}
|
}
|
||||||
if (role == Subtitle) {
|
if (role == Subtitle) {
|
||||||
return m_filterModel->data(filterIndex, UserListModel::UserIDRole);
|
return m_filterModel->data(filterIndex, UserListModel::UserIdRole);
|
||||||
}
|
}
|
||||||
if (role == Icon) {
|
if (role == Icon) {
|
||||||
return m_filterModel->data(filterIndex, UserListModel::AvatarRole);
|
return m_filterModel->data(filterIndex, UserListModel::AvatarRole);
|
||||||
@@ -114,7 +114,7 @@ void CompletionModel::updateCompletion()
|
|||||||
{
|
{
|
||||||
if (text().startsWith(QLatin1Char('@'))) {
|
if (text().startsWith(QLatin1Char('@'))) {
|
||||||
m_filterModel->setSourceModel(m_userListModel);
|
m_filterModel->setSourceModel(m_userListModel);
|
||||||
m_filterModel->setFilterRole(UserListModel::UserIDRole);
|
m_filterModel->setFilterRole(UserListModel::UserIdRole);
|
||||||
m_filterModel->setSecondaryFilterRole(UserListModel::NameRole);
|
m_filterModel->setSecondaryFilterRole(UserListModel::NameRole);
|
||||||
m_filterModel->setFullText(m_fullText);
|
m_filterModel->setFullText(m_fullText);
|
||||||
m_filterModel->setFilterText(m_text);
|
m_filterModel->setFilterText(m_text);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ UserListModel::UserListModel(QObject *parent)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserListModel::setRoom(Quotient::Room *room)
|
void UserListModel::setRoom(NeoChatRoom *room)
|
||||||
{
|
{
|
||||||
if (m_currentRoom == room) {
|
if (m_currentRoom == room) {
|
||||||
return;
|
return;
|
||||||
@@ -51,15 +51,19 @@ void UserListModel::setRoom(Quotient::Room *room)
|
|||||||
connect(user, &User::avatarChanged, this, &UserListModel::avatarChanged);
|
connect(user, &User::avatarChanged, this, &UserListModel::avatarChanged);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this] {
|
connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this]() {
|
||||||
setRoom(nullptr);
|
setRoom(nullptr);
|
||||||
});
|
});
|
||||||
qDebug() << m_users.count() << "user(s) in the room";
|
|
||||||
}
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
Q_EMIT roomChanged();
|
Q_EMIT roomChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NeoChatRoom *UserListModel::room() const
|
||||||
|
{
|
||||||
|
return m_currentRoom;
|
||||||
|
}
|
||||||
|
|
||||||
Quotient::User *UserListModel::userAt(QModelIndex index) const
|
Quotient::User *UserListModel::userAt(QModelIndex index) const
|
||||||
{
|
{
|
||||||
if (index.row() < 0 || index.row() >= m_users.size()) {
|
if (index.row() < 0 || index.row() >= m_users.size()) {
|
||||||
@@ -75,14 +79,13 @@ QVariant UserListModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (index.row() >= m_users.count()) {
|
if (index.row() >= m_users.count()) {
|
||||||
qDebug() << "UserListModel, something's wrong: index.row() >= m_users.count()";
|
return QStringLiteral("DEADBEEF");
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
auto user = m_users.at(index.row());
|
auto user = m_users.at(index.row());
|
||||||
if (role == NameRole) {
|
if (role == NameRole) {
|
||||||
return user->displayname(m_currentRoom);
|
return user->displayname(m_currentRoom);
|
||||||
}
|
}
|
||||||
if (role == UserIDRole) {
|
if (role == UserIdRole) {
|
||||||
return user->id();
|
return user->id();
|
||||||
}
|
}
|
||||||
if (role == AvatarRole) {
|
if (role == AvatarRole) {
|
||||||
@@ -187,7 +190,7 @@ void UserListModel::avatarChanged(Quotient::User *user, const Quotient::Room *co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int UserListModel::findUserPos(User *user) const
|
int UserListModel::findUserPos(Quotient::User *user) const
|
||||||
{
|
{
|
||||||
return findUserPos(m_currentRoom->roomMembername(user));
|
return findUserPos(m_currentRoom->roomMembername(user));
|
||||||
}
|
}
|
||||||
@@ -202,7 +205,7 @@ QHash<int, QByteArray> UserListModel::roleNames() const
|
|||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
|
|
||||||
roles[NameRole] = "name";
|
roles[NameRole] = "name";
|
||||||
roles[UserIDRole] = "userId";
|
roles[UserIdRole] = "userId";
|
||||||
roles[AvatarRole] = "avatar";
|
roles[AvatarRole] = "avatar";
|
||||||
roles[ObjectRole] = "user";
|
roles[ObjectRole] = "user";
|
||||||
roles[PermRole] = "perm";
|
roles[PermRole] = "perm";
|
||||||
|
|||||||
@@ -6,11 +6,12 @@
|
|||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class NeoChatRoom;
|
||||||
|
|
||||||
namespace Quotient
|
namespace Quotient
|
||||||
{
|
{
|
||||||
class Connection;
|
|
||||||
class Room;
|
|
||||||
class User;
|
class User;
|
||||||
|
class Room;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserType : public QObject
|
class UserType : public QObject
|
||||||
@@ -31,11 +32,11 @@ public:
|
|||||||
class UserListModel : public QAbstractListModel
|
class UserListModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Quotient::Room *room READ room WRITE setRoom NOTIFY roomChanged)
|
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
|
||||||
public:
|
public:
|
||||||
enum EventRoles {
|
enum EventRoles {
|
||||||
NameRole = Qt::DisplayRole,
|
NameRole = Qt::UserRole + 1,
|
||||||
UserIDRole,
|
UserIdRole,
|
||||||
AvatarRole,
|
AvatarRole,
|
||||||
ObjectRole,
|
ObjectRole,
|
||||||
PermRole,
|
PermRole,
|
||||||
@@ -43,11 +44,9 @@ public:
|
|||||||
|
|
||||||
UserListModel(QObject *parent = nullptr);
|
UserListModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] Quotient::Room *room() const
|
[[nodiscard]] NeoChatRoom *room() const;
|
||||||
{
|
void setRoom(NeoChatRoom *room);
|
||||||
return m_currentRoom;
|
|
||||||
}
|
|
||||||
void setRoom(Quotient::Room *room);
|
|
||||||
[[nodiscard]] Quotient::User *userAt(QModelIndex index) const;
|
[[nodiscard]] Quotient::User *userAt(QModelIndex index) const;
|
||||||
|
|
||||||
[[nodiscard]] QVariant data(const QModelIndex &index, int role = NameRole) const override;
|
[[nodiscard]] QVariant data(const QModelIndex &index, int role = NameRole) const override;
|
||||||
@@ -65,7 +64,7 @@ private Q_SLOTS:
|
|||||||
void avatarChanged(Quotient::User *user, const Quotient::Room *context);
|
void avatarChanged(Quotient::User *user, const Quotient::Room *context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Quotient::Room *m_currentRoom;
|
NeoChatRoom *m_currentRoom;
|
||||||
QList<Quotient::User *> m_users;
|
QList<Quotient::User *> m_users;
|
||||||
|
|
||||||
int findUserPos(Quotient::User *user) const;
|
int findUserPos(Quotient::User *user) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user