Finishing the renaming of the BufferTreeView, since SVN doesn't allow
[quassel.git] / src / client / nickmodel.cpp
index a3e7692..801a5cc 100644 (file)
@@ -5,7 +5,7 @@
  *   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        *
@@ -50,6 +50,7 @@ void NickModel::setIrcChannel(IrcChannel *channel) {
   _ircChannel = channel;
   reset();
   if(_ircChannel) {
+    connect(channel, SIGNAL(destroyed()), this, SLOT(setIrcChannel()));
     connect(channel, SIGNAL(ircUserJoined(IrcUser *)), this, SLOT(addUser(IrcUser *)));
     connect(channel, SIGNAL(ircUserParted(IrcUser *)), this, SLOT(removeUser(IrcUser *)));
     connect(channel, SIGNAL(ircUserNickSet(IrcUser *, QString)), this, SLOT(renameUser(IrcUser *)));
@@ -60,7 +61,6 @@ void NickModel::setIrcChannel(IrcChannel *channel) {
       addUser(ircuser);
     }
   }
-
 }
 
 QVariant NickModel::headerData(int section, Qt::Orientation orientation, int role) const {
@@ -214,7 +214,7 @@ void NickModel::removeUser(const QModelIndex &index) {
   endRemoveRows();
 }
 
-void NickModel::renameUser(IrcUser *user) {
+void NickModel::renameUser(IrcUser *user) { //qDebug() << "renaming" << user->nick();
   QModelIndex index = indexOfUser(user);
   emit dataChanged(index, index);
 }
@@ -241,6 +241,16 @@ FilteredNickModel::FilteredNickModel(QObject *parent) : QSortFilterProxyModel(pa
 
 }
 
+FilteredNickModel::~FilteredNickModel() {
+
+}
+
+void FilteredNickModel::setSourceModel(QAbstractItemModel *model) {
+  QSortFilterProxyModel::setSourceModel(model);
+  connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceRowsInserted(const QModelIndex &, int, int)));
+  connect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int)));
+}
+
 // Hide empty categories
 bool FilteredNickModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
   if(!source_parent.isValid()) {
@@ -250,3 +260,19 @@ bool FilteredNickModel::filterAcceptsRow(int source_row, const QModelIndex &sour
   return true;
 }
 
+void FilteredNickModel::sourceRowsInserted(const QModelIndex &index, int start, int end) {
+  if(!index.isValid()) return;
+  if(sourceModel()->rowCount(index) <= end - start + 1) {
+    // category no longer empty
+    invalidateFilter();
+  }
+}
+
+void FilteredNickModel::sourceRowsRemoved(const QModelIndex &index, int, int) {
+  if(!index.isValid()) return;
+  if(sourceModel()->rowCount(index) == 0) {
+    // category is now empty!
+    invalidateFilter();
+  }
+}
+