Document customemojimodel

This commit is contained in:
James Graham
2023-04-14 12:57:05 +00:00
parent fe064c0ef8
commit a807cc6143

View File

@@ -17,19 +17,29 @@ struct CustomEmoji {
Q_PROPERTY(QString name MEMBER name) Q_PROPERTY(QString name MEMBER name)
}; };
/**
* @class CustomEmojiModel
*
* This class defines the model for custom user emojis.
*
* This is based upon the im.ponies.user_emotes spec (MSC2545).
*/
class CustomEmojiModel : public QAbstractListModel class CustomEmojiModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
/**
* @brief Defines the model roles.
*/
enum Roles { enum Roles {
Name = Qt::DisplayRole, Name = Qt::DisplayRole, /**< The name of the emoji. */
ImageURL, ImageURL, /**< The URL for the custom emoji. */
ModelData, // for emulating the regular emoji model's usage, otherwise the UI code would get too complicated ModelData, /**< for emulating the regular emoji model's usage, otherwise the UI code would get too complicated. */
MxcUrl = 50, MxcUrl = 50, /**< The mxc source URL for the custom emoji. */
DisplayRole = 51, DisplayRole = 51, /**< The name of the emoji. For compatibility with EmojiModel. */
ReplacedTextRole = 52, ReplacedTextRole = 52, /**< The name of the emoji. For compatibility with EmojiModel. */
DescriptionRole = 53, // also invalid, reserved DescriptionRole = 53, /**< Invalid, reserved. For compatibility with EmojiModel. */
}; };
Q_ENUM(Roles); Q_ENUM(Roles);
@@ -39,14 +49,45 @@ public:
return _instance; return _instance;
} }
/**
* @brief Get the given role value at the given index.
*
* @sa QAbstractItemModel::data
*/
QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override;
/**
* @brief Number of rows in the model.
*
* @sa QAbstractItemModel::rowCount
*/
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
/**
* @brief Returns a mapping from Role enum values to role names.
*
* @sa Roles, QAbstractItemModel::roleNames()
*/
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
/**
* @brief Substitute any custom emojis for an image in the input text.
*/
Q_INVOKABLE QString preprocessText(const QString &it); Q_INVOKABLE QString preprocessText(const QString &it);
/**
* @brief Return a list of custom emojis where the name contains the filter text.
*/
Q_INVOKABLE QVariantList filterModel(const QString &filter); Q_INVOKABLE QVariantList filterModel(const QString &filter);
/**
* @brief Add a new emoji to the model.
*/
Q_INVOKABLE void addEmoji(const QString &name, const QUrl &location); Q_INVOKABLE void addEmoji(const QString &name, const QUrl &location);
/**
* @brief Remove an emoji from the model.
*/
Q_INVOKABLE void removeEmoji(const QString &name); Q_INVOKABLE void removeEmoji(const QString &name);
private: private: