X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fmessagefilter.cpp;h=c1253da8694da354308e7650247011fd0b8d2d0d;hp=4ee6b16accb4e177bf85a87eff735c4453c0f71c;hb=0d49f7e83bd1055711e66aa880f3a0d62f7eefc9;hpb=9ce42695baef3bdd6f61aaff23c4b59061e46fe6 diff --git a/src/client/messagefilter.cpp b/src/client/messagefilter.cpp index 4ee6b16a..c1253da8 100644 --- a/src/client/messagefilter.cpp +++ b/src/client/messagefilter.cpp @@ -20,28 +20,41 @@ #include "messagefilter.h" +MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent) + : QSortFilterProxyModel(parent) +{ + setSourceModel(source); +} + MessageFilter::MessageFilter(MessageModel *source, const QList &buffers, QObject *parent) : QSortFilterProxyModel(parent), - _bufferList(buffers) + _validBuffers(buffers.toSet()) { setSourceModel(source); - } QString MessageFilter::idString() const { - if(_bufferList.isEmpty()) return "*"; - QString idstr; - QStringList bufids; - foreach(BufferId id, _bufferList) bufids << QString(id.toInt()); - bufids.sort(); - foreach(QString id, bufids) idstr += id + '|'; - idstr.chop(1); - return idstr; + if(_validBuffers.isEmpty()) + return "*"; + + QList bufferIds = _validBuffers.toList();; + qSort(bufferIds); + + QStringList bufferIdStrings; + foreach(BufferId id, bufferIds) + bufferIdStrings << QString::number(id.toInt()); + + return bufferIdStrings.join("|"); } bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); - if(_bufferList.isEmpty()) return true; + if(_validBuffers.isEmpty()) + return true; + BufferId id = sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value(); - return _bufferList.contains(id); + if(!id.isValid()) { + return true; + } + return _validBuffers.contains(id); }