Communi  3.0.0
A cross-platform IRC framework written with Qt
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Macros Groups Pages
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Properties | List of all members
IrcBufferModel Class Reference

Keeps track of buffers. 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 (IrcBuffer *buffer)
 
void aboutToBeRemoved (IrcBuffer *buffer)
 
void added (IrcBuffer *buffer)
 
void messageIgnored (IrcMessage *message)
 
void removed (IrcBuffer *buffer)
 

Public Member Functions

 IrcBufferModel (QObject *parent=0)
 
virtual ~IrcBufferModel ()
 
Q_INVOKABLE IrcBufferadd (const QString &title)
 
Q_INVOKABLE void add (IrcBuffer *buffer)
 
IrcBufferbuffer (const QModelIndex &index) const
 
Q_INVOKABLE bool contains (const QString &title) const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
Q_INVOKABLE IrcBufferfind (const QString &title) const
 
Q_INVOKABLE IrcBufferget (int index) const
 
QModelIndex index (IrcBuffer *buffer) const
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const
 
Q_INVOKABLE int indexOf (IrcBuffer *buffer) const
 
Q_INVOKABLE void remove (const QString &title)
 
Q_INVOKABLE void remove (IrcBuffer *buffer)
 
QHash< int, QByteArrayroleNames () const
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 

Protected Slots

virtual IrcBuffercreateBuffer (const QString &title)
 
virtual IrcChannelcreateChannel (const QString &title)
 

Protected Member Functions

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

Properties

IrcBuffer bufferPrototype
 
QList< IrcBuffer * > buffers
 
IrcChannel channelPrototype
 
QStringList channels
 
IrcConnection connection
 
int count
 
Irc::DataRole displayRole
 
IrcNetwork network
 
Irc::SortMethod sortMethod
 
Qt::SortOrder sortOrder
 

Detailed Description

IrcBufferModel automatically keeps track of channel and query buffers and manages IrcBuffer instances for them. It will notify via signals when channel and query buffers are added and/or removed. IrcBufferModel can be used directly as a data model for Qt's item views - both in C++ and QML.

IrcConnection* connection = new IrcConnection(this);
IrcBufferModel* model = new IrcBufferModel(connection);
connect(model, SIGNAL(added(IrcBuffer*)), this, SLOT(onBufferAdded(IrcBuffer*)));
connect(model, SIGNAL(removed(IrcBuffer*)), this, SLOT(onBufferRemoved(IrcBuffer*)));
listView->setModel(model);

Constructor & Destructor Documentation

IrcBufferModel::IrcBufferModel ( QObject parent = 0)
explicit

Constructs a new model with parent.

Note
If parent is an instance of IrcConnection, it will be automatically assigned to connection.
IrcBufferModel::~IrcBufferModel ( )
virtual

Destructs the model.

Member Function Documentation

void IrcBufferModel::aboutToBeAdded ( IrcBuffer buffer)
signal

This signal is emitted just before a buffer is added to the list of buffers.

void IrcBufferModel::aboutToBeRemoved ( IrcBuffer buffer)
signal

This signal is emitted just before a buffer is removed from the list of buffers.

IrcBuffer * IrcBufferModel::add ( const QString title)

Adds a buffer with title to the model and returns it.

void IrcBufferModel::add ( IrcBuffer buffer)

Adds the buffer to the model.

void IrcBufferModel::added ( IrcBuffer buffer)
signal

This signal is emitted when a buffer is added to the list of buffers.

IrcBuffer * IrcBufferModel::buffer ( const QModelIndex index) const

Returns the buffer for model index.

void IrcBufferModel::clear ( )
slot

Clears the model.

All buffers except persistent buffers are removed and destroyed.

In order to remove a persistent buffer, either explicitly call remove() or delete the buffer.

bool IrcBufferModel::contains ( const QString title) const

Returns true if the model contains title.

IrcBuffer * IrcBufferModel::createBuffer ( const QString title)
protectedvirtualslot

Creates a buffer object with title.

IrcBufferModel will automatically call this factory method when a need for the buffer object occurs ie. a private message is received.

The default implementation creates an instance of the buffer prototype. Reimplement this function in order to alter the default behavior.

