Document publicroomlistmodel

This commit is contained in:
James Graham
2023-04-15 09:00:49 +00:00
parent 6438977964
commit 516b1cff88
2 changed files with 78 additions and 21 deletions

View File

@@ -12,6 +12,11 @@ PublicRoomListModel::PublicRoomListModel(QObject *parent)
{ {
} }
Quotient::Connection *PublicRoomListModel::connection() const
{
return m_connection;
}
void PublicRoomListModel::setConnection(Connection *conn) void PublicRoomListModel::setConnection(Connection *conn)
{ {
if (m_connection == conn) { if (m_connection == conn) {
@@ -47,6 +52,11 @@ void PublicRoomListModel::setConnection(Connection *conn)
Q_EMIT hasMoreChanged(); Q_EMIT hasMoreChanged();
} }
QString PublicRoomListModel::server() const
{
return m_server;
}
void PublicRoomListModel::setServer(const QString &value) void PublicRoomListModel::setServer(const QString &value)
{ {
if (m_server == value) { if (m_server == value) {
@@ -76,6 +86,11 @@ void PublicRoomListModel::setServer(const QString &value)
Q_EMIT hasMoreChanged(); Q_EMIT hasMoreChanged();
} }
QString PublicRoomListModel::keyword() const
{
return m_keyword;
}
void PublicRoomListModel::setKeyword(const QString &value) void PublicRoomListModel::setKeyword(const QString &value)
{ {
if (m_keyword == value) { if (m_keyword == value) {

View File

@@ -13,54 +13,96 @@ namespace Quotient
class Connection; class Connection;
} }
/**
* @class PublicRoomListModel
*
* This class defines the model for visualising a list of public rooms.
*
* The model finds the public rooms visible to the given server (which doesn't have
* to be the user's home server) and can also apply a filter if desired.
*
* Due to the fact that the public room list could be huge the model is lazily loaded
* and requires that the next batch of rooms be manually called.
*/
class PublicRoomListModel : public QAbstractListModel class PublicRoomListModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
/**
* @brief The current connection that the model is getting its rooms from.
*/
Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged) Q_PROPERTY(Quotient::Connection *connection READ connection WRITE setConnection NOTIFY connectionChanged)
/**
* @brief The server to get the public room list from.
*/
Q_PROPERTY(QString server READ server WRITE setServer NOTIFY serverChanged) Q_PROPERTY(QString server READ server WRITE setServer NOTIFY serverChanged)
/**
* @brief The filter keyword for the list of public rooms.
*/
Q_PROPERTY(QString keyword READ keyword WRITE setKeyword NOTIFY keywordChanged) Q_PROPERTY(QString keyword READ keyword WRITE setKeyword NOTIFY keywordChanged)
/**
* @brief Whether the model has more items to load.
*/
Q_PROPERTY(bool hasMore READ hasMore NOTIFY hasMoreChanged) Q_PROPERTY(bool hasMore READ hasMore NOTIFY hasMoreChanged)
public: public:
/**
* @brief Defines the model roles.
*/
enum EventRoles { enum EventRoles {
NameRole = Qt::DisplayRole + 1, NameRole = Qt::DisplayRole + 1, /**< The name of the room. */
AvatarRole, AvatarRole, /**< The source URL for the room's avatar. */
TopicRole, TopicRole, /**< The room topic. */
RoomIDRole, RoomIDRole, /**< The room matrix ID. */
AliasRole, AliasRole, /**< The room canonical alias. */
MemberCountRole, MemberCountRole, /**< The number of members in the room. */
AllowGuestsRole, AllowGuestsRole, /**< Whether the room allows guest users. */
WorldReadableRole, WorldReadableRole, /**< Whether the room events can be seen by non-members. */
IsJoinedRole, IsJoinedRole, /**< Whether the local user has joined the room. */
}; };
PublicRoomListModel(QObject *parent = nullptr); PublicRoomListModel(QObject *parent = nullptr);
/**
* @brief Get the given role value at the given index.
*
* @sa QAbstractItemModel::data
*/
[[nodiscard]] QVariant data(const QModelIndex &index, int role = NameRole) const override; [[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; [[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; [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] Quotient::Connection *connection() const [[nodiscard]] Quotient::Connection *connection() const;
{
return m_connection;
}
void setConnection(Quotient::Connection *conn); void setConnection(Quotient::Connection *conn);
[[nodiscard]] QString server() const [[nodiscard]] QString server() const;
{
return m_server;
}
void setServer(const QString &value); void setServer(const QString &value);
[[nodiscard]] QString keyword() const [[nodiscard]] QString keyword() const;
{
return m_keyword;
}
void setKeyword(const QString &value); void setKeyword(const QString &value);
[[nodiscard]] bool hasMore() const; [[nodiscard]] bool hasMore() const;
/**
* @brief Load the next set of rooms.
*
* @param count the maximum number of rooms to load.
*/
Q_INVOKABLE void next(int count = 50); Q_INVOKABLE void next(int count = 50);
private: private: