From 3ed952db9ec3e51c465bacb9aa53d57e3b7f40fa Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 15 Apr 2023 08:15:23 +0000 Subject: [PATCH] Document emojimodel --- src/models/emojimodel.h | 109 +++++++++++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 23 deletions(-) diff --git a/src/models/emojimodel.h b/src/models/emojimodel.h index 58674a65b..bb9e06bcf 100644 --- a/src/models/emojimodel.h +++ b/src/models/emojimodel.h @@ -51,12 +51,30 @@ struct Emoji { Q_DECLARE_METATYPE(Emoji) +/** + * @class EmojiModel + * + * This class defines the model for visualising a list of emojis. + */ class EmojiModel : public QAbstractListModel { Q_OBJECT + /** + * @brief Return a list of recently used emojis. + */ Q_PROPERTY(QVariantList history READ history NOTIFY historyChanged) + + /** + * @brief Return a list of emoji categories. + * + * @note No custom emoji categories will be included. + */ Q_PROPERTY(QVariantList categories READ categories CONSTANT) + + /** + * @brief Return a list of emoji categories with custom emojis. + */ Q_PROPERTY(QVariantList categoriesWithCustom READ categoriesWithCustom CONSTANT) public: @@ -66,47 +84,92 @@ public: return _instance; } + /** + * @brief Defines the model roles. + */ enum RoleNames { - ShortNameRole = Qt::DisplayRole, - UnicodeRole, - InvalidRole = 50, - DisplayRole = 51, - ReplacedTextRole = 52, - DescriptionRole = 53, + ShortNameRole = Qt::DisplayRole, /**< The name of the emoji. */ + UnicodeRole, /**< The unicode character of the emoji. */ + InvalidRole = 50, /**< Invalid, reserved. */ + DisplayRole = 51, /**< The display text for an emoji. */ + ReplacedTextRole = 52, /**< The text to replace the short name with (i.e. the unicode character). */ + DescriptionRole = 53, /**< The long description of an emoji. */ }; Q_ENUM(RoleNames); + /** + * @brief Defines the potential categories an emoji can be placed in. + */ enum Category { - Custom, - Search, - SearchNoCustom, - History, - HistoryNoCustom, - Smileys, - People, - Nature, - Food, - Activities, - Travel, - Objects, - Symbols, - Flags, - Component, + Custom, /**< A custom user emoji. */ + Search, /**< The results of a filter. */ + SearchNoCustom, /**< The results of a filter with no custom emojis. */ + History, /**< Recently used emojis. */ + HistoryNoCustom, /**< Recently used emojis with no custom emojis. */ + Smileys, /**< Smileys & emotion emojis. */ + People, /**< People & Body emojis. */ + Nature, /**< Animals & Nature emojis. */ + Food, /**< Food & Drink emojis. */ + Activities, /**< Activities emojis. */ + Travel, /**< Travel & Places emojis. */ + Objects, /**< Objects emojis. */ + Symbols, /**< Symbols emojis. */ + Flags, /**< Flags emojis. */ + Component, /**< ??? */ }; Q_ENUM(Category) - [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; + /** + * @brief Get the given role value at the given index. + * + * @sa QAbstractItemModel::data + */ [[nodiscard]] QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) 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 RoleNames, QAbstractItemModel::roleNames() + */ [[nodiscard]] QHash roleNames() const override; - Q_INVOKABLE QVariantList history() const; + /** + * @brief Return a filtered list of emojis. + * + * @note This includes custom emojis, use filterModelNoCustom to return a result + * without custom emojis. + * + * @sa filterModelNoCustom + */ Q_INVOKABLE static QVariantList filterModel(const QString &filter, bool limit = true); + + /** + * @brief Return a filtered list of emojis without custom emojis. + * + * @note Use filterModel to return a result with custom emojis. + * + * @sa filterModel + */ Q_INVOKABLE static QVariantList filterModelNoCustom(const QString &filter, bool limit = true); + /** + * @brief Return a list of emojis for the given category. + */ Q_INVOKABLE QVariantList emojis(Category category) const; + /** + * @brief Return a list of emoji tones for the given base emoji. + */ Q_INVOKABLE QVariantList tones(const QString &baseEmoji) const; + Q_INVOKABLE QVariantList history() const; QVariantList categories() const; QVariantList categoriesWithCustom() const;