X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fnickmodel.cpp;h=2827890e7346a4e304335a9358ff6c5d7f2b259f;hp=a1e8bcd36b8d89128387c76c296ab94ae4607fa3;hb=2e6dc76ae100a6b8e1b1661e422995f90083500e;hpb=eaa92c3648f551569e504971ebc75021a7e3e720 diff --git a/src/client/nickmodel.cpp b/src/client/nickmodel.cpp index a1e8bcd3..2827890e 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 * @@ -194,14 +194,14 @@ int NickModel::categoryFromIndex(const QModelIndex &index) const { return index.internalId(); } -void NickModel::addUser(IrcUser *user) { //qDebug() << "adding" << user->nick(); +void NickModel::addUser(IrcUser *user) { int cat = userCategory(user); beginInsertRows(createIndex(cat-1, 0, 0), 0, 0); users[cat-1].prepend(user); endInsertRows(); } -void NickModel::removeUser(IrcUser *user) { //qDebug() << "removing" << user->nick(); +void NickModel::removeUser(IrcUser *user) { // we don't know for sure which category this user was in, so we have to search QModelIndex index = indexOfUser(user); removeUser(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(); + } +} +