Mudlet  0
Mudclient
IrcBufferModel Class Reference

#include <IrcBufferModel>

+ Inheritance diagram for IrcBufferModel:

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 countChanged (int count)
 
void emptyChanged (bool empty)
 
void added (IrcBuffer *buffer)
 
void removed (IrcBuffer *buffer)
 
void aboutToBeAdded (IrcBuffer *buffer)
 
void aboutToBeRemoved (IrcBuffer *buffer)
 
void persistentChanged (bool persistent)
 
void buffersChanged (const QList< IrcBuffer *> &buffers)
 
void channelsChanged (const QStringList &channels)
 
void connectionChanged (IrcConnection *connection)
 
void networkChanged (IrcNetwork *network)
 
void messageIgnored (IrcMessage *message)
 
void bufferPrototypeChanged (IrcBuffer *prototype)
 
void channelPrototypeChanged (IrcChannel *prototype)
 
void destroyed (IrcBufferModel *model)
 
void joinDelayChanged (int delay)
 
void monitorEnabledChanged (bool enabled)
 

Public Member Functions

 IrcBufferModel (QObject *parent=0)
 
virtual ~IrcBufferModel ()
 
IrcConnectionconnection () const
 
void setConnection (IrcConnection *connection)
 
IrcNetworknetwork () const
 
int count () const
 
bool isEmpty () const
 
QStringList channels () const
 
QList< IrcBuffer * > buffers () const
 
Q_INVOKABLE IrcBufferget (int index) const
 
Q_INVOKABLE IrcBufferfind (const QString &title) const
 
Q_INVOKABLE bool contains (const QString &title) const
 
Q_INVOKABLE int indexOf (IrcBuffer *buffer) const
 
Q_INVOKABLE IrcBufferadd (const QString &title)
 
Q_INVOKABLE void add (IrcBuffer *buffer)
 
Q_INVOKABLE void remove (const QString &title)
 
Q_INVOKABLE void remove (IrcBuffer *buffer)
 
Qt::SortOrder sortOrder () const
 
void setSortOrder (Qt::SortOrder order)
 
Irc::SortMethod sortMethod () const
 
void setSortMethod (Irc::SortMethod method)
 
Irc::DataRole displayRole () const
 
void setDisplayRole (Irc::DataRole role)
 
bool isPersistent () const
 
void setPersistent (bool persistent)
 
QModelIndex index (IrcBuffer *buffer) const
 
IrcBufferbuffer (const QModelIndex &index) const
 
QHash< int, QByteArray > roleNames () const
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
QModelIndex index (int row, int column=0, const QModelIndex &parent=QModelIndex()) const
 
IrcBufferbufferPrototype () const
 
void setBufferPrototype (IrcBuffer *prototype)
 
IrcChannelchannelPrototype () const
 
void setChannelPrototype (IrcChannel *prototype)
 
int joinDelay () const
 
void setJoinDelay (int delay)
 
bool isMonitorEnabled () const
 
void setMonitorEnabled (bool enabled)
 
Q_INVOKABLE QByteArray saveState (int version=0) const
 
Q_INVOKABLE bool restoreState (const QByteArray &state, int version=0)
 

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

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

