X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fclient%2Fnickmodel.h;h=4baa1117b1f3555178b29dc5feed0486230ac5df;hb=8699dd758516d0ded076811e8ea656adc95e69d0;hp=313c67811758246a80b60296bbcc95728067ef73;hpb=b173301cf898a31c19835f0512883b3ac15cdf55;p=quassel.git diff --git a/src/client/nickmodel.h b/src/client/nickmodel.h index 313c6781..4baa1117 100644 --- a/src/client/nickmodel.h +++ b/src/client/nickmodel.h @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by the Quassel IRC Team * + * Copyright (C) 2005-08 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -22,47 +22,73 @@ #define _NICKMODEL_H_ #include +#include +#include class IrcChannel; +class IrcUser; -/* -//! Represents a single IrcUser within a NickTreeModel. -class NickTreeItem : public TreeItem { +//! Represents the IrcUsers in a given IrcChannel. +/** This model is a wrapper around the nicks/IrcUsers stored in an IrcChannel. It provides a tree with two, + * levels, where the top-level items are the categories (such as Ops, Voiced etc), and the second-level items + * the actual nicks/users. Several roles are provided to access information about a nick. + * + * Note that the nicks are not sorted in any way. Use a FilteredNickModel instead. + */ +class NickModel : public QAbstractItemModel { Q_OBJECT public: - NickTreeItem(IrcUser *ircuser, TreeItem *parent = 0); + enum NickModelRole { SortKeyRole = Qt::UserRole }; - //virtual QVariant data(int column, int row) const; - - private: + NickModel(IrcChannel *channel = 0, QObject *parent = 0); + virtual ~NickModel(); -}; + virtual QModelIndex index(int row, int col, const QModelIndex &parent) const; + virtual QModelIndex parent(const QModelIndex &index) const; + virtual int rowCount(const QModelIndex &) const; + virtual int columnCount(const QModelIndex &) const; + virtual QVariant data(const QModelIndex &, int role) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; -//! Represents a group of nicks, such as Ops, Voiced etc. -class NickTreeGroupItem : public TreeItem { - Q_OBJECT + IrcChannel *ircChannel() const; - public: - NickTreeGroupItem(const QString &title, TreeItem *parent = 0); + QModelIndex indexOfUser(IrcUser *) const; + int categoryFromModes(const QString &modes) const; + int categoryFromIndex(const QModelIndex &index) const; + int userCategory(IrcUser *) const; - //virtual QVariant data(int column, int row) const; + public slots: + void setIrcChannel(IrcChannel *chan = 0); + void addUser(IrcUser *); + void removeUser(IrcUser *); + void removeUser(const QModelIndex &); + void renameUser(IrcUser *); + void changeUserModes(IrcUser *); private: + IrcChannel *_ircChannel; + QVector > users; + }; -*/ -//! Represents the IrcUsers in a given IrcChannel. -class NickModel : public QAbstractItemModel { +//! This ProxyModel can be used on top of a NickModel in order to provide a sorted nicklist and to hide unused categories. +class FilteredNickModel : public QSortFilterProxyModel { Q_OBJECT public: - NickModel(IrcChannel *); - virtual ~NickModel(); + FilteredNickModel(QObject *parent = 0); + virtual ~FilteredNickModel(); - private: - + virtual void setSourceModel(QAbstractItemModel *model); + + private slots: + void sourceRowsInserted(const QModelIndex &, int, int); + void sourceRowsRemoved(const QModelIndex &, int, int); + + protected: + virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; };