• ChannelMessageProxyModel
  • ChannelMessageProxyModel Class

    Filters chat messages by channel name using a QSortFilterProxyModel. More...

    Header: #include <ChannelMessageProxyModel>
    Inherits: QSortFilterProxyModel

    Public Functions

    ChannelMessageProxyModel(QObject *parent = nullptr)
    QString channel() const
    QString channelName() const
    QVariantMap get(int row) const
    void setChannel(const QString &name)

    Signals

    Reimplemented Protected Functions

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

    Detailed Description

    Overview

    ChannelMessageProxyModel provides a filtered view over the ChatMessageModel, exposing only those messages that belong to a specified channel. It is commonly used in tabbed chat UIs or side-by-side channel panes to isolate conversations by topic.

    The proxy works by matching the ChatMessageModel::ChannelRole of each message against a user-specified channel string, which can be set from C++ or QML.

    Internal Members

    Private Variables

    • m_channel (QString) – The name of the channel currently used to filter messages.

    See also ChannelPayload and ChatMessageModel.

    Member Function Documentation

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

    Constructs a new proxy for filtering messages by channel.

    Sets the filter role to ChatMessageModel::ChannelRole and enables dynamic filtering behavior when the channel name changes.

    parent is the optional QObject parent.

    QString ChannelMessageProxyModel::channel() const

    Returns the current channel name used for filtering.

    Note: Getter function for property channel.

    See also setChannel().

    [override virtual protected] bool ChannelMessageProxyModel::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 belongs to the current channel.

    This override implements the actual filtering logic by comparing the channel name of each source row against m_channel.

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

    Returns all role data at proxy row row as a QVariantMap.

    This method maps the row index from the proxy to the source model, retrieves data for all roles, and returns the values as a QML-friendly map.

    Returns an empty map if the row is invalid.

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

    void ChannelMessageProxyModel::setChannel(const QString &name)

    Updates the channel filter string to name.

    This will trigger re-evaluation of the source model and emit channelChanged() if the name has changed.

    Note: Setter function for property channel.

    See also channel().