Exposes a list of available public channels to QML and C++. More...
Header: | #include <ChannelModel> |
Inherits: | QAbstractListModel |
ChannelModel(QObject *parent = nullptr) | |
void | addChannels(const QList<ChannelPayload> &channels) |
void | clear() |
ChannelPayload | get(int index) 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 |
ChannelModel maintains a collection of ChannelPayload objects that represent public chat channels the user may join. This model is primarily used to populate views such as channel sidebars, dropdowns, or tab lists in the chat UI.
The model supports bulk insertion of channels, retrieving metadata for a specific index, and complete clearing of the internal channel list.
Private Variables
m_channels (QList<ChannelPayload>)
– Holds all currently known channels received from the server.See also ChannelPayload.
[explicit]
ChannelModel::ChannelModel(QObject *parent = nullptr)Constructs an empty ChannelModel.
This constructor is used to create the model instance, typically within a view model or controller class. It does not populate any data initially.
parent is the optional QObject parent.
[invokable]
void ChannelModel::addChannels(const QList<ChannelPayload> &channels)Appends the given list of channels to the model.
This emits the appropriate signals for attached views to update accordingly.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[invokable]
void ChannelModel::clear()Removes all channels from the model.
This resets the model, clearing all internal data and notifying any attached views.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[override virtual]
QVariant ChannelModel::data(const QModelIndex &index, int role = Qt::DisplayRole) constReimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.
Returns the data at index for the given role.
This includes channel ID, name, description, sort order, and the raw payload object. If the index is invalid, an invalid QVariant is returned.
[invokable]
ChannelPayload ChannelModel::get(int index) constReturns the channel at index as a ChannelPayload.
If the index is out of bounds, an empty ChannelPayload is returned.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[override virtual]
QHash<int, QByteArray> ChannelModel::roleNames() constReimplements: QAbstractItemModel::roleNames() const.
Returns a mapping of role enums to QML-visible role names.
These names are used when binding model roles in QML views.
[override virtual]
int ChannelModel::rowCount(const QModelIndex &parent = QModelIndex()) constReimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
Returns the number of channels in the model.
parent is unused in this implementation because the model is flat.
This function is used by view components to determine the number of entries to display.