From 6cc773426fc496174048d0c5f2f0fc200ecbd73a Mon Sep 17 00:00:00 2001 From: James Graham Date: Thu, 13 Apr 2023 17:35:44 +0000 Subject: [PATCH] Document completionmodel Document completionmodel and remove unnecessary includes --- src/models/completionmodel.cpp | 1 - src/models/completionmodel.h | 73 ++++++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/src/models/completionmodel.cpp b/src/models/completionmodel.cpp index cdc877ef2..6eb754548 100644 --- a/src/models/completionmodel.cpp +++ b/src/models/completionmodel.cpp @@ -5,7 +5,6 @@ #include #include "actionsmodel.h" -#include "chatdocumenthandler.h" #include "completionproxymodel.h" #include "customemojimodel.h" #include "emojimodel.h" diff --git a/src/models/completionmodel.h b/src/models/completionmodel.h index 429c82954..fe7945d91 100644 --- a/src/models/completionmodel.h +++ b/src/models/completionmodel.h @@ -13,41 +13,89 @@ class UserListModel; class NeoChatRoom; class RoomListModel; +/** + * @class CompletionModel + * + * This class defines the model for suggesting completions in chat text. + * + * This model is able to select the appropriate completion type for the input text + * and present a list of options that can be presented to the user. + */ class CompletionModel : public QAbstractListModel { Q_OBJECT + + /** + * @brief The current text to search for completions. + */ Q_PROPERTY(QString text READ text NOTIFY textChanged) + + /** + * @brief The current room that the model is getting completions for. + */ Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) + + /** + * @brief The current type of completion being done on the entered text. + * + * @sa AutoCompletionType + */ Q_PROPERTY(AutoCompletionType autoCompletionType READ autoCompletionType NOTIFY autoCompletionTypeChanged); + + /** + * @brief The RoomListModel to be used for room completions. + */ Q_PROPERTY(RoomListModel *roomListModel READ roomListModel WRITE setRoomListModel NOTIFY roomListModelChanged); public: + /** + * @brief Defines the different types of completion available. + */ enum AutoCompletionType { - User, - Room, - Emoji, - Command, - None, + User, /**< A user in the current room. */ + Room, /**< A matrix room. */ + Emoji, /**< An emoji. */ + Command, /**< A / command. */ + None, /**< No available completion for the current text. */ }; Q_ENUM(AutoCompletionType) + /** + * @brief Defines the model roles. + */ enum Roles { - Text = Qt::DisplayRole, - Subtitle, - Icon, - ReplacedText, + Text = Qt::DisplayRole, /**< The main text to show. */ + Subtitle, /**< The subtitle text to show. */ + Icon, /**< The icon to show. */ + ReplacedText, /**< The text to replace the input text with for the completion. */ }; Q_ENUM(Roles); CompletionModel(QObject *parent = nullptr); - int rowCount(const QModelIndex &parent = QModelIndex()) const override; + /** + * @brief Get the given role value at the given index. + * + * @sa QAbstractItemModel::data + */ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + /** + * @brief Number of rows in the model. + * + * @sa QAbstractItemModel::rowCount + */ + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + /** + * @brief Returns a mapping from Role enum values to role names. + * + * @sa EventRoles, QAbstractItemModel::roleNames() + */ QHash roleNames() const override; QString text() const; void setText(const QString &text, const QString &fullText); - void updateCompletion(); NeoChatRoom *room() const; void setRoom(NeoChatRoom *room); @@ -56,6 +104,7 @@ public: void setRoomListModel(RoomListModel *roomListModel); AutoCompletionType autoCompletionType() const; + void setAutoCompletionType(AutoCompletionType autoCompletionType); Q_SIGNALS: void textChanged(); @@ -70,7 +119,7 @@ private: NeoChatRoom *m_room = nullptr; AutoCompletionType m_autoCompletionType = None; - void setAutoCompletionType(AutoCompletionType autoCompletionType); + void updateCompletion(); UserListModel *m_userListModel; RoomListModel *m_roomListModel;