* 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 *
_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 *)));
addUser(ircuser);
}
}
-
}
QVariant NickModel::headerData(int section, Qt::Orientation orientation, int role) const {
endRemoveRows();
}
-void NickModel::renameUser(IrcUser *user) {
+void NickModel::renameUser(IrcUser *user) { //qDebug() << "renaming" << user->nick();
QModelIndex index = indexOfUser(user);
emit dataChanged(index, index);
}
}
+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()) {
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();
+ }
+}
+