Document completionmodel
Document completionmodel and remove unnecessary includes
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include "actionsmodel.h"
|
#include "actionsmodel.h"
|
||||||
#include "chatdocumenthandler.h"
|
|
||||||
#include "completionproxymodel.h"
|
#include "completionproxymodel.h"
|
||||||
#include "customemojimodel.h"
|
#include "customemojimodel.h"
|
||||||
#include "emojimodel.h"
|
#include "emojimodel.h"
|
||||||
|
|||||||
@@ -13,41 +13,89 @@ class UserListModel;
|
|||||||
class NeoChatRoom;
|
class NeoChatRoom;
|
||||||
class RoomListModel;
|
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
|
class CompletionModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The current text to search for completions.
|
||||||
|
*/
|
||||||
Q_PROPERTY(QString text READ text NOTIFY textChanged)
|
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)
|
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);
|
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);
|
Q_PROPERTY(RoomListModel *roomListModel READ roomListModel WRITE setRoomListModel NOTIFY roomListModelChanged);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Defines the different types of completion available.
|
||||||
|
*/
|
||||||
enum AutoCompletionType {
|
enum AutoCompletionType {
|
||||||
User,
|
User, /**< A user in the current room. */
|
||||||
Room,
|
Room, /**< A matrix room. */
|
||||||
Emoji,
|
Emoji, /**< An emoji. */
|
||||||
Command,
|
Command, /**< A / command. */
|
||||||
None,
|
None, /**< No available completion for the current text. */
|
||||||
};
|
};
|
||||||
Q_ENUM(AutoCompletionType)
|
Q_ENUM(AutoCompletionType)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Defines the model roles.
|
||||||
|
*/
|
||||||
enum Roles {
|
enum Roles {
|
||||||
Text = Qt::DisplayRole,
|
Text = Qt::DisplayRole, /**< The main text to show. */
|
||||||
Subtitle,
|
Subtitle, /**< The subtitle text to show. */
|
||||||
Icon,
|
Icon, /**< The icon to show. */
|
||||||
ReplacedText,
|
ReplacedText, /**< The text to replace the input text with for the completion. */
|
||||||
};
|
};
|
||||||
Q_ENUM(Roles);
|
Q_ENUM(Roles);
|
||||||
|
|
||||||
CompletionModel(QObject *parent = nullptr);
|
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;
|
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<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
void setText(const QString &text, const QString &fullText);
|
void setText(const QString &text, const QString &fullText);
|
||||||
void updateCompletion();
|
|
||||||
|
|
||||||
NeoChatRoom *room() const;
|
NeoChatRoom *room() const;
|
||||||
void setRoom(NeoChatRoom *room);
|
void setRoom(NeoChatRoom *room);
|
||||||
@@ -56,6 +104,7 @@ public:
|
|||||||
void setRoomListModel(RoomListModel *roomListModel);
|
void setRoomListModel(RoomListModel *roomListModel);
|
||||||
|
|
||||||
AutoCompletionType autoCompletionType() const;
|
AutoCompletionType autoCompletionType() const;
|
||||||
|
void setAutoCompletionType(AutoCompletionType autoCompletionType);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void textChanged();
|
void textChanged();
|
||||||
@@ -70,7 +119,7 @@ private:
|
|||||||
NeoChatRoom *m_room = nullptr;
|
NeoChatRoom *m_room = nullptr;
|
||||||
AutoCompletionType m_autoCompletionType = None;
|
AutoCompletionType m_autoCompletionType = None;
|
||||||
|
|
||||||
void setAutoCompletionType(AutoCompletionType autoCompletionType);
|
void updateCompletion();
|
||||||
|
|
||||||
UserListModel *m_userListModel;
|
UserListModel *m_userListModel;
|
||||||
RoomListModel *m_roomListModel;
|
RoomListModel *m_roomListModel;
|
||||||
|
|||||||
Reference in New Issue
Block a user