Filters chat messages by channel name using a QSortFilterProxyModel. More...
Header: | #include <ChannelMessageProxyModel> |
Inherits: | QSortFilterProxyModel |
ChannelMessageProxyModel(QObject *parent = nullptr) | |
QString | channel() const |
QString | channelName() const |
QVariantMap | get(int row) const |
void | setChannel(const QString &name) |
void | channelChanged() |
virtual bool | filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override |
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.
Private Variables
m_channel (QString)
– The name of the channel currently used to filter messages.See also ChannelPayload and ChatMessageModel.
[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.
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) constReimplements: 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) constReturns 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.
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().