Stores all private chat messages and provides the source for filtering. More...
Header: | #include <PrivateMessageModel> |
Inherits: | QAbstractListModel |
PrivateMessageModel(QObject *parent = nullptr) | |
void | appendMessage(const PrivateMessagePayload &msg) |
void | clear() |
const QList<PrivateMessagePayload> & | 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 |
PrivateMessageModel is a QAbstractListModel that holds a list of PrivateMessagePayload objects, representing one-on-one direct messages between users. It is not exposed directly to QML; instead, it is consumed internally by PrivateMessageProxyModel, which filters messages by user and is exposed to the UI through the ClientManager.
The model supports prepending new messages, clearing its contents, and retrieving the full internal list for use by message controllers or proxies.
Private Variables
m_messages (QList<PrivateMessagePayload>)
— Stores private messages in reverse-chronological orderSee also PrivateMessageProxyModel.
[explicit]
PrivateMessageModel::PrivateMessageModel(QObject *parent = nullptr)Constructs an empty private message model.
parent is the optional QObject parent.
[invokable]
void PrivateMessageModel::appendMessage(const PrivateMessagePayload &msg)Prepends a private message msg to the model.
New messages appear at the top of the list.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
Clears all private messages from the model.
[override virtual]
QVariant PrivateMessageModel::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 the given role.
This includes fields such as sender, recipient, and timestamp. Returns an invalid QVariant if the index is out of bounds.
Returns a const reference to the internal message list.
[override virtual]
QHash<int, QByteArray> PrivateMessageModel::roleNames() constReimplements: QAbstractItemModel::roleNames() const.
Returns a mapping from role IDs to QML role names.
This allows QML views to bind to message properties like username
, message
, etc.
[override virtual]
int PrivateMessageModel::rowCount(const QModelIndex &parent = QModelIndex()) constReimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
Returns the number of messages in the model.
parent is unused in this flat list implementation.