Communi  3.7.0
A cross-platform IRC framework written with Qt
Loading...
Searching...
No Matches
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Properties | List of all members
IrcBufferModel Class Reference

Keeps track of buffers. More...

#include <IrcBufferModel>

Inherits QAbstractListModel.

Public Slots

void clear ()
 
void receiveMessage (IrcMessage *message)
 
void sort (int column=0, Qt::SortOrder order=Qt::AscendingOrder) override
 
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=nullptr)
 
 ~IrcBufferModel () override
 
Q_INVOKABLE IrcBufferadd (const QString &title)
 
Q_INVOKABLE void add (IrcBuffer *buffer)
 
IrcBufferbuffer (const QModelIndex &index) const
 
IrcBufferbufferPrototype () const
 
QList< IrcBuffer * > buffers () const
 
IrcChannelchannelPrototype () const
 
QStringList channels () const
 
IrcConnectionconnection () const
 
Q_INVOKABLE bool contains (const QString &title) const
 
int count () const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
Irc::DataRole displayRole () const
 
Q_INVOKABLE IrcBufferfind (const QString &title) const
 
Q_INVOKABLE IrcBufferget (int index) const
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const override
 
QModelIndex index (IrcBuffer *buffer) const
 
Q_INVOKABLE int indexOf (IrcBuffer *buffer) const
 
int joinDelay () const
 
IrcNetworknetwork () 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, QByteArray > roleNames () const override
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
Q_INVOKABLE QByteArray saveState (int version=0) const
 
Irc::SortMethod sortMethod () const
 
Qt::SortOrder sortOrder () 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

bool empty
 
bool monitorEnabled
 
bool persistent
 

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);
Keeps track of buffers.
Definition ircbuffermodel.h:48
void added(IrcBuffer *buffer)
void removed(IrcBuffer *buffer)
Keeps track of buffer status.
Definition ircbuffer.h:50
Provides means to establish a connection to an IRC server.
Definition ircconnection.h:49

Constructor & Destructor Documentation

◆ IrcBufferModel()

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

Constructs a new model with parent.

Note
If parent is an instance of IrcConnection, it will be automatically assigned to connection.

◆ ~IrcBufferModel()

IrcBufferModel::~IrcBufferModel ( )
override

Destructs the model.

Member Function Documentation

◆ aboutToBeAdded

void IrcBufferModel::aboutToBeAdded ( IrcBuffer buffer)
signal

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

◆ aboutToBeRemoved

void IrcBufferModel::aboutToBeRemoved ( IrcBuffer buffer)
signal

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

◆ add() [1/2]

IrcBuffer * IrcBufferModel::add ( const QString &  title)

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

◆ add() [2/2]

void IrcBufferModel::add ( IrcBuffer buffer)

Adds the buffer to the model.

◆ added

void IrcBufferModel::added ( IrcBuffer buffer)
signal

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

◆ buffer()

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

Returns the buffer for model index.

◆ bufferPrototype()

IrcBuffer * IrcBufferModel::bufferPrototype ( ) const

This property holds the buffer prototype.

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

Note
A custom buffer prototype must reimplement IrcBuffer::clone().
Access functions:

◆ buffers()

QList< IrcBuffer * > IrcBufferModel::buffers ( ) const

This property holds the list of buffers.

Access function:
Notifier signal:
  • void buffersChanged(const QList<IrcBuffer*>& buffers)

◆ channelPrototype()

IrcChannel * IrcBufferModel::channelPrototype ( ) const

This property holds the channel prototype.

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

Note
A custom channel prototype must reimplement IrcChannel::clone().
Access functions:

◆ channels()

QStringList IrcBufferModel::channels ( ) const

This property holds the list of channel names.

Access function:
  • QStringList channels() const
Notifier signal:
  • void channelsChanged(const QStringList& channels)

◆ clear

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.

◆ connection()

IrcConnection * IrcBufferModel::connection ( ) const

This property holds the connection.

Access functions:
Warning
Changing the connection on the fly is not supported.

◆ contains()

bool IrcBufferModel::contains ( const QString &  title) const

Returns true if the model contains title.

◆ count()

int IrcBufferModel::count ( ) const

This property holds the number of buffers.

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

◆ createBuffer

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

◆ createChannel

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

◆ data()

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

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

◆ displayRole()

Irc::DataRole IrcBufferModel::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()

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

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

◆ get()

IrcBuffer * IrcBufferModel::get ( int  index) const

Returns the buffer object at index.

◆ index() [1/2]

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

Returns the model index for buffer.

◆ indexOf()

int IrcBufferModel::indexOf ( IrcBuffer buffer) const

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

◆ joinDelay()

int IrcBufferModel::joinDelay ( ) const
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)

◆ lessThan()

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

◆ messageIgnored

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()

◆ network()

IrcNetwork * IrcBufferModel::network ( ) const

This property holds the network.

Access functions:

◆ receiveMessage

void IrcBufferModel::receiveMessage ( IrcMessage message)
slot

Makes the model receive and handle message.

◆ remove() [1/2]

void IrcBufferModel::remove ( const QString &  title)

Removes and destroys a buffer with title from the model.

◆ remove() [2/2]

void IrcBufferModel::remove ( IrcBuffer buffer)

Removes and destroys a buffer from the model.

◆ removed

void IrcBufferModel::removed ( IrcBuffer buffer)
signal

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

◆ restoreState()

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()

◆ roleNames()

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

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.

◆ rowCount()

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

Returns the number of buffers.

◆ saveState()

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().

◆ sort [1/2]

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

Sorts the model using the given order.

◆ sort [2/2]

void IrcBufferModel::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 IrcBufferModel::sortMethod ( ) const

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", "#libera", "jpnurmi", "#qt"
Irc::SortByTitle Buffers are sorted alphabetically, and channels before queries. "#communi", "#libera", "#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()

◆ sortOrder()

Qt::SortOrder IrcBufferModel::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()

Property Documentation

◆ empty

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)

◆ monitorEnabled

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

◆ persistent

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)