Document and Cleanup userlistmodel

Document and cleanup userlist model.

- Remove unneeded enum UserTypes
- Cleanup includes and remove need to include QPointer
- make clear that it is a user or users that are being refreshed

Note: breaks libquotient 0.6 compatibility because of the changes to how m_currentRoom is handled
This commit is contained in:
James Graham
2023-04-29 14:53:01 +00:00
committed by Tobias Fella
parent 014185c4c9
commit ca805917de
3 changed files with 65 additions and 73 deletions

View File

@@ -3,8 +3,6 @@
#pragma once
#include <room.h>
#include <QAbstractListModel>
#include <QObject>
#include <QPointer>
@@ -14,37 +12,38 @@ class NeoChatRoom;
namespace Quotient
{
class User;
class Room;
}
class UserType : public QObject
{
Q_OBJECT
public:
enum Types {
Owner = 1,
Admin,
Moderator,
Member,
Muted,
Custom,
};
Q_ENUM(Types)
};
/**
* @class UserListModel
*
* This class defines the model for listing the users in a room.
*
* As well as gathering all the users from a room, the model ensures that they are
* sorted in alphabetical order.
*
* @sa NeoChatRoom
*/
class UserListModel : public QAbstractListModel
{
Q_OBJECT
/**
* @brief The room that the model is getting its users from.
*/
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
public:
/**
* @brief Defines the model roles.
*/
enum EventRoles {
NameRole = Qt::UserRole + 1,
UserIdRole,
AvatarRole,
ObjectRole,
PowerLevelRole,
PowerLevelStringRole,
NameRole = Qt::UserRole + 1, /**< The user's display name in the current room. */
UserIdRole, /**< Matrix ID of the user. */
AvatarRole, /**< The source URL for the user's avatar in the current room. */
ObjectRole, /**< The QObject for the user. */
PowerLevelRole, /**< The user's power level in the current room. */
PowerLevelStringRole, /**< The name of the user's power level in the current room. */
};
UserListModel(QObject *parent = nullptr);
@@ -52,11 +51,30 @@ public:
[[nodiscard]] NeoChatRoom *room() const;
void setRoom(NeoChatRoom *room);
/**
* @brief The user at the given index of the model.
*/
[[nodiscard]] Quotient::User *userAt(QModelIndex index) const;
/**
* @brief Get the given role value at the given index.
*
* @sa QAbstractItemModel::data
*/
[[nodiscard]] QVariant data(const QModelIndex &index, int role = NameRole) const override;
/**
* @brief Number of rows in the model.
*
* @sa QAbstractItemModel::rowCount
*/
[[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
/**
* @brief Returns a mapping from Role enum values to role names.
*
* @sa EventRoles, QAbstractItemModel::roleNames()
*/
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
Q_SIGNALS:
@@ -66,9 +84,8 @@ Q_SIGNALS:
private Q_SLOTS:
void userAdded(Quotient::User *user);
void userRemoved(Quotient::User *user);
void refresh(Quotient::User *user, const QVector<int> &roles = {});
void refreshAll();
void avatarChanged(Quotient::User *user, const Quotient::Room *context);
void refreshUser(Quotient::User *user, const QVector<int> &roles = {});
void refreshAllUsers();
private:
QPointer<NeoChatRoom> m_currentRoom;