1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include <QAbstractItemModel>
25 #include <QSortFilterProxyModel>
31 //! Represents the IrcUsers in a given IrcChannel.
32 /** This model is a wrapper around the nicks/IrcUsers stored in an IrcChannel. It provides a tree with two,
33 * levels, where the top-level items are the categories (such as Ops, Voiced etc), and the second-level items
34 * the actual nicks/users. Several roles are provided to access information about a nick.
36 * Note that the nicks are not sorted in any way. Use a FilteredNickModel instead.
38 class NickModel : public QAbstractItemModel {
42 enum NickModelRole { SortKeyRole = Qt::UserRole };
44 NickModel(IrcChannel *channel = 0, QObject *parent = 0);
47 virtual QModelIndex index(int row, int col, const QModelIndex &parent) const;
48 virtual QModelIndex parent(const QModelIndex &index) const;
49 virtual int rowCount(const QModelIndex &) const;
50 virtual int columnCount(const QModelIndex &) const;
51 virtual QVariant data(const QModelIndex &, int role) const;
52 virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
54 IrcChannel *ircChannel() const;
56 QModelIndex indexOfUser(IrcUser *) const;
57 int categoryFromModes(const QString &modes) const;
58 int categoryFromIndex(const QModelIndex &index) const;
59 int userCategory(IrcUser *) const;
62 void setIrcChannel(IrcChannel *chan = 0);
63 void addUser(IrcUser *);
64 void removeUser(IrcUser *);
65 void removeUser(const QModelIndex &);
66 void renameUser(IrcUser *);
67 void changeUserModes(IrcUser *);
71 IrcChannel *_ircChannel;
72 QVector<QList<IrcUser *> > users;
76 //! This ProxyModel can be used on top of a NickModel in order to provide a sorted nicklist and to hide unused categories.
77 class FilteredNickModel : public QSortFilterProxyModel {
81 FilteredNickModel(QObject *parent = 0);
82 virtual ~FilteredNickModel();
84 virtual void setSourceModel(QAbstractItemModel *model);
87 void sourceRowsInserted(const QModelIndex &, int, int);
88 void sourceRowsRemoved(const QModelIndex &, int, int);
91 virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;