Communi  3.4.0
A cross-platform IRC framework written with Qt
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 receiveMessage (IrcMessage *message)
 
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)
 
Q_INVOKABLE bool restoreState (const QByteArray &state, int version=0)
 
QHash< int, QByteArrayroleNames () const
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
Q_INVOKABLE QByteArray saveState (int version=0) 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
 
bool empty
 
int joinDelay
 
bool monitorEnabled
 
IrcNetwork network
 
bool persistent
 
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::receiveMessage ( IrcMessage message)
slot

Makes the model receive and handle message.

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.

bool IrcBufferModel::restoreState ( const QByteArray state,
int  version = 0 
)
Since
3.1

Restores the state of the model. The version number is compared with that stored in state. If they do not match, the model state is left unchanged, and this function returns false; otherwise, the state is restored, and true is returned.

See also
saveState()
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.

QByteArray IrcBufferModel::saveState ( int  version = 0) const
Since
3.1

Saves the state of the model. The version number is stored as part of the state data.

To restore the saved state, pass the return value and version number to restoreState().

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:
bool IrcBufferModel::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)
int IrcBufferModel::joinDelay
readwrite
Since
3.3

This property holds the join delay in seconds.

The default value is 0 - channels are joined immediately after getting connected. A negative value disables automatic joining of channels.

Access function:
  • int joinDelay() const
  • void setJoinDelay(int delay)
Notifier signal:
  • void joinDelayChanged(int delay)
bool IrcBufferModel::monitorEnabled
readwrite
Since
3.4

This property holds whether automatic monitor is enabled.

The default value is false.

Access function:
  • bool isMonitorEnabled() const
  • void setMonitorEnabled(bool enabled)
Notifier signal:
  • void monitorEnabledChanged(bool enabled)
See also
IRCv3 support
IrcNetwork * IrcBufferModel::network
read

This property holds the network.

Access functions:
bool IrcBufferModel::persistent
readwrite
Since
3.1

This property holds whether the model is persistent.

The default value is false.

A persistent model does not remove and destruct channel buffers automatically when leaving the corresponding channels. In order to remove buffers from a persistent model, either call IrcBufferModel::remove() or delete the buffer.

Access functions:
  • bool isPersistent() const
  • void setPersistent(bool persistent)
Notifier signal:
  • void persistentChanged(bool persistent)
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"
Irc::SortByActivity Buffers are sorted based on their messaging activity, last active buffers first. -
Note
Irc::SortByActivity support was added in version 3.4.
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()