See Also
bufferPrototype
IrcChannel * IrcBufferModel::createChannel ( const QString title)
protectedvirtualslot

Creates a channel object with title.

IrcBufferModel will automatically call this factory method when a need for the channel object occurs ie. a channel is being joined.

The default implementation creates an instance of the channel prototype. Reimplement this function in order to alter the default behavior.

See Also
channelPrototype
QVariant IrcBufferModel::data ( const QModelIndex index,
int  role = Qt::DisplayRole 
) const

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

IrcBuffer * IrcBufferModel::find ( const QString title) const

Returns the buffer object for title or 0 if not found.

IrcBuffer * IrcBufferModel::get ( int  index) const

Returns the buffer object at index.

QModelIndex IrcBufferModel::index ( IrcBuffer buffer) const

Returns the model index for buffer.

QModelIndex IrcBufferModel::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 IrcBufferModel::indexOf ( IrcBuffer buffer) const

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

bool IrcBufferModel::lessThan ( IrcBuffer one,
IrcBuffer 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 IrcBufferModel::messageIgnored ( IrcMessage message)
signal

This signal is emitted when a message was ignored.

IrcBufferModel handles only buffer specific messages and delivers them to the appropriate IrcBuffer instances. When applications decide to handle IrcBuffer::messageReceived(), this signal makes it easy to implement handling for the rest, non-buffer specific messages.

See Also
IrcConnection::messageReceived(), IrcBuffer::messageReceived()
void IrcBufferModel::remove ( const QString title)

Removes and destroys a buffer with title from the model.

void IrcBufferModel::remove ( IrcBuffer buffer)

Removes and destroys a buffer from the model.

void IrcBufferModel::removed ( IrcBuffer buffer)
signal

This signal is emitted when a buffer is removed from the list of buffers.

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

The following role names are provided by default:

Role Name Type Example
Qt::DisplayRole "display" 1) -
Irc::BufferRole "buffer" IrcBuffer* <object>
Irc::ChannelRole "channel" IrcChannel* <object>
Irc::NameRole "name" QString "communi"
Irc::PrefixRole "prefix" QString "#"
Irc::TitleRole "title" QString "#communi"

1) The type depends on displayRole.

Reimplemented from QAbstractItemModel.

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

Returns the number of buffers.

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

Sorts the model using the given order.

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

Sorts the model using the given method and order.

See Also
lessThan()

Property Documentation

IrcBuffer * IrcBufferModel::bufferPrototype
readwrite

This property holds the buffer prototype.

The prototype is used by the default implementation of createBuffer().

Note
The prototype must have an invokable constructor.
Access functions:
QList< IrcBuffer * > IrcBufferModel::buffers
read

This property holds the list of buffers.

Access function:
Notifier signal:
IrcChannel * IrcBufferModel::channelPrototype
readwrite

This property holds the channel prototype.

The prototype is used by the default implementation of createChannel().

Note
The prototype must have an invokable constructor.
Access functions:
QStringList IrcBufferModel::channels
read

This property holds the list of channel names.

Access function:
Notifier signal:
IrcConnection * IrcBufferModel::connection
readwrite

This property holds the connection.

Access functions:
Warning
Changing the connection on the fly is not supported.
int IrcBufferModel::count
read

This property holds the number of buffers.

Access function:
  • int count() const
Notifier signal:
  • void countChanged(int count)
Irc::DataRole IrcBufferModel::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:
IrcNetwork * IrcBufferModel::network
read

This property holds the network.

Access functions:
Irc::SortMethod IrcBufferModel::sortMethod
readwrite

This property holds the model sort method.

The default value is Irc::SortByHand.

Method Description Example
Irc::SortByHand Buffers are not sorted automatically, but only by calling sort(). -
Irc::SortByName Buffers are sorted alphabetically, ignoring any channel prefix. "bot", "#communi", "#freenode", "jpnurmi", "#qt"
Irc::SortByTitle Buffers are sorted alphabetically, and channels before queries. "#communi", "#freenode", "#qt", "bot", "jpnurmi"
Access functions:
See Also
sort(), lessThan()
Qt::SortOrder IrcBufferModel::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()