Exposes a list of chat messages in a given channel. More...
Header: | #include <ChatMessageModel> |
Inherits: | QAbstractListModel |
ChatMessageModel(QObject *parent = nullptr) | |
void | appendMessage(const ChatMessagePayload &msg) |
void | clear() |
const QList<ChatMessagePayload> & | messages() const |
virtual QVariant | data(const QModelIndex &index, int role = Qt::DisplayRole) const override |
virtual QHash<int, QByteArray> | roleNames() const override |
virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
ChatMessageModel is a QAbstractListModel that holds a collection of ChatMessagePayload objects. It provides role-based access to properties like message ID, sender, channel, and authored time. This model is typically used in combination with ChannelMessageProxyModel to display only messages relevant to a specific channel.
Messages can be appended from either C++ or QML, and the model supports full clearing and retrieval of the raw backing list.
Private Variables
m_messages (QList<ChatMessagePayload>)
– Internal list of all messages stored in reverse-chronological order.See also ChannelMessageProxyModel and ChatMessagePayload.
[explicit]
ChatMessageModel::ChatMessageModel(QObject *parent = nullptr)Constructs an empty ChatMessageModel instance.
parent is the optional QObject parent.
[invokable]
void ChatMessageModel::appendMessage(const ChatMessagePayload &msg)Appends a new chat message msg to the top of the model.
This inserts the message in reverse-chronological order (most recent first).
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
Removes all messages from the model.
This is typically used during disconnection or channel switching.
[override virtual]
QVariant ChatMessageModel::data(const QModelIndex &index, int role = Qt::DisplayRole) constReimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.
Returns the data for the message at index for a given role.
This includes properties such as ID, username, channel name, and message body. Returns an invalid QVariant if the index is out of range.
Returns a const reference to the internal message list.
This allows controller classes to inspect or iterate over the full model contents.
[override virtual]
QHash<int, QByteArray> ChatMessageModel::roleNames() constReimplements: QAbstractItemModel::roleNames() const.
Returns a mapping from role values to their corresponding QML role names.
This is used by QML delegates to access message properties directly in views.
[override virtual]
int ChatMessageModel::rowCount(const QModelIndex &parent = QModelIndex()) constReimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
Returns the number of messages in the model.
This is used by QML views to determine how many items to render. parent is unused for flat list models.