Private Member Functions

 Q_PRIVATE_SLOT (d_func(), void _irc_connected()) Q_PRIVATE_SLOT(d_func()
 
void _irc_initialized ()) Q_PRIVATE_SLOT(d_func()
 
void void _irc_disconnected ()) Q_PRIVATE_SLOT(d_func()
 
void void void _irc_bufferDestroyed (IrcBuffer *)) Q_PRIVATE_SLOT(d_func()
 
void void void void _irc_restoreBuffers ()) Q_PRIVATE_SLOT(d_func()
 

Private Attributes

QScopedPointer< IrcBufferModelPrivated_ptr
 

Friends

class IrcBufferLessThan
 
class IrcBufferGreaterThan
 

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.

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

Definition at line 47 of file ircbuffermodel.h.

Constructor & Destructor Documentation

◆ IrcBufferModel()

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.

Definition at line 580 of file ircbuffermodel.cpp.

References setBufferPrototype(), setChannelPrototype(), and setConnection().

582 {
583  Q_D(IrcBufferModel);
584  d->q_ptr = this;
585  setBufferPrototype(new IrcBuffer(this));
586  setChannelPrototype(new IrcChannel(this));
587  setConnection(qobject_cast<IrcConnection*>(parent));
588 }
void setChannelPrototype(IrcChannel *prototype)
void setConnection(IrcConnection *connection)
Keeps track of channel status.
Definition: ircchannel.h:40
Keeps track of buffer status.
Definition: ircbuffer.h:49
QScopedPointer< IrcBufferModelPrivate > d_ptr
void setBufferPrototype(IrcBuffer *prototype)
Keeps track of buffers.
+ Here is the call graph for this function:

◆ ~IrcBufferModel()

IrcBufferModel::~IrcBufferModel ( )
virtual

Destructs the model.

Definition at line 593 of file ircbuffermodel.cpp.

References buffer(), connection(), and destroyed().

594 {
595  Q_D(IrcBufferModel);
596  foreach (IrcBuffer* buffer, d->bufferList) {
597  buffer->disconnect(this);
598  delete buffer;
599  }
600  d->bufferList.clear();
601  d->bufferMap.clear();
602  d->channels.clear();
603  emit destroyed(this);
604 }
IrcBuffer * buffer(const QModelIndex &index) const
Keeps track of buffer status.
Definition: ircbuffer.h:49
void destroyed(IrcBufferModel *model)
Keeps track of buffers.
+ Here is the call graph for this function:

Member Function Documentation

◆ connection()

IrcConnection* IrcBufferModel::connection ( ) const

Referenced by setConnection(), and ~IrcBufferModel().

+ Here is the caller graph for this function:

◆ setConnection()

void IrcBufferModel::setConnection ( IrcConnection connection)

Definition at line 621 of file ircbuffermodel.cpp.

References _irc_disconnected(), _irc_initialized(), connection(), connectionChanged(), count(), IrcConnection::installMessageFilter(), network(), networkChanged(), and rowCount().

Referenced by IrcBufferModel().

622 {
623  Q_D(IrcBufferModel);
624  if (d->connection != connection) {
625  if (d->connection) {
626  qCritical("IrcBufferModel::setConnection(): changing the connection on the fly is not supported.");
627  return;
628  }
629  d->connection = connection;
630  d->connection->installMessageFilter(d);
631  d->connection->installCommandFilter(d);
632  connect(d->connection, SIGNAL(connected()), this, SLOT(_irc_connected()));
633  connect(d->connection, SIGNAL(disconnected()), this, SLOT(_irc_disconnected()));
634  connect(d->connection->network(), SIGNAL(initialized()), this, SLOT(_irc_initialized()));
635  emit connectionChanged(connection);
636  emit networkChanged(network());
637  }
638 }
void networkChanged(IrcNetwork *network)
Keeps track of buffers.
void _irc_initialized()) Q_PRIVATE_SLOT(d_func()
void connectionChanged(IrcConnection *connection)
void installMessageFilter(QObject *filter)
IrcNetwork * network() const
IrcConnection * connection() const
void void _irc_disconnected()) Q_PRIVATE_SLOT(d_func()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ network()

IrcNetwork* IrcBufferModel::network ( ) const

Referenced by setConnection().

+ Here is the caller graph for this function:

◆ count()

int IrcBufferModel::count ( ) const

Referenced by setConnection().

+ Here is the caller graph for this function:

◆ isEmpty()

bool IrcBufferModel::isEmpty ( ) const

Definition at line 678 of file ircbuffermodel.cpp.

References buffers(), and channels().

679 {
680  Q_D(const IrcBufferModel);
681  return d->bufferList.isEmpty();
682 }
Keeps track of buffers.
+ Here is the call graph for this function:

◆ channels()

QStringList IrcBufferModel::channels ( ) const

Referenced by isEmpty().

+ Here is the caller graph for this function:

◆ buffers()

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

Referenced by isEmpty(), restoreState(), and saveState().

+ Here is the caller graph for this function:

◆ get()

IrcBuffer * IrcBufferModel::get ( int  index) const

Returns the buffer object at index.

Definition at line 717 of file ircbuffermodel.cpp.

718 {
719  Q_D(const IrcBufferModel);
720  return d->bufferList.value(index);
721 }
Keeps track of buffers.

◆ find()

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

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

Definition at line 726 of file ircbuffermodel.cpp.

Referenced by dlgIRC::processCustomCommand().

727 {
728  Q_D(const IrcBufferModel);
729  return d->bufferMap.value(title.toLower());
730 }
Keeps track of buffers.
+ Here is the caller graph for this function:

◆ contains()

bool IrcBufferModel::contains ( const QString title) const

Returns true if the model contains title.

Definition at line 735 of file ircbuffermodel.cpp.

736 {
737  Q_D(const IrcBufferModel);
738  return d->bufferMap.contains(title.toLower());
739 }
Keeps track of buffers.

◆ indexOf()

int IrcBufferModel::indexOf ( IrcBuffer buffer) const

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

Definition at line 745 of file ircbuffermodel.cpp.

746 {
747  Q_D(const IrcBufferModel);
748  return d->bufferList.indexOf(buffer);
749 }
Keeps track of buffers.

◆ add() [1/2]

IrcBuffer * IrcBufferModel::add ( const QString title)

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

Definition at line 754 of file ircbuffermodel.cpp.

Referenced by dlgIRC::setupBuffers(), and dlgIRC::slot_onUserActivated().

755 {
756  Q_D(IrcBufferModel);
757  return d->createBuffer(title);
758 }
Keeps track of buffers.
+ Here is the caller graph for this function:

◆ add() [2/2]

void IrcBufferModel::add ( IrcBuffer buffer)

Adds the buffer to the model.

Definition at line 763 of file ircbuffermodel.cpp.

764 {
765  Q_D(IrcBufferModel);
766  d->addBuffer(buffer);
767 }
Keeps track of buffers.

◆ remove() [1/2]

void IrcBufferModel::remove ( const QString title)

Removes and destroys a buffer with title from the model.

Definition at line 772 of file ircbuffermodel.cpp.

Referenced by dlgIRC::ircRestart().

773 {
774  Q_D(IrcBufferModel);
775  d->destroyBuffer(title, true);
776 }
Keeps track of buffers.
+ Here is the caller graph for this function:

◆ remove() [2/2]

void IrcBufferModel::remove ( IrcBuffer buffer)

Removes and destroys a buffer from the model.

Definition at line 781 of file ircbuffermodel.cpp.

References buffer(), and displayRole().

782 {
783  delete buffer;
784 }
IrcBuffer * buffer(const QModelIndex &index) const
+ Here is the call graph for this function:

◆ sortOrder()

Qt::SortOrder IrcBufferModel::sortOrder ( ) const

Referenced by buffer().

+ Here is the caller graph for this function:

◆ setSortOrder()

void IrcBufferModel::setSortOrder ( Qt::SortOrder  order)

Definition at line 881 of file ircbuffermodel.cpp.

References sort(), Irc::SortByHand, and sortMethod().

882 {
883  Q_D(IrcBufferModel);
884  if (d->sortOrder != order) {
885  d->sortOrder = order;
886  if (d->sortMethod != Irc::SortByHand && !d->bufferList.isEmpty())
887  sort(d->sortMethod, d->sortOrder);
888  }
889 }
void sort(int column=0, Qt::SortOrder order=Qt::AscendingOrder)
Keeps track of buffers.
+ Here is the call graph for this function:

◆ sortMethod()

Irc::SortMethod IrcBufferModel::sortMethod ( ) const

Referenced by setSortOrder().

+ Here is the caller graph for this function:

◆ setSortMethod()

void IrcBufferModel::setSortMethod ( Irc::SortMethod  method)

Definition at line 917 of file ircbuffermodel.cpp.

References sort(), and Irc::SortByHand.

918 {
919  Q_D(IrcBufferModel);
920  if (d->sortMethod != method) {
921  d->sortMethod = method;
922  if (d->sortMethod != Irc::SortByHand && !d->bufferList.isEmpty())
923  sort(d->sortMethod, d->sortOrder);
924  }
925 }
void sort(int column=0, Qt::SortOrder order=Qt::AscendingOrder)
Keeps track of buffers.
+ Here is the call graph for this function:

◆ displayRole()

Irc::DataRole IrcBufferModel::displayRole ( ) const

Referenced by remove().

+ Here is the caller graph for this function:

◆ setDisplayRole()

void IrcBufferModel::setDisplayRole ( Irc::DataRole  role)

Definition at line 803 of file ircbuffermodel.cpp.

804 {
805  Q_D(IrcBufferModel);
806  d->role = role;
807 }
Keeps track of buffers.

◆ isPersistent()

bool IrcBufferModel::isPersistent ( ) const

Definition at line 829 of file ircbuffermodel.cpp.

830 {
831  Q_D(const IrcBufferModel);
832  return d->persistent;
833 }
Keeps track of buffers.

◆ setPersistent()

void IrcBufferModel::setPersistent ( bool  persistent)

Definition at line 835 of file ircbuffermodel.cpp.

References persistent, and persistentChanged().

836 {
837  Q_D(IrcBufferModel);
838  if (d->persistent != persistent) {
839  d->persistent = persistent;
840  emit persistentChanged(persistent);
841  }
842 }
Keeps track of buffers.
void persistentChanged(bool persistent)

◆ index() [1/2]

QModelIndex IrcBufferModel::index ( IrcBuffer buffer) const

Returns the model index for buffer.

Definition at line 847 of file ircbuffermodel.cpp.

Referenced by dlgIRC::processCustomCommand(), dlgIRC::slot_onBufferAdded(), dlgIRC::slot_onUserActivated(), and sort().

848 {
849  Q_D(const IrcBufferModel);
850  return index(d->bufferList.indexOf(buffer));
851 }
QModelIndex index(IrcBuffer *buffer) const
Keeps track of buffers.
+ Here is the caller graph for this function:

◆ buffer()

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

Returns the buffer for model index.

Definition at line 856 of file ircbuffermodel.cpp.

References sortOrder().

Referenced by clear(), data(), remove(), saveState(), sort(), and ~IrcBufferModel().

857 {
858  if (!hasIndex(index.row(), index.column()))
859  return 0;
860 
861  return static_cast<IrcBuffer*>(index.internalPointer());
862 }
Keeps track of buffer status.
Definition: ircbuffer.h:49
QModelIndex index(IrcBuffer *buffer) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ roleNames()

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

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.

Definition at line 1112 of file ircbuffermodel.cpp.

References Irc::BufferRole, Irc::ChannelRole, Irc::NameRole, Irc::PrefixRole, and Irc::TitleRole.

1113 {
1114  QHash<int, QByteArray> roles;
1115  roles[Qt::DisplayRole] = "display";
1116  roles[Irc::BufferRole] = "buffer";
1117  roles[Irc::ChannelRole] = "channel";
1118  roles[Irc::NameRole] = "name";
1119  roles[Irc::PrefixRole] = "prefix";
1120  roles[Irc::TitleRole] = "title";
1121  return roles;
1122 }

◆ rowCount()

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

Returns the number of buffers.

Definition at line 1127 of file ircbuffermodel.cpp.

Referenced by setConnection().

1128 {
1129  if (parent.isValid())
1130  return 0;
1131 
1132  Q_D(const IrcBufferModel);
1133  return d->bufferList.count();
1134 }
Keeps track of buffers.
+ Here is the caller graph for this function:

◆ data()

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.

Definition at line 1139 of file ircbuffermodel.cpp.

References buffer(), Irc::BufferRole, Irc::ChannelRole, IrcBuffer::name, Irc::NameRole, IrcBuffer::prefix, Irc::PrefixRole, IrcBuffer::title, Irc::TitleRole, and IrcBuffer::toChannel().

1140 {
1141  Q_D(const IrcBufferModel);
1142  if (!hasIndex(index.row(), index.column(), index.parent()))
1143  return QVariant();
1144 
1145  IrcBuffer* buffer = static_cast<IrcBuffer*>(index.internalPointer());
1146  Q_ASSERT(buffer);
1147 
1148  switch (role) {
1149  case Qt::DisplayRole:
1150  return data(index, d->role);
1151  case Irc::BufferRole:
1152  return QVariant::fromValue(buffer);
1153  case Irc::ChannelRole:
1154  return QVariant::fromValue(buffer->toChannel());
1155  case Irc::NameRole:
1156  return buffer->name();
1157  case Irc::PrefixRole:
1158  return buffer->prefix();
1159  case Irc::TitleRole:
1160  return buffer->title();
1161  }
1162 
1163  return QVariant();
1164 }
QString title
Definition: ircbuffer.h:52
IrcBuffer * buffer(const QModelIndex &index) const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Q_INVOKABLE IrcChannel * toChannel()
Definition: ircbuffer.cpp:405
Keeps track of buffer status.
Definition: ircbuffer.h:49
QModelIndex index(IrcBuffer *buffer) const
QString name
Definition: ircbuffer.h:53
Keeps track of buffers.
QString prefix
Definition: ircbuffer.h:54
+ Here is the call graph for this function:

◆ index() [2/2]

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

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

Definition at line 1169 of file ircbuffermodel.cpp.

References bufferPrototype().

1170 {
1171  Q_D(const IrcBufferModel);
1172  if (!hasIndex(row, column, parent))
1173  return QModelIndex();
1174 
1175  return createIndex(row, column, d->bufferList.at(row));
1176 }
Keeps track of buffers.
+ Here is the call graph for this function:

◆ bufferPrototype()

IrcBuffer* IrcBufferModel::bufferPrototype ( ) const

Referenced by index().

+ Here is the caller graph for this function:

◆ setBufferPrototype()

void IrcBufferModel::setBufferPrototype ( IrcBuffer prototype)

Definition at line 1195 of file ircbuffermodel.cpp.

References bufferPrototypeChanged(), and channelPrototype().

Referenced by IrcBufferModel().

1196 {
1197  Q_D(IrcBufferModel);
1198  if (d->bufferProto != prototype) {
1199  if (d->bufferProto && d->bufferProto->parent() == this)
1200  delete d->bufferProto;
1201  d->bufferProto = prototype ? prototype : new IrcBuffer(this);
1202  emit bufferPrototypeChanged(d->bufferProto);
1203  }
1204 }
Keeps track of buffer status.
Definition: ircbuffer.h:49
Keeps track of buffers.
void bufferPrototypeChanged(IrcBuffer *prototype)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ channelPrototype()

IrcChannel* IrcBufferModel::channelPrototype ( ) const

Referenced by setBufferPrototype().

+ Here is the caller graph for this function:

◆ setChannelPrototype()

void IrcBufferModel::setChannelPrototype ( IrcChannel prototype)

Definition at line 1223 of file ircbuffermodel.cpp.

References channelPrototypeChanged(), and joinDelay().

Referenced by IrcBufferModel().

1224 {
1225  Q_D(IrcBufferModel);
1226  if (d->channelProto != prototype) {
1227  if (d->channelProto && d->channelProto->parent() == this)
1228  delete d->channelProto;
1229  d->channelProto = prototype ? prototype : new IrcChannel(this);
1230  emit channelPrototypeChanged(d->channelProto);
1231  }
1232 }
Keeps track of channel status.
Definition: ircchannel.h:40
void channelPrototypeChanged(IrcChannel *prototype)
Keeps track of buffers.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ joinDelay()

int IrcBufferModel::joinDelay ( ) const

Referenced by setChannelPrototype().

+ Here is the caller graph for this function:

◆ setJoinDelay()

void IrcBufferModel::setJoinDelay ( int  delay)

Definition at line 1256 of file ircbuffermodel.cpp.

References joinDelayChanged().

1257 {
1258  Q_D(IrcBufferModel);
1259  if (d->joinDelay != delay) {
1260  d->joinDelay = delay;
1261  emit joinDelayChanged(delay);
1262  }
1263 }
Keeps track of buffers.
void joinDelayChanged(int delay)

◆ isMonitorEnabled()

bool IrcBufferModel::isMonitorEnabled ( ) const

Definition at line 1282 of file ircbuffermodel.cpp.

1283 {
1284  Q_D(const IrcBufferModel);
1285  return d->monitorEnabled;
1286 }
Keeps track of buffers.

◆ setMonitorEnabled()

void IrcBufferModel::setMonitorEnabled ( bool  enabled)

Definition at line 1288 of file ircbuffermodel.cpp.

References monitorEnabledChanged().

1289 {
1290  Q_D(IrcBufferModel);
1291  if (d->monitorEnabled != enabled) {
1292  d->monitorEnabled = enabled;
1293  emit monitorEnabledChanged(enabled);
1294  }
1295 }
void monitorEnabledChanged(bool enabled)
Keeps track 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().

Definition at line 1304 of file ircbuffermodel.cpp.

References buffer(), buffers(), and IrcBuffer::title.

1305 {
1306  Q_D(const IrcBufferModel);
1307  QVariantMap args;
1308  args.insert("version", version);
1309 
1310  QVariantMap states = d->bufferStates;
1311  foreach (IrcBuffer* buffer, d->bufferList)
1312  states.insert(buffer->title(), d->saveBuffer(buffer));
1313 
1314  QVariantList buffers;
1315  foreach (const QVariant& b, states)
1316  buffers += b;
1317  args.insert("buffers", buffers);
1318 
1319  QByteArray state;
1320  QDataStream out(&state, QIODevice::WriteOnly);
1321  out << args;
1322  return state;
1323 }
QString title
Definition: ircbuffer.h:52
IrcBuffer * buffer(const QModelIndex &index) const
QList< IrcBuffer * > buffers() const
Keeps track of buffer status.
Definition: ircbuffer.h:49
Keeps track of buffers.
+ Here is the call graph for this function:

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

Definition at line 1334 of file ircbuffermodel.cpp.

References _irc_restoreBuffers(), buffers(), and IRC_END_NAMESPACE.

1335 {
1336  Q_D(IrcBufferModel);
1337  QVariantMap args;
1338  QDataStream in(state);
1339  in >> args;
1340  if (in.status() != QDataStream::Ok || args.value("version", -1).toInt() != version)
1341  return false;
1342 
1343  const QVariantList buffers = args.value("buffers").toList();
1344  foreach (const QVariant& v, buffers) {
1345  const QVariantMap b = v.toMap();
1346  d->bufferStates.insert(b.value("title").toString(), b);
1347  }
1348 
1349  if (d->joinDelay >= 0 && d->connection && d->connection->isConnected())
1350  QTimer::singleShot(d->joinDelay * 1000, this, SLOT(_irc_restoreBuffers()));
1351 
1352  return true;
1353 }
QList< IrcBuffer * > buffers() const
void void void void _irc_restoreBuffers()) Q_PRIVATE_SLOT(d_func()
Keeps track of buffers.
+ Here is the call graph for this function:

◆ 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.

Definition at line 934 of file ircbuffermodel.cpp.

References buffer(), buffersChanged(), channelsChanged(), countChanged(), emptyChanged(), IrcBuffer::isChannel(), IrcBuffer::isPersistent(), and IrcBuffer::title.

935 {
936  Q_D(IrcBufferModel);
937  if (!d->bufferList.isEmpty()) {
938  bool bufferRemoved = false;
939  bool channelRemoved = false;
940  foreach (IrcBuffer* buffer, d->bufferList) {
941  if (!buffer->isPersistent()) {
942  if (!bufferRemoved) {
943  beginResetModel();
944  bufferRemoved = true;
945  }
946  channelRemoved |= buffer->isChannel();
947  buffer->disconnect(this);
948  d->bufferList.removeOne(buffer);
949  d->channels.removeOne(buffer->title());
950  d->bufferMap.remove(buffer->title().toLower());
951  delete buffer;
952  }
953  }
954  if (bufferRemoved) {
955  endResetModel();
956  if (channelRemoved)
957  emit channelsChanged(d->channels);
958  emit buffersChanged(d->bufferList);
959  emit countChanged(d->bufferList.count());
960  if (d->bufferList.isEmpty())
961  emit emptyChanged(true);
962  }
963  }
964 }
QString title
Definition: ircbuffer.h:52
IrcBuffer * buffer(const QModelIndex &index) const
bool isPersistent() const
Definition: ircbuffer.cpp:525
Keeps track of buffer status.
Definition: ircbuffer.h:49
void buffersChanged(const QList< IrcBuffer *> &buffers)
Keeps track of buffers.
void channelsChanged(const QStringList &channels)
void countChanged(int count)
void emptyChanged(bool empty)
bool isChannel() const
Definition: ircbuffer.cpp:394
+ Here is the call graph for this function:

◆ receiveMessage

void IrcBufferModel::receiveMessage ( IrcMessage message)
slot

Makes the model receive and handle message.

Definition at line 969 of file ircbuffermodel.cpp.

970 {
971  Q_D(IrcBufferModel);
972  d->messageFilter(message);
973 }
Keeps track of buffers.

◆ sort [1/2]

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

Sorts the model using the given order.

Definition at line 978 of file ircbuffermodel.cpp.

Referenced by setSortMethod(), and setSortOrder().

979 {
980  Q_D(IrcBufferModel);
981  if (column == 0)
982  sort(d->sortMethod, order);
983 }
void sort(int column=0, Qt::SortOrder order=Qt::AscendingOrder)
Keeps track of buffers.
+ Here is the caller graph for this function:

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

Definition at line 990 of file ircbuffermodel.cpp.

References buffer(), index(), IrcBufferGreaterThan, IrcBufferLessThan, and Irc::SortByHand.

991 {
992  Q_D(IrcBufferModel);
993  if (method == Irc::SortByHand)
994  return;
995 
996  emit layoutAboutToBeChanged();
997 
998  QList<IrcBuffer*> persistentBuffers;
999  QModelIndexList oldPersistentIndexes = persistentIndexList();
1000  foreach (const QModelIndex& index, oldPersistentIndexes)
1001  persistentBuffers += static_cast<IrcBuffer*>(index.internalPointer());
1002 
1003  if (order == Qt::AscendingOrder)
1004  qSort(d->bufferList.begin(), d->bufferList.end(), IrcBufferLessThan(this, method));
1005  else
1006  qSort(d->bufferList.begin(), d->bufferList.end(), IrcBufferGreaterThan(this, method));
1007 
1008  QModelIndexList newPersistentIndexes;
1009  foreach (IrcBuffer* buffer, persistentBuffers)
1010  newPersistentIndexes += index(d->bufferList.indexOf(buffer));
1011  changePersistentIndexList(oldPersistentIndexes, newPersistentIndexes);
1012 
1013  emit layoutChanged();
1014 }
IrcBuffer * buffer(const QModelIndex &index) const
friend class IrcBufferLessThan
Keeps track of buffer status.
Definition: ircbuffer.h:49
QModelIndex index(IrcBuffer *buffer) const
Keeps track of buffers.
friend class IrcBufferGreaterThan
+ Here is the call graph for this function:

◆ countChanged

void IrcBufferModel::countChanged ( int  count)
signal

Referenced by clear().

+ Here is the caller graph for this function:

◆ emptyChanged

void IrcBufferModel::emptyChanged ( bool  empty)
signal

Referenced by clear().

+ Here is the caller graph for this function:

◆ added

void IrcBufferModel::added ( IrcBuffer buffer)
signal

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

Referenced by dlgIRC::setupBuffers().

+ Here is the caller graph for this function:

◆ removed

void IrcBufferModel::removed ( IrcBuffer buffer)
signal

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

Referenced by dlgIRC::setupBuffers().

+ Here is the caller graph for this function:

◆ 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.

◆ persistentChanged

void IrcBufferModel::persistentChanged ( bool  persistent)
signal

Referenced by setPersistent().

+ Here is the caller graph for this function:

◆ buffersChanged

void IrcBufferModel::buffersChanged ( const QList< IrcBuffer *> &  buffers)
signal

Referenced by clear().

+ Here is the caller graph for this function:

◆ channelsChanged

void IrcBufferModel::channelsChanged ( const QStringList &  channels)
signal

Referenced by clear(), and dlgIRC::setupBuffers().

+ Here is the caller graph for this function:

◆ connectionChanged

void IrcBufferModel::connectionChanged ( IrcConnection connection)
signal

Referenced by setConnection().

+ Here is the caller graph for this function:

◆ networkChanged

void IrcBufferModel::networkChanged ( IrcNetwork network)
signal

Referenced by setConnection().

+ Here is the caller graph for this function:

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

Referenced by dlgIRC::setupBuffers().

+ Here is the caller graph for this function:

◆ bufferPrototypeChanged

void IrcBufferModel::bufferPrototypeChanged ( IrcBuffer prototype)
signal

Referenced by setBufferPrototype().

+ Here is the caller graph for this function:

◆ channelPrototypeChanged

void IrcBufferModel::channelPrototypeChanged ( IrcChannel prototype)
signal

Referenced by setChannelPrototype().

+ Here is the caller graph for this function:

◆ destroyed

void IrcBufferModel::destroyed ( IrcBufferModel model)
signal

Referenced by ~IrcBufferModel().

+ Here is the caller graph for this function:

◆ joinDelayChanged

void IrcBufferModel::joinDelayChanged ( int  delay)
signal

Referenced by setJoinDelay().

+ Here is the caller graph for this function:

◆ monitorEnabledChanged

void IrcBufferModel::monitorEnabledChanged ( bool  enabled)
signal

Referenced by setMonitorEnabled().

+ Here is the caller graph for this function:

◆ 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

Definition at line 1027 of file ircbuffermodel.cpp.

1028 {
1029  Q_D(IrcBufferModel);
1030  Q_UNUSED(title);
1031  QObject* instance = d->bufferProto->metaObject()->newInstance(Q_ARG(QObject*, this));
1032  return qobject_cast<IrcBuffer*>(instance);
1033 }
Keeps track of buffer status.
Definition: ircbuffer.h:49
Keeps track of buffers.

◆ 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

Definition at line 1046 of file ircbuffermodel.cpp.

1047 {
1048  Q_D(IrcBufferModel);
1049  Q_UNUSED(title);
1050  QObject* instance = d->channelProto->metaObject()->newInstance(Q_ARG(QObject*, this));
1051  return qobject_cast<IrcChannel*>(instance);
1052 }
Keeps track of channel status.
Definition: ircchannel.h:40
Keeps track of buffers.

◆ 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

Definition at line 1063 of file ircbuffermodel.cpp.

References IrcBufferPrivate::activity, IrcNetwork::channelTypes, IrcBufferPrivate::get(), IrcBuffer::isSticky(), IrcBuffer::name, IrcBuffer::network, IrcBuffer::prefix, Irc::SortByActivity, and Irc::SortByTitle.

Referenced by IrcBufferLessThan::operator()(), and IrcBufferGreaterThan::operator()().

1064 {
1065  if (one->isSticky() != another->isSticky())
1066  return one->isSticky();
1067 
1068  if (method == Irc::SortByActivity) {
1069  QDateTime ts1 = IrcBufferPrivate::get(one)->activity;
1070  QDateTime ts2 = IrcBufferPrivate::get(another)->activity;
1071  if (ts1.isValid() || ts2.isValid())
1072  return ts1.isValid() && ts1 > ts2;
1073  }
1074 
1075  if (method == Irc::SortByTitle) {
1076  const QStringList prefixes = one->network()->channelTypes();
1077 
1078  const QString p1 = one->prefix();
1079  const QString p2 = another->prefix();
1080 
1081  const int i1 = !p1.isEmpty() ? prefixes.indexOf(p1.at(0)) : -1;
1082  const int i2 = !p2.isEmpty() ? prefixes.indexOf(p2.at(0)) : -1;
1083 
1084  if (i1 >= 0 && i2 < 0)
1085  return true;
1086  if (i1 < 0 && i2 >= 0)
1087  return false;
1088  if (i1 >= 0 && i2 >= 0 && i1 != i2)
1089  return i1 < i2;
1090  }
1091 
1092  // Irc::SortByName
1093  const QString n1 = one->name();
1094  const QString n2 = another->name();
1095  return n1.compare(n2, Qt::CaseInsensitive) < 0;
1096 }
bool isSticky() const
Definition: ircbuffer.cpp:490
static IrcBufferPrivate * get(IrcBuffer *buffer)
Definition: ircbuffer_p.h:80
QDateTime activity
Definition: ircbuffer_p.h:92
QString name
Definition: ircbuffer.h:53
IrcNetwork network
Definition: ircbuffer.h:56
QStringList channelTypes
Definition: ircnetwork.h:50
QString prefix
Definition: ircbuffer.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Q_PRIVATE_SLOT()

IrcBufferModel::Q_PRIVATE_SLOT ( d_func()  ,
void   _irc_connected() 
)
private

◆ _irc_initialized()

void IrcBufferModel::_irc_initialized ( )
private

Referenced by setConnection().

+ Here is the caller graph for this function:

◆ _irc_disconnected()

void void IrcBufferModel::_irc_disconnected ( )
private

Referenced by setConnection().

+ Here is the caller graph for this function:

◆ _irc_bufferDestroyed()

void void void IrcBufferModel::_irc_bufferDestroyed ( IrcBuffer )
private

◆ _irc_restoreBuffers()

void void void void IrcBufferModel::_irc_restoreBuffers ( )
private

Referenced by restoreState().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ IrcBufferLessThan

friend class IrcBufferLessThan
friend

Definition at line 156 of file ircbuffermodel.h.

Referenced by sort().

◆ IrcBufferGreaterThan

friend class IrcBufferGreaterThan
friend

Definition at line 157 of file ircbuffermodel.h.

Referenced by sort().

Field Documentation

◆ d_ptr

QScopedPointer<IrcBufferModelPrivate> IrcBufferModel::d_ptr
private

Definition at line 158 of file ircbuffermodel.h.

Property Documentation

◆ count

int IrcBufferModel::count
read

This property holds the number of buffers.

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

Definition at line 50 of file ircbuffermodel.h.

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

Definition at line 51 of file ircbuffermodel.h.

◆ sortOrder

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

Definition at line 52 of file ircbuffermodel.h.

◆ sortMethod

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

Definition at line 53 of file ircbuffermodel.h.

◆ channels

QStringList IrcBufferModel::channels
read

This property holds the list of channel names.

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

Definition at line 54 of file ircbuffermodel.h.

◆ displayRole

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:

Definition at line 55 of file ircbuffermodel.h.

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

Definition at line 56 of file ircbuffermodel.h.

Referenced by setPersistent().

◆ buffers

QList< IrcBuffer * > IrcBufferModel::buffers
read

This property holds the list of buffers.

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

Definition at line 57 of file ircbuffermodel.h.

Referenced by dlgIRC::slot_onBufferAdded(), and dlgIRC::slot_onUserActivated().

◆ connection

IrcConnection * IrcBufferModel::connection
readwrite

This property holds the connection.

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

Definition at line 58 of file ircbuffermodel.h.

◆ network

IrcNetwork * IrcBufferModel::network
read

This property holds the network.

Access functions:

Definition at line 59 of file ircbuffermodel.h.

Referenced by IrcChannelPrivate::init(), and IrcChannelPrivate::setUserMode().

◆ bufferPrototype

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:

Definition at line 60 of file ircbuffermodel.h.

◆ channelPrototype

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:

Definition at line 61 of file ircbuffermodel.h.

◆ joinDelay

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)

Definition at line 62 of file ircbuffermodel.h.

◆ 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

Definition at line 63 of file ircbuffermodel.h.


The documentation for this class was generated from the following files: