BufferViewOverlay now correctly respects filtering of buffer types
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 12 Apr 2010 18:36:00 +0000 (20:36 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 11 May 2010 21:06:08 +0000 (23:06 +0200)
src/client/bufferviewoverlay.cpp
src/client/bufferviewoverlay.h
src/qtui/debugbufferviewoverlay.cpp
src/uisupport/bufferviewoverlayfilter.cpp

index b1938d1..f4b2985 100644 (file)
@@ -33,8 +33,6 @@ BufferViewOverlay::BufferViewOverlay(QObject *parent)
   : QObject(parent),
     _aboutToUpdate(false),
     _uninitializedViewCount(0),
-    _addBuffersAutomatically(false),
-    _hideInactiveBuffers(false),
     _allowedBufferTypes(0),
     _minimumActivity(0)
 {
@@ -98,11 +96,9 @@ void BufferViewOverlay::viewInitialized(BufferViewConfig *config) {
   }
   disconnect(config, SIGNAL(initDone()), this, SLOT(viewInitialized()));
 
-  connect(config, SIGNAL(configChanged()), this, SLOT(update()));  
+  connect(config, SIGNAL(configChanged()), this, SLOT(update()));
 //   connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(update()));
-//   connect(config, SIGNAL(addNewBuffersAutomaticallySet(bool)), this, SLOT(update()));
 //   connect(config, SIGNAL(sortAlphabeticallySet(bool)), this, SLOT(update()));
-//   connect(config, SIGNAL(hideInactiveBuffersSet(bool)), this, SLOT(update()));
 //   connect(config, SIGNAL(allowedBufferTypesSet(int)), this, SLOT(update()));
 //   connect(config, SIGNAL(minimumActivitySet(int)), this, SLOT(update()));
 //   connect(config, SIGNAL(bufferListSet()), this, SLOT(update()));
@@ -140,8 +136,6 @@ void BufferViewOverlay::updateHelper() {
 
   bool changed = false;
 
-  bool addBuffersAutomatically = false;
-  bool hideInactiveBuffers = true;
   int allowedBufferTypes = 0;
   int minimumActivity = -1;
   QSet<NetworkId> networkIds;
@@ -157,48 +151,32 @@ void BufferViewOverlay::updateHelper() {
       if(!config)
         continue;
 
-      networkIds << config->networkId();
-      if(config->networkId().isValid()) {
-        NetworkId networkId = config->networkId();
-        // we have to filter out all the buffers that don't belong to this net... :/
-        QSet<BufferId> bufferIds;
-        foreach(BufferId bufferId, config->bufferList()) {
-          if(Client::networkModel()->networkId(bufferId) == networkId)
-            bufferIds << bufferId;
-        }
-        buffers += bufferIds;
-
-        bufferIds.clear();
-        foreach(BufferId bufferId, config->temporarilyRemovedBuffers()) {
-          if(Client::networkModel()->networkId(bufferId) == networkId)
-            bufferIds << bufferId;
-        }
-        tempRemovedBuffers += bufferIds;
-      } else {
-        buffers += config->bufferList().toSet();
-        tempRemovedBuffers += config->temporarilyRemovedBuffers();
-      }
-
-      // in the overlay a buffer is removed it is removed from all views
-      if(removedBuffers.isEmpty())
-        removedBuffers = config->removedBuffers();
-      else
-        removedBuffers.intersect(config->removedBuffers());
-
-
-      addBuffersAutomatically |= config->addNewBuffersAutomatically();
-      hideInactiveBuffers &= config->hideInactiveBuffers();
       allowedBufferTypes |= config->allowedBufferTypes();
       if(minimumActivity == -1 || config->minimumActivity() < minimumActivity)
         minimumActivity = config->minimumActivity();
+
+      networkIds << config->networkId();
+
+
+      // we have to apply several filters before we can add a buffer to a category (visible, removed, ...)
+      buffers += filterBuffersByConfig(config->bufferList(), config);
+      tempRemovedBuffers += filterBuffersByConfig(config->temporarilyRemovedBuffers().toList(), config);
+      removedBuffers += config->removedBuffers();
     }
+
+    // prune the sets from overlap
     QSet<BufferId> availableBuffers = Client::networkModel()->allBufferIds().toSet();
+
     buffers.intersect(availableBuffers);
+
     tempRemovedBuffers.intersect(availableBuffers);
+    tempRemovedBuffers.subtract(buffers);
+
+    removedBuffers.intersect(availableBuffers);
+    removedBuffers.subtract(tempRemovedBuffers);
+    removedBuffers.subtract(buffers);
   }
 
-  changed |= (addBuffersAutomatically != _addBuffersAutomatically);
-  changed |= (hideInactiveBuffers != _hideInactiveBuffers);
   changed |= (allowedBufferTypes != _allowedBufferTypes);
   changed |= (minimumActivity != _minimumActivity);
   changed |= (networkIds != _networkIds);
@@ -206,8 +184,6 @@ void BufferViewOverlay::updateHelper() {
   changed |= (removedBuffers != _removedBuffers);
   changed |= (tempRemovedBuffers != _tempRemovedBuffers);
 
-  _addBuffersAutomatically = addBuffersAutomatically;
-  _hideInactiveBuffers = hideInactiveBuffers;
   _allowedBufferTypes = allowedBufferTypes;
   _minimumActivity = minimumActivity;
   _networkIds = networkIds;
@@ -221,6 +197,24 @@ void BufferViewOverlay::updateHelper() {
     emit hasChanged();
 }
 
+QSet<BufferId> BufferViewOverlay::filterBuffersByConfig(const QList<BufferId> &buffers, const BufferViewConfig *config) {
+  Q_ASSERT(config);
+
+  QSet<BufferId> bufferIds;
+  BufferInfo bufferInfo;
+  foreach(BufferId bufferId, buffers) {
+    bufferInfo = Client::networkModel()->bufferInfo(bufferId);
+    if(!(bufferInfo.type() & config->allowedBufferTypes()))
+      continue;
+    if(config->networkId().isValid() && bufferInfo.networkId() != config->networkId())
+      continue;
+    bufferIds << bufferId;
+  }
+
+  return bufferIds;
+}
+
+
 void BufferViewOverlay::customEvent(QEvent *event) {
   if(event->type() == _updateEventId) {
     updateHelper();
@@ -252,16 +246,6 @@ const QSet<BufferId> &BufferViewOverlay::tempRemovedBufferIds() {
   return _tempRemovedBuffers;
 }
 
-bool BufferViewOverlay::addBuffersAutomatically() {
-  updateHelper();
-  return _addBuffersAutomatically;
-}
-
-bool BufferViewOverlay::hideInactiveBuffers() {
-  updateHelper();
-  return _hideInactiveBuffers;
-}
-
 int BufferViewOverlay::allowedBufferTypes() {
   updateHelper();
   return _allowedBufferTypes;
index 96f6323..204e553 100644 (file)
@@ -42,8 +42,6 @@ public:
   const QSet<BufferId> &removedBufferIds();
   const QSet<BufferId> &tempRemovedBufferIds();
 
-  bool addBuffersAutomatically();
-  bool hideInactiveBuffers();
   int allowedBufferTypes();
   int minimumActivity();
 
@@ -69,15 +67,14 @@ private slots:
 
 private:
   void updateHelper();
+  QSet<BufferId> filterBuffersByConfig(const QList<BufferId> &buffers, const BufferViewConfig *config);
+
   bool _aboutToUpdate;
 
   QSet<int> _bufferViewIds;
   int _uninitializedViewCount;
 
   QSet<NetworkId> _networkIds;
-
-  bool _addBuffersAutomatically;
-  bool _hideInactiveBuffers;
   int _allowedBufferTypes;
   int _minimumActivity;
 
index 976499a..1207c2a 100644 (file)
@@ -54,8 +54,6 @@ DebugBufferViewOverlay::DebugBufferViewOverlay(QWidget *parent)
   layout->addRow(tr("Removed buffers:"), _removedBufferIds = new QTextEdit(this));
   layout->addRow(tr("Temp. removed buffers:"), _tempRemovedBufferIds = new QTextEdit(this));
 
-  layout->addRow(tr("Add Buffers Automatically:"), _addBuffersAutomatically = new QLabel(this));
-  layout->addRow(tr("Hide inactive buffers:"), _hideInactiveBuffers = new QLabel(this));
   layout->addRow(tr("Allowed buffer types:"), _allowedBufferTypes = new QLabel(this));
   layout->addRow(tr("Minimum activity:"), _minimumActivity = new QLabel(this));
 
@@ -100,8 +98,6 @@ void DebugBufferViewOverlay::update() {
   }
   _tempRemovedBufferIds->setText(ids.join(", "));
 
-  _addBuffersAutomatically->setText(overlay->addBuffersAutomatically() ? "yes" : "no");
-  _hideInactiveBuffers->setText(overlay->hideInactiveBuffers() ? "yes" : "no");
   _allowedBufferTypes->setText(QString::number(overlay->allowedBufferTypes()));
   _minimumActivity->setText(QString::number(overlay->minimumActivity()));
 
index 992ab6c..4309ee9 100644 (file)
@@ -83,10 +83,6 @@ bool BufferViewOverlayFilter::filterAcceptsRow(int source_row, const QModelIndex
   if(_overlay->minimumActivity() > activityLevel)
     return false;
 
-  bool isActive = sourceModel()->data(source_bufferIndex, NetworkModel::ItemActiveRole).toBool();
-  if(_overlay->hideInactiveBuffers() && !isActive && activityLevel <= BufferInfo::OtherActivity)
-    return false;
-
   int bufferType = sourceModel()->data(source_bufferIndex, NetworkModel::BufferTypeRole).toInt();
   if(!(_overlay->allowedBufferTypes() & bufferType))
     return false;
@@ -104,6 +100,7 @@ bool BufferViewOverlayFilter::filterAcceptsRow(int source_row, const QModelIndex
     return false;
 
   // the buffer is not known to us
-  return _overlay->addBuffersAutomatically();
+  qDebug() << "BufferViewOverlayFilter::filterAcceptsRow()" << bufferId << "is unknown!";
+  return false;
 }