Fixed annoying bug where the nicklist wouldn't be shown sometimes because of an incon...
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 29 Nov 2007 17:09:15 +0000 (17:09 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 29 Nov 2007 17:09:15 +0000 (17:09 +0000)
ProxyModel.
I had to hack NickView to always call expandAll() when rows are inserted. This works, but is ugly
and we should find a more elegant solution in due time.

src/client/nickmodel.cpp
src/client/nickmodel.h
src/uisupport/nickview.cpp
src/uisupport/nickview.h

index a1e8bcd..f755c0e 100644 (file)
@@ -194,14 +194,14 @@ int NickModel::categoryFromIndex(const QModelIndex &index) const {
   return index.internalId();
 }
 
-void NickModel::addUser(IrcUser *user) { //qDebug() << "adding" << user->nick();
+void NickModel::addUser(IrcUser *user) {
   int cat = userCategory(user);
   beginInsertRows(createIndex(cat-1, 0, 0), 0, 0);
   users[cat-1].prepend(user);
   endInsertRows();
 }
 
-void NickModel::removeUser(IrcUser *user) { //qDebug() << "removing" << user->nick();
+void NickModel::removeUser(IrcUser *user) {
   // we don't know for sure which category this user was in, so we have to search
   QModelIndex index = indexOfUser(user);
   removeUser(index);
@@ -241,6 +241,16 @@ FilteredNickModel::FilteredNickModel(QObject *parent) : QSortFilterProxyModel(pa
 
 }
 
+FilteredNickModel::~FilteredNickModel() {
+
+}
+
+void FilteredNickModel::setSourceModel(QAbstractItemModel *model) {
+  QSortFilterProxyModel::setSourceModel(model);
+  connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(sourceRowsInserted(const QModelIndex &, int, int)));
+  connect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int)));
+}
+
 // Hide empty categories
 bool FilteredNickModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
   if(!source_parent.isValid()) {
@@ -250,3 +260,19 @@ bool FilteredNickModel::filterAcceptsRow(int source_row, const QModelIndex &sour
   return true;
 }
 
+void FilteredNickModel::sourceRowsInserted(const QModelIndex &index, int start, int end) {
+  if(!index.isValid()) return;
+  if(sourceModel()->rowCount(index) <= end - start + 1) {
+    // category no longer empty
+    invalidateFilter();
+  }
+}
+
+void FilteredNickModel::sourceRowsRemoved(const QModelIndex &index, int, int) {
+  if(!index.isValid()) return;
+  if(sourceModel()->rowCount(index) == 0) {
+    // category is now empty!
+    invalidateFilter();
+  }
+}
+
index 8a65e9d..938543d 100644 (file)
@@ -79,6 +79,13 @@ class FilteredNickModel : public QSortFilterProxyModel {
 
   public:
     FilteredNickModel(QObject *parent = 0);
+    virtual ~FilteredNickModel();
+
+    virtual void setSourceModel(QAbstractItemModel *model);
+
+  private slots:
+    void sourceRowsInserted(const QModelIndex &, int, int);
+    void sourceRowsRemoved(const QModelIndex &, int, int);
 
   protected:
     virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
index 9894ba8..68b51cf 100644 (file)
@@ -22,6 +22,7 @@
 #include "nickmodel.h"
 
 #include <QHeaderView>
+#include <QDebug>
 
 NickView::NickView(QWidget *parent) : QTreeView(parent) {
   setGeometry(0, 0, 30, 30);
@@ -47,3 +48,9 @@ void NickView::setModel(NickModel *model) {
   filteredModel->setSourceModel(model);
   expandAll();
 }
+
+void NickView::rowsInserted(const QModelIndex &index, int start, int end) {
+  QTreeView::rowsInserted(index, start, end);
+  expandAll();  // FIXME We need to do this more intelligently. Maybe a pimped TreeView?
+}
+
index 2dcf180..a131c0a 100644 (file)
@@ -34,6 +34,9 @@ class NickView : public QTreeView {
     NickView(QWidget *parent = 0);
     virtual ~NickView();
 
+  protected:
+    void rowsInserted(const QModelIndex &, int, int);
+
   public slots:
     void setModel(NickModel *model);