X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fbufferviewfilter.cpp;h=cf3d4685a442bb4c928dfff8fbfd6ef5caf80f5b;hp=29694002adfcaacf66c783c25c3d247ba4fb9f79;hb=f9fc50a5e043668a2525a6c0903ea339d4ba05b7;hpb=d6b056e936ec441258d291b7a8af7b83f9f53016 diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index 29694002..cf3d4685 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * 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 * @@ -20,6 +20,10 @@ #include "bufferviewfilter.h" +#include + +#include "networkmodel.h" + /***************************************** * The Filter for the Tree View *****************************************/ @@ -30,10 +34,14 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, const Modes &filte { setSourceModel(model); setSortCaseSensitivity(Qt::CaseInsensitive); + + // FIXME + // ok the following basically sucks. therfore it's commented out. Justice served. + // a better solution would use dataChanged() // I have this feeling that this resulted in a fuckup once... no clue though right now and invalidateFilter isn't a slot -.- //connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidate())); - connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidateFilter_())); + // connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidateFilter_())); } void BufferViewFilter::invalidateFilter_() { @@ -54,16 +62,18 @@ bool BufferViewFilter::dropMimeData(const QMimeData *data, Qt::DropAction action if(parent != QModelIndex()) return QSortFilterProxyModel::dropMimeData(data, action, row, column, parent); - if(!BufferTreeModel::mimeContainsBufferList(data)) + if(!NetworkModel::mimeContainsBufferList(data)) return false; - QList< QPair > bufferList = BufferTreeModel::mimeDataToBufferList(data); + QList< QPair > bufferList = NetworkModel::mimeDataToBufferList(data); uint netId, bufferId; for(int i = 0; i < bufferList.count(); i++) { netId = bufferList[i].first; bufferId = bufferList[i].second; - networks << netId; + if(!networks.contains(netId)) { + networks << netId; + } addBuffer(bufferId); } return true; @@ -84,12 +94,17 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) { return; // only child elements can be deleted bool lastBuffer = (rowCount(index.parent()) == 1); - uint netId = index.data(BufferTreeModel::NetworkIdRole).toUInt(); - uint bufferuid = index.data(BufferTreeModel::BufferUidRole).toUInt(); + uint netId = index.data(NetworkModel::NetworkIdRole).toUInt(); + uint bufferuid = index.data(NetworkModel::BufferIdRole).toUInt(); + if(buffers.contains(bufferuid)) { buffers.remove(bufferuid); - if(lastBuffer) + + if(lastBuffer) { networks.remove(netId); + Q_ASSERT(!networks.contains(netId)); + } + invalidateFilter(); } @@ -97,32 +112,31 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) { bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const { - Buffer::Type bufferType = (Buffer::Type) source_bufferIndex.data(BufferTreeModel::BufferTypeRole).toInt(); + BufferItem::Type bufferType = (BufferItem::Type) source_bufferIndex.data(NetworkModel::BufferTypeRole).toInt(); - if((mode & NoChannels) && bufferType == Buffer::ChannelType) + if((mode & NoChannels) && bufferType == BufferItem::ChannelType) return false; - if((mode & NoQueries) && bufferType == Buffer::QueryType) + if((mode & NoQueries) && bufferType == BufferItem::QueryType) return false; - if((mode & NoServers) && bufferType == Buffer::StatusType) + if((mode & NoServers) && bufferType == BufferItem::StatusType) return false; -// bool isActive = source_bufferIndex.data(BufferTreeModel::BufferActiveRole).toBool(); +// bool isActive = source_bufferIndex.data(NetworkModel::BufferActiveRole).toBool(); // if((mode & NoActive) && isActive) // return false; // if((mode & NoInactive) && !isActive) // return false; -// if((mode & FullCustom)) { -// uint bufferuid = source_bufferIndex.data(BufferTreeModel::BufferUidRole).toUInt(); -// if(!buffers.contains(bufferuid)) -// return false; -// } + if((mode & FullCustom)) { + uint bufferuid = source_bufferIndex.data(NetworkModel::BufferIdRole).toUInt(); + return buffers.contains(bufferuid); + } return true; } bool BufferViewFilter::filterAcceptNetwork(const QModelIndex &source_index) const { - uint net = source_index.data(BufferTreeModel::NetworkIdRole).toUInt(); + uint net = source_index.data(NetworkModel::NetworkIdRole).toUInt(); return !((mode & (SomeNets | FullCustom)) && !networks.contains(net)); } @@ -141,8 +155,8 @@ bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &sourc } bool BufferViewFilter::lessThan(const QModelIndex &left, const QModelIndex &right) const { - int lefttype = left.data(BufferTreeModel::BufferTypeRole).toInt(); - int righttype = right.data(BufferTreeModel::BufferTypeRole).toInt(); + int lefttype = left.data(NetworkModel::BufferTypeRole).toInt(); + int righttype = right.data(NetworkModel::BufferTypeRole).toInt(); if(lefttype != righttype) return lefttype < righttype; @@ -150,3 +164,17 @@ bool BufferViewFilter::lessThan(const QModelIndex &left, const QModelIndex &righ return QSortFilterProxyModel::lessThan(left, right); } +QVariant BufferViewFilter::data(const QModelIndex &index, int role) const { + if(role == Qt::ForegroundRole) + return foreground(index); + else + return QSortFilterProxyModel::data(index, role); +} + +QVariant BufferViewFilter::foreground(const QModelIndex &index) const { + if(!index.data(NetworkModel::ItemActiveRole).toBool()) + return QColor(Qt::gray); + + // FIXME:: show colors depending on activity level + return QColor(Qt::black); +}