Fixed custom Views
[quassel.git] / src / client / nickmodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef _NICKMODEL_H_
22 #define _NICKMODEL_H_
23
24 #include <QAbstractItemModel>
25 #include <QSortFilterProxyModel>
26 #include <QVector>
27
28 class IrcChannel;
29 class IrcUser;
30
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.
35  *
36  *  Note that the nicks are not sorted in any way. Use a FilteredNickModel instead.
37  */
38 class NickModel : public QAbstractItemModel {
39   Q_OBJECT
40
41   public:
42     enum NickModelRole { SortKeyRole = Qt::UserRole };
43
44     NickModel(IrcChannel *channel = 0, QObject *parent = 0);
45     virtual ~NickModel();
46
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;
53
54     IrcChannel *ircChannel() const;
55
56     QModelIndex indexOfUser(IrcUser *) const;
57     int categoryFromModes(const QString &modes) const;
58     int categoryFromIndex(const QModelIndex &index) const;
59     int userCategory(IrcUser *) const;
60
61   public slots:
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 *);
68
69   private:
70
71     IrcChannel *_ircChannel;
72     QVector<QList<IrcUser *> > users;
73
74 };
75
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 {
78   Q_OBJECT
79
80   public:
81     FilteredNickModel(QObject *parent = 0);
82     virtual ~FilteredNickModel();
83
84     virtual void setSourceModel(QAbstractItemModel *model);
85
86   private slots:
87     void sourceRowsInserted(const QModelIndex &, int, int);
88     void sourceRowsRemoved(const QModelIndex &, int, int);
89
90   protected:
91     virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
92
93 };
94
95 #endif