Communi  3.7.0
A cross-platform IRC framework written with Qt
Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
IrcUserModel Class Reference

Keeps track of channel users. More...

#include <IrcUserModel>

Inherits QAbstractListModel.

Public Slots

void clear ()
 
void sort (int column=0, Qt::SortOrder order=Qt::AscendingOrder) override
 
void sort (Irc::SortMethod method, Qt::SortOrder order=Qt::AscendingOrder)
 

Signals

void aboutToBeAdded (IrcUser *user)
 
void aboutToBeRemoved (IrcUser *user)
 
void added (IrcUser *user)
 
void removed (IrcUser *user)
 

Public Member Functions

 IrcUserModel (QObject *parent=nullptr)
 
 ~IrcUserModel () override
 
IrcChannelchannel () const
 
Q_INVOKABLE bool contains (const QString &name) const
 
int count () const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
Irc::DataRole displayRole () const
 
Q_INVOKABLE IrcUserfind (const QString &name) const
 
Q_INVOKABLE IrcUserget (int index) const
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const override
 
QModelIndex index (IrcUser *user) const
 
Q_INVOKABLE int indexOf (IrcUser *user) const
 
QStringList names () const
 
QHash< int, QByteArray > roleNames () const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
Irc::SortMethod sortMethod () const
 
Qt::SortOrder sortOrder () const
 
QStringList titles () const
 
IrcUseruser (const QModelIndex &index) const
 
QList< IrcUser * > users () const
 

Protected Member Functions

virtual bool lessThan (IrcUser *one, IrcUser *another, Irc::SortMethod method) const
 

Properties

bool empty
 

Detailed Description

In order to keep track of channel users, create an instance of IrcUserModel. It will notify via signals when users are added and/or removed. IrcUserModel can be used directly as a data model for Qt's item views - both in C++ and QML.

void ChatView::setChannel(IrcChannel* channel)
{
IrcUserModel* model = new IrcUserModel(channel);
connect(model, SIGNAL(added(IrcUser*)), this, SLOT(onUserAdded(IrcUser*)));
connect(model, SIGNAL(removed(IrcUser*)), this, SLOT(onUserRemoved(IrcUser*)));
nickCompleter->setModel(model);
userListView->setModel(model);
}
Keeps track of channel status.
Definition: ircchannel.h:41
Keeps track of channel users.
Definition: ircusermodel.h:46
void added(IrcUser *user)
IrcUserModel(QObject *parent=nullptr)
Definition: ircusermodel.cpp:282
void removed(IrcUser *user)
Keeps track of user status on a channel.
Definition: ircuser.h:43

Constructor & Destructor Documentation

◆ IrcUserModel()

IrcUserModel::IrcUserModel ( QObject *  parent = nullptr)
explicit

Constructs a new model with parent.

Note
If parent is an instance of IrcChannel, it will be automatically assigned to channel.

◆ ~IrcUserModel()

IrcUserModel::~IrcUserModel ( )
override

Destructs the model.

Member Function Documentation

◆ aboutToBeAdded

void IrcUserModel::aboutToBeAdded ( IrcUser user)
signal

This signal is emitted just before a user is added to the list of users.

◆ aboutToBeRemoved

void IrcUserModel::aboutToBeRemoved ( IrcUser user)
signal

This signal is emitted just before a user is removed from the list of users.

◆ added

void IrcUserModel::added ( IrcUser user)
signal

This signal is emitted when a user is added to the list of users.

◆ channel()

IrcChannel * IrcUserModel::channel ( ) const

This property holds the channel.

Access functions:
Notifier signal:

◆ clear

void IrcUserModel::clear ( )
slot

Clears the model.

◆ contains()

bool IrcUserModel::contains ( const QString &  name) const

Returns true if the model contains name.

◆ count()

int IrcUserModel::count ( ) const

This property holds the number of users on the channel.

Access function:
  • int count() const
Notifier signal:
  • void countChanged(int count)

◆ data()

QVariant IrcUserModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
override

Returns the data for specified role referred to by the index.

See also
Irc::DataRole, roleNames()

◆ displayRole()

Irc::DataRole IrcUserModel::displayRole ( ) const

This property holds the display role.

The specified data role is returned for Qt::DisplayRole.

The default value is Irc::TitleRole.

Access functions:

◆ find()

IrcUser * IrcUserModel::find ( const QString &  name) const

