fixing custom buffer views with minimum activity
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 3 May 2008 17:11:29 +0000 (17:11 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 3 May 2008 17:11:29 +0000 (17:11 +0000)
src/uisupport/bufferview.cpp
src/uisupport/bufferview.h
src/uisupport/bufferviewfilter.cpp
src/uisupport/bufferviewfilter.h
version.inc

index 3b895d1..c168eaa 100644 (file)
@@ -129,11 +129,25 @@ void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig *
   } else {
     BufferViewFilter *filter = new BufferViewFilter(model_, config);
     setModel(filter);
-    connect(this, SIGNAL(removeBuffer(const QModelIndex &)), filter, SLOT(removeBuffer(const QModelIndex &)));
+    connect(this, SIGNAL(removeBuffer(const QModelIndex &)),
+           filter, SLOT(removeBuffer(const QModelIndex &)));
   }
   setConfig(config);
 }
 
+void BufferView::setSelectionModel(QItemSelectionModel *selectionModel) {
+  if(QTreeView::selectionModel())
+    disconnect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+              model(), SIGNAL(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex)));
+    
+  QTreeView::setSelectionModel(selectionModel);
+  BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
+  if(filter) {
+    connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+           filter, SLOT(checkPreviousCurrentForRemoval(QModelIndex, QModelIndex)));
+  }
+}
+
 void BufferView::setConfig(BufferViewConfig *config) {
   if(_config == config)
     return;
index b42c6c1..66ee467 100644 (file)
@@ -42,6 +42,7 @@ public:
 
   void setModel(QAbstractItemModel *model);
   void setFilteredModel(QAbstractItemModel *model, BufferViewConfig *config);
+  virtual void setSelectionModel(QItemSelectionModel *selectionModel);
 
   void setConfig(BufferViewConfig *config);
   inline BufferViewConfig *config() { return _config; }
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
 // ******************************
index 4715f11..4a80f7e 100644 (file)
@@ -63,6 +63,9 @@ public:
 
 public slots:
   void removeBuffer(const QModelIndex &);
+  void checkPreviousCurrentForRemoval(const QModelIndex &current, const QModelIndex &previous);
+  void checkItemForRemoval(const QModelIndex &index) { checkItemsForRemoval(index, index); }
+  void checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight);
   void source_rowsInserted(const QModelIndex &parent, int start, int end);
   
 protected:
@@ -70,17 +73,21 @@ protected:
   bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
   bool bufferLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
   bool networkLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
+  virtual void customEvent(QEvent *event);
 
+signals:
+  void _dataChanged(const QModelIndex &source_topLeft, const QModelIndex &source_bottomRight);
+  
 private:
   QPointer<BufferViewConfig> _config;
-
+  
   QColor _FgColorInactiveActivity;
   QColor _FgColorNoActivity;
   QColor _FgColorHighlightActivity;
   QColor _FgColorNewMessageActivity;
   QColor _FgColorOtherActivity;
   void loadColors();
-  
+
   bool filterAcceptBuffer(const QModelIndex &) const;
   bool filterAcceptNetwork(const QModelIndex &) const;
   void addBuffer(const BufferId &);
index 79f7d31..641fb53 100644 (file)
@@ -4,8 +4,8 @@
 { using namespace Global;
 
   quasselVersion = "0.2.0-beta1-pre";
-  quasselDate = "2008-05-02";
-  quasselBuild = 807;
+  quasselDate = "2008-05-03";
+  quasselBuild = 808;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 731;