2018-08-26 05:17:12 +00:00
|
|
|
#ifndef USERLISTMODEL_H
|
|
|
|
#define USERLISTMODEL_H
|
|
|
|
|
|
|
|
#include "room.h"
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QtCore/QAbstractListModel>
|
|
|
|
|
|
|
|
namespace QMatrixClient {
|
|
|
|
class Connection;
|
|
|
|
class Room;
|
|
|
|
class User;
|
|
|
|
} // namespace QMatrixClient
|
|
|
|
|
|
|
|
class UserListModel : public QAbstractListModel {
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(
|
|
|
|
QMatrixClient::Room* room READ room WRITE setRoom NOTIFY roomChanged)
|
|
|
|
public:
|
2018-09-11 05:14:56 +00:00
|
|
|
enum EventRoles { NameRole = Qt::UserRole + 1, UserIDRole, AvatarRole };
|
2018-08-26 05:17:12 +00:00
|
|
|
|
|
|
|
using User = QMatrixClient::User;
|
|
|
|
|
|
|
|
UserListModel(QObject* parent = nullptr);
|
|
|
|
|
|
|
|
QMatrixClient::Room* room() { return m_currentRoom; }
|
|
|
|
void setRoom(QMatrixClient::Room* room);
|
|
|
|
User* userAt(QModelIndex index);
|
|
|
|
|
2018-09-09 02:12:45 +00:00
|
|
|
QVariant data(const QModelIndex& index, int role = NameRole) const override;
|
2018-08-26 05:17:12 +00:00
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
|
|
|
|
|
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void roomChanged();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void userAdded(User* user);
|
|
|
|
void userRemoved(User* user);
|
|
|
|
void refresh(User* user, QVector<int> roles = {});
|
|
|
|
void avatarChanged(User* user, const QMatrixClient::Room* context);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QMatrixClient::Room* m_currentRoom;
|
|
|
|
QList<User*> m_users;
|
|
|
|
|
|
|
|
int findUserPos(User* user) const;
|
|
|
|
int findUserPos(const QString& username) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // USERLISTMODEL_H
|