Returns the user object for name or 0 if not found.

◆ get()

IrcUser * IrcUserModel::get ( int  index) const

Returns the user object at index.

◆ index() [1/2]

QModelIndex IrcUserModel::index ( int  row,
int  column = 0,
const QModelIndex &  parent = QModelIndex() 
) const
override

Returns the index of the item in the model specified by the given row, column and parent index.

◆ index() [2/2]

QModelIndex IrcUserModel::index ( IrcUser user) const

Returns the model index for user.

◆ indexOf()

int IrcUserModel::indexOf ( IrcUser user) const

Returns the index of the specified user, or -1 if the model does not contain the user.

◆ lessThan()

bool IrcUserModel::lessThan ( IrcUser one,
IrcUser another,
Irc::SortMethod  method 
) const
protectedvirtual

Returns true if one buffer is "less than" another, otherwise returns false.

The default implementation sorts according to the specified sort method. Reimplement this function in order to customize the sort order.

See also
sort(), sortMethod

◆ names()

QStringList IrcUserModel::names ( ) const

This property holds the list of names in alphabetical order.

Access function:
  • QStringList names() const
Notifier signal:
  • void namesChanged(const QStringList& names)

◆ removed

void IrcUserModel::removed ( IrcUser user)
signal

This signal is emitted when a user is removed from the list of users.

◆ roleNames()

QHash< int, QByteArray > IrcUserModel::roleNames ( ) const
override

The following role names are provided by default:

Role Name Type Example
Qt::DisplayRole "display" 1) -
Irc::UserRole "user" IrcUser* <object>
Irc::NameRole "name" QString "jpnurmi"
Irc::PrefixRole "prefix" QString "@"
Irc::ModeRole "mode" QString "o"
Irc::TitleRole "title" QString "@jpnurmi"

1) The type depends on displayRole.

◆ rowCount()

int IrcUserModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
override

Returns the number of users on the channel.

◆ sort [1/2]

void IrcUserModel::sort ( int  column = 0,
Qt::SortOrder  order = Qt::AscendingOrder 
)
overrideslot

Sorts the model using the given order.

◆ sort [2/2]

void IrcUserModel::sort ( Irc::SortMethod  method,
Qt::SortOrder  order = Qt::AscendingOrder 
)
slot

Sorts the model using the given method and order.

See also
lessThan()

◆ sortMethod()

Irc::SortMethod IrcUserModel::sortMethod ( ) const

This property holds the model sort method.

The default value is Irc::SortByHand.

Method Description Example
Irc::SortByHand Users are not sorted automatically, but only by calling sort(). -
Irc::SortByName Users are sorted alphabetically, ignoring any mode prefix. "bot", "@ChanServ", "jpnurmi", "+qtassistant"
Irc::SortByTitle Users are sorted alphabetically, and special users (operators, voiced users) before normal users. "@ChanServ", "+qtassistant", "bot", "jpnurmi"
Irc::SortByActivity Users are sorted based on their activity, last active and mentioned (1) users first. -

1) For performance reasons, IrcUserModel does not scan the whole channel messages to find out if a channel user was mentioned. IrcUserModel merely checks if channel messages begin with the name of a user in the model.

Access functions:
See also
sort(), lessThan()

◆ sortOrder()

Qt::SortOrder IrcUserModel::sortOrder ( ) const

This property holds the model sort order.

The default value is Qt::AscendingOrder.

Access functions:
  • Qt::SortOrder sortOrder() const
  • void setSortOrder(Qt::SortOrder order)
See also
sort(), lessThan()

◆ titles()

QStringList IrcUserModel::titles ( ) const
Since
3.3

This property holds the list of titles.

Access function:
  • QStringList titles() const
Notifier signal:
  • void titlesChanged(const QStringList& titles)

◆ user()

IrcUser * IrcUserModel::user ( const QModelIndex &  index) const

Returns the user for model index.

◆ users()

QList< IrcUser * > IrcUserModel::users ( ) const

This property holds the list of users.

The order of users is kept as sent from the server.

Access function:
Notifier signal:
  • void usersChanged(const QList<IrcUser*>& users)

Property Documentation

◆ empty

bool IrcUserModel::empty
read
Since
3.1

This property holds the whether the model is empty.

Access function:
  • bool isEmpty() const
Notifier signal:
  • void emptyChanged(bool empty)