Document stickermodel

This commit is contained in:
James Graham
2023-05-08 15:39:41 +01:00
committed by Tobias Fella
parent 11343e6bdf
commit 40edfef046

View File

@@ -11,25 +11,67 @@
class ImagePacksModel;
/**
* @class StickerModel
*
* A model to visualise a set of stickers.
*
* The stickers are obtained from a Matrix image pack. See Matrix MSC2545 for more details.
* https://github.com/Sorunome/matrix-doc/blob/soru/emotes/proposals/2545-emotes.md
*/
class StickerModel : public QAbstractListModel
{
Q_OBJECT
/**
* @brief The image pack that the stickers come from.
*
* @sa ImagePacksModel
*/
Q_PROPERTY(ImagePacksModel *model READ model WRITE setModel NOTIFY modelChanged)
/**
* @brief The index of the pack in the ImagePacksModel.
*
* @sa ImagePacksModel
*/
Q_PROPERTY(int packIndex READ packIndex WRITE setPackIndex NOTIFY packIndexChanged)
/**
* @brief The current room that the model is being used in.
*/
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
public:
/**
* @brief Defines the model roles.
*/
enum Roles {
Url = Qt::UserRole + 1,
Body,
Url = Qt::UserRole + 1, /**< The source mxc URL for the image. */
Body, /**< The image caption, if any. */
};
explicit StickerModel(QObject *parent = nullptr);
[[nodiscard]] int rowCount(const QModelIndex &index) const override;
/**
* @brief Get the given role value at the given index.
*
* @sa QAbstractItemModel::data
*/
[[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
/**
* @brief Number of rows in the model.
*
* @sa QAbstractItemModel::rowCount
*/
[[nodiscard]] int rowCount(const QModelIndex &index) const override;
/**
* @brief Returns a mapping from Role enum values to role names.
*
* @sa Roles, QAbstractItemModel::roleNames()
*/
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] ImagePacksModel *model() const;
@@ -41,6 +83,9 @@ public:
[[nodiscard]] NeoChatRoom *room() const;
void setRoom(NeoChatRoom *room);
/**
* @brief Post the sticker at the given index as an event in the room.
*/
Q_INVOKABLE void postSticker(int index);
Q_SIGNALS: