Fix issues with buffer selection and filtered views
[quassel.git] / src / uisupport / bufferviewfilter.cpp
index 0850a50..4c5d4a9 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2014 by the Quassel Project                        *
+ *   Copyright (C) 2005-2015 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 #include "client.h"
 #include "clientbufferviewconfig.h"
 #include "graphicalui.h"
-#include "iconloader.h"
 #include "networkmodel.h"
 #include "uistyle.h"
 
-class CheckRemovalEvent : public QEvent
-{
-public:
-    CheckRemovalEvent(const QModelIndex &source_index) : QEvent(QEvent::User), index(source_index) {};
-    QPersistentModelIndex index;
-};
-
 
 /*****************************************
 * The Filter for the Tree View
@@ -58,9 +50,6 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig *
 
     setDynamicSortFilter(true);
 
-    connect(this, SIGNAL(_dataChanged(const QModelIndex &, const QModelIndex &)),
-        this, SLOT(_q_sourceDataChanged(QModelIndex, QModelIndex)));
-
     _enableEditMode.setCheckable(true);
     _enableEditMode.setChecked(_editMode);
     connect(&_enableEditMode, SIGNAL(toggled(bool)), this, SLOT(enableEditMode(bool)));
@@ -162,12 +151,12 @@ void BufferViewFilter::enableEditMode(bool enable)
     if (enable == false) {
         addBuffers(QList<BufferId>::fromSet(_toAdd));
         QSet<BufferId>::const_iterator iter;
-        for (iter = _toTempRemove.constBegin(); iter != _toTempRemove.constEnd(); iter++) {
+        for (iter = _toTempRemove.constBegin(); iter != _toTempRemove.constEnd(); ++iter) {
             if (config()->temporarilyRemovedBuffers().contains(*iter))
                 continue;
             config()->requestRemoveBuffer(*iter);
         }
-        for (iter = _toRemove.constBegin(); iter != _toRemove.constEnd(); iter++) {
+        for (iter = _toRemove.constBegin(); iter != _toRemove.constEnd(); ++iter) {
             if (config()->removedBuffers().contains(*iter))
                 continue;
             config()->requestRemoveBufferPermanently(*iter);
@@ -377,6 +366,10 @@ bool BufferViewFilter::filterAcceptNetwork(const QModelIndex &source_index) cons
     if (!config())
         return true;
 
+    if (config()->hideInactiveNetworks() && !(sourceModel()->data(source_index, NetworkModel::ItemActiveRole).toBool())) {
+        return false;
+    }
+
     if (!config()->networkId().isValid()) {
         return true;
     }
@@ -539,34 +532,6 @@ bool BufferViewFilter::setCheckedState(const QModelIndex &index, Qt::CheckState
 }
 
 
-void BufferViewFilter::checkPreviousCurrentForRemoval(const QModelIndex &current, const QModelIndex &previous)
-{
-    Q_UNUSED(current);
-    if (previous.isValid())
-        QCoreApplication::postEvent(this, new CheckRemovalEvent(previous));
-}
-
-
-void BufferViewFilter::customEvent(QEvent *event)
-{
-    if (event->type() != QEvent::User)
-        return;
-
-    CheckRemovalEvent *removalEvent = static_cast<CheckRemovalEvent *>(event);
-    checkItemForRemoval(removalEvent->index);
-
-    event->accept();
-}
-
-
-void BufferViewFilter::checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight)
-{
-    QModelIndex source_topLeft = mapToSource(topLeft);
-    QModelIndex source_bottomRight = mapToSource(bottomRight);
-    emit _dataChanged(source_topLeft, source_bottomRight);
-}
-
-
 bool BufferViewFilter::bufferIdLessThan(const BufferId &left, const BufferId &right)
 {
     Q_CHECK_PTR(Client::networkModel());