• PrivateMessageProxyModel
  • PrivateMessageProxyModel Class

    Filters private messages exchanged between two specific users. More...

    Header: #include <PrivateMessageProxyModel>
    Inherits: QSortFilterProxyModel

    Public Functions

    PrivateMessageProxyModel(QObject *parent = nullptr)
    QVariantMap get(int row) const
    QString myUserId() const
    void setMyUserId(const QString &id)
    void setTargetUserId(const QString &id)
    QString targetUserId() const

    Signals

    Reimplemented Protected Functions

    virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override

    Detailed Description

    Overview

    PrivateMessageProxyModel sits on top of PrivateMessageModel and filters its contents to only expose messages where either:

    • The current user is the sender and the target user is the recipient
    • Or the current user is the recipient and the target user is the sender

    This allows QML views to display private chat threads without managing filtering logic.

    Internal Members

    Private Variables

    • m_myUserId (QString) — ID of the current authenticated user
    • m_targetUserId (QString) — ID of the user on the other end of the conversation

    See also PrivateMessageModel.

    Member Function Documentation

    [explicit] PrivateMessageProxyModel::PrivateMessageProxyModel(QObject *parent = nullptr)

    Constructs a new proxy model for filtering private messages.

    [override virtual protected] bool PrivateMessageProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const

    Reimplements: QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const.

    Returns true if the message at sourceRow is between the current user and the target user.

    Both sent and received messages are accepted.

    sourceParent is the parent index for the row. For flat list models, this is typically an invalid index.

    [invokable] QVariantMap PrivateMessageProxyModel::get(int row) const

    Returns a single row as a QVariantMap, useful for QML delegate access.

    row is the index in the proxy model. Returns an empty map if the index is invalid.

    Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

    QString PrivateMessageProxyModel::myUserId() const

    Returns the ID of the current user.

    Note: Getter function for property myUserId.

    See also setMyUserId().

    void PrivateMessageProxyModel::setMyUserId(const QString &id)

    Sets the ID of the current user.

    id is the client user id.

    Calling this triggers a re-evaluation of the filter.

    Note: Setter function for property myUserId.

    See also myUserId().

    void PrivateMessageProxyModel::setTargetUserId(const QString &id)

    Sets the ID of the user being chatted with.

    id is the user id of private chat partner.

    Calling this triggers a re-evaluation of the filter.

    Note: Setter function for property targetUserId.

    See also targetUserId().

    QString PrivateMessageProxyModel::targetUserId() const

    Returns the ID of the chat partner (target user).

    Note: Getter function for property targetUserId.

    See also setTargetUserId().