1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "bufferviewoverlayfilter.h"
23 #include "bufferviewoverlay.h"
24 #include "networkmodel.h"
27 BufferViewOverlayFilter::BufferViewOverlayFilter(QAbstractItemModel *model, BufferViewOverlay *overlay)
28 : QSortFilterProxyModel(model),
32 setSourceModel(model);
34 setDynamicSortFilter(true);
37 void BufferViewOverlayFilter::setOverlay(BufferViewOverlay *overlay) {
38 if(_overlay == overlay)
42 disconnect(_overlay, 0, this, 0);
52 connect(overlay, SIGNAL(destroyed()), this, SLOT(overlayDestroyed()));
53 connect(overlay, SIGNAL(hasChanged()), this, SLOT(invalidate()));
57 void BufferViewOverlayFilter::overlayDestroyed() {
61 bool BufferViewOverlayFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
65 QModelIndex source_bufferIndex = sourceModel()->index(source_row, 0, source_parent);
67 if(!source_bufferIndex.isValid()) {
68 qWarning() << "filterAcceptsRow has been called with an invalid Child";
72 NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_bufferIndex, NetworkModel::ItemTypeRole).toInt();
74 NetworkId networkId = sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value<NetworkId>();
75 if(!_overlay->networkIds().contains(networkId) && ! _overlay->allNetworks()) {
77 } else if(itemType == NetworkModel::NetworkItemType) {
78 // network items don't need further checks.
82 int activityLevel = sourceModel()->data(source_bufferIndex, NetworkModel::BufferActivityRole).toInt();
83 if(_overlay->minimumActivity() > activityLevel)
86 bool isActive = sourceModel()->data(source_bufferIndex, NetworkModel::ItemActiveRole).toBool();
87 if(_overlay->hideInactiveBuffers() && !isActive && activityLevel <= BufferInfo::OtherActivity)
90 int bufferType = sourceModel()->data(source_bufferIndex, NetworkModel::BufferTypeRole).toInt();
91 if(!(_overlay->allowedBufferTypes() & bufferType))
94 BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value<BufferId>();
95 Q_ASSERT(bufferId.isValid());
97 if(_overlay->bufferIds().contains(bufferId))
100 if(_overlay->tempRemovedBufferIds().contains(bufferId))
101 return activityLevel > BufferInfo::OtherActivity;
103 if(_overlay->removedBufferIds().contains(bufferId))
106 // the buffer is not known to us
107 return _overlay->addBuffersAutomatically();