X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fbufferviewoverlayfilter.cpp;h=a90f8e86b88e53d6a71674836d671b8f766915e2;hp=97a3246e563ec165f620028668e2e0d28e167456;hb=c64a887d0f05222590299fb2bb8d56fa9fadb16d;hpb=ab16c77fe03b73a863d9b52b11919bcbac903f58 diff --git a/src/uisupport/bufferviewoverlayfilter.cpp b/src/uisupport/bufferviewoverlayfilter.cpp index 97a3246e..a90f8e86 100644 --- a/src/uisupport/bufferviewoverlayfilter.cpp +++ b/src/uisupport/bufferviewoverlayfilter.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-09 by the Quassel Project * + * Copyright (C) 2005-2012 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "bufferviewoverlayfilter.h" @@ -25,79 +25,88 @@ #include "types.h" BufferViewOverlayFilter::BufferViewOverlayFilter(QAbstractItemModel *model, BufferViewOverlay *overlay) - : QSortFilterProxyModel(model), + : QSortFilterProxyModel(model), _overlay(0) { - setOverlay(overlay); - setSourceModel(model); + setOverlay(overlay); + setSourceModel(model); - setDynamicSortFilter(true); + setDynamicSortFilter(true); } -void BufferViewOverlayFilter::setOverlay(BufferViewOverlay *overlay) { - if(_overlay == overlay) - return; - if(_overlay) { - disconnect(_overlay, 0, this, 0); - } +void BufferViewOverlayFilter::setOverlay(BufferViewOverlay *overlay) +{ + if (_overlay == overlay) + return; - _overlay = overlay; + if (_overlay) { + disconnect(_overlay, 0, this, 0); + } - if(!overlay) { - invalidate(); - return; - } + _overlay = overlay; + + if (!overlay) { + invalidate(); + return; + } - connect(overlay, SIGNAL(destroyed()), this, SLOT(overlayDestroyed())); - connect(overlay, SIGNAL(hasChanged()), this, SLOT(invalidate())); - invalidate(); + connect(overlay, SIGNAL(destroyed()), this, SLOT(overlayDestroyed())); + connect(overlay, SIGNAL(hasChanged()), this, SLOT(invalidate())); + invalidate(); } -void BufferViewOverlayFilter::overlayDestroyed() { - setOverlay(0); + +void BufferViewOverlayFilter::overlayDestroyed() +{ + setOverlay(0); } -bool BufferViewOverlayFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { - if(!_overlay) - return false; - QModelIndex source_bufferIndex = sourceModel()->index(source_row, 0, source_parent); +bool BufferViewOverlayFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +{ + if (!_overlay) + return false; - if(!source_bufferIndex.isValid()) { - qWarning() << "filterAcceptsRow has been called with an invalid Child"; - return false; - } + QModelIndex source_bufferIndex = sourceModel()->index(source_row, 0, source_parent); - NetworkId networkId = sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value(); - if(!_overlay->networkIds().contains(networkId) && ! _overlay->allNetworks()) - return false; + if (!source_bufferIndex.isValid()) { + qWarning() << "filterAcceptsRow has been called with an invalid Child"; + return false; + } - int activityLevel = sourceModel()->data(source_bufferIndex, NetworkModel::BufferActivityRole).toInt(); - if(_overlay->minimumActivity() > activityLevel) - return false; + NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_bufferIndex, NetworkModel::ItemTypeRole).toInt(); - bool isActive = sourceModel()->data(source_bufferIndex, NetworkModel::ItemActiveRole).toBool(); - if(_overlay->hideInactiveBuffers() && !isActive && activityLevel <= BufferInfo::OtherActivity) - return false; + NetworkId networkId = sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value(); + if (!_overlay->networkIds().contains(networkId) && !_overlay->allNetworks()) { + return false; + } + else if (itemType == NetworkModel::NetworkItemType) { + // network items don't need further checks. + return true; + } - int bufferType = sourceModel()->data(source_bufferIndex, NetworkModel::BufferTypeRole).toInt(); - if(!(_overlay->allowedBufferTypes() & bufferType)) - return false; + int activityLevel = sourceModel()->data(source_bufferIndex, NetworkModel::BufferActivityRole).toInt(); + if (_overlay->minimumActivity() > activityLevel) + return false; - BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value(); - Q_ASSERT(bufferId.isValid()); + int bufferType = sourceModel()->data(source_bufferIndex, NetworkModel::BufferTypeRole).toInt(); + if (!(_overlay->allowedBufferTypes() & bufferType)) + return false; - if(_overlay->bufferIds().contains(bufferId)) - return true; + BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value(); + Q_ASSERT(bufferId.isValid()); - if(_overlay->tempRemovedBufferIds().contains(bufferId)) - return activityLevel > BufferInfo::OtherActivity; + if (_overlay->bufferIds().contains(bufferId)) + return true; - if(_overlay->removedBufferIds().contains(bufferId)) - return false; + if (_overlay->tempRemovedBufferIds().contains(bufferId)) + return activityLevel > BufferInfo::OtherActivity; - // the buffer is not known to us - return _overlay->addBuffersAutomatically(); -} + if (_overlay->removedBufferIds().contains(bufferId)) + return false; + // the buffer is not known to us + qDebug() << "BufferViewOverlayFilter::filterAcceptsRow()" << bufferId << "is unknown!"; + return false; +}