This should fix a bug resulting in a crash, when a IrcUser object was not destroyed...
[quassel.git] / src / client / nickmodel.h
index 313c678..8a65e9d 100644 (file)
 #define _NICKMODEL_H_
 
 #include <QAbstractItemModel>
+#include <QSortFilterProxyModel>
+#include <QVector>
 
 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;
+    NickModel(IrcChannel *channel = 0, QObject *parent = 0);
+    virtual ~NickModel();
 
-  private:
+    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;
 
-};
+    IrcChannel *ircChannel() const;
 
-//! Represents a group of nicks, such as Ops, Voiced etc.
-class NickTreeGroupItem : public TreeItem {
-  Q_OBJECT
+    QModelIndex indexOfUser(IrcUser *) const;
+    int categoryFromModes(const QString &modes) const;
+    int categoryFromIndex(const QModelIndex &index) const;
+    int userCategory(IrcUser *) const;
 
-  public:
-    NickTreeGroupItem(const QString &title, TreeItem *parent = 0);
-
-    //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<QList<IrcUser *> > 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);
 
-  private:
-    
+  protected:
+    virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
 
 };