X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fnickmodel.cpp;h=efde51288e50357da77216aa58b3e9b48beef984;hp=a3e7692f9a6f44d049e57643fc06232fdc1b2003;hb=57ce4f437b29e538c80029d57f39efdbb9afb328;hpb=fb1c465a71b110984d59722bbf0ed873674daf94 diff --git a/src/client/nickmodel.cpp b/src/client/nickmodel.cpp index a3e7692f..efde5128 100644 --- a/src/client/nickmodel.cpp +++ b/src/client/nickmodel.cpp @@ -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 * @@ -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 { @@ -178,7 +178,7 @@ int NickModel::userCategory(IrcUser *user) const { int NickModel::categoryFromModes(const QString &modes) const { int cat; - // we hardcode this even though we have PREFIX in networkinfo... but that wouldn't help with mapping modes to + // we hardcode this even though we have PREFIX in network... but that wouldn't help with mapping modes to // category strings anyway. if(modes.contains('q')) cat = 1; else if(modes.contains('a')) cat = 2; @@ -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(); + } +} +