fixing custom buffer views with minimum activity
[quassel.git] / src / uisupport / bufferviewfilter.cpp
index 51f8b0e..c34d023 100644 (file)
 
 #include "uisettings.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
 *****************************************/
@@ -40,6 +46,9 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig *
   setDynamicSortFilter(true);
 
   loadColors();
+
+  connect(this, SIGNAL(_dataChanged(const QModelIndex &, const QModelIndex &)),
+         this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
 }
 
 void BufferViewFilter::loadColors() {
@@ -268,6 +277,28 @@ void BufferViewFilter::source_rowsInserted(const QModelIndex &parent, int start,
   }
 }
 
+void BufferViewFilter::checkPreviousCurrentForRemoval(const QModelIndex &current, const QModelIndex &previous) {
+  Q_UNUSED(current);
+  if(previous.isValid())
+    qApp->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);
+}
+
 // ******************************
 //  Helper
 // ******************************