Communi  3.4.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...

Inherits QAbstractListModel.

Public Slots

void clear ()
 
void sort (int column=0, Qt::SortOrder order=Qt::AscendingOrder)
 
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=0)
 
virtual ~IrcUserModel ()
 
Q_INVOKABLE bool contains (const QString &name) const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
Q_INVOKABLE IrcUserfind (const QString &name) const
 
Q_INVOKABLE IrcUserget (int index) const
 
QModelIndex index (IrcUser *user) const
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const
 
Q_INVOKABLE int indexOf (IrcUser *user) const
 
QHash< int, QByteArrayroleNames () const
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
IrcUseruser (const QModelIndex &index) const
 

Protected Member Functions

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

Properties

IrcChannel channel
 
int count
 
Irc::DataRole displayRole
 
bool empty
 
QStringList names
 
Irc::SortMethod sortMethod
 
Qt::SortOrder sortOrder
 
QStringList titles
 
QList< IrcUser * > users
 

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);
}

Constructor & Destructor Documentation

IrcUserModel::IrcUserModel ( QObject parent = 0)
explicit

Constructs a new model with parent.

Note
If parent is an instance of IrcChannel, it will be automatically assigned to channel.
IrcUserModel::~IrcUserModel ( )
virtual

Destructs the model.

Member Function Documentation

void IrcUserModel::aboutToBeAdded ( IrcUser user)
signal

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

void IrcUserModel::aboutToBeRemoved ( IrcUser user)
signal

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

void IrcUserModel::added ( IrcUser user)
signal

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

void IrcUserModel::clear ( )
slot

Clears the model.

bool IrcUserModel::contains ( const QString name) const

Returns true if the model contains name.

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

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

See also
Irc::DataRole, roleNames()
IrcUser * IrcUserModel::find ( const QString name) const

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

IrcUser * IrcUserModel::get ( int  index) const

Returns the user object at index.

QModelIndex IrcUserModel::index ( IrcUser user) const

Returns the model index for user.

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

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

Reimplemented from QAbstractListModel.

int IrcUserModel::indexOf ( IrcUser user) const

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

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
void IrcUserModel::removed ( IrcUser user)
signal

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

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

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.

Reimplemented from QAbstractItemModel.

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

Returns the number of users on the channel.

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

Sorts the model using the given order.

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

Sorts the model using the given method and order.

See also
lessThan()
IrcUser * IrcUserModel::user ( const QModelIndex index) const

Returns the user for model index.

Property Documentation

IrcChannel * IrcUserModel::channel
readwrite

This property holds the channel.

Access functions:
Notifier signal:
int IrcUserModel::count
read

This property holds the number of users on the channel.

Access function:
  • int count() const
Notifier signal:
  • void countChanged(int count)
Irc::DataRole IrcUserModel::displayRole
readwrite

This property holds the display role.

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

The default value is Irc::TitleRole.

Access functions:
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)
QStringList IrcUserModel::names
read

This property holds the list of names in alphabetical order.

Access function:
Notifier signal:
Irc::SortMethod IrcUserModel::sortMethod
readwrite

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()
Qt::SortOrder IrcUserModel::sortOrder
readwrite

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()
QStringList IrcUserModel::titles
read
Since
3.3

This property holds the list of titles.

Access function:
Notifier signal:
QList< IrcUser * > IrcUserModel::users
read

This property holds the list of users.

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

Access function:
Notifier signal: