Fixing Issues with the NetworkModel. Though the performance still
[quassel.git] / src / client / networkmodel.cpp
index aa4aefe..48a6b8c 100644 (file)
@@ -94,9 +94,9 @@ QVariant BufferItem::data(int column, int role) const {
   case NetworkModel::ItemTypeRole:
     return NetworkModel::BufferItemType;
   case NetworkModel::BufferIdRole:
-    return QVariant::fromValue<BufferId>(bufferInfo().uid());
+    return qVariantFromValue(bufferInfo().uid());
   case NetworkModel::NetworkIdRole:
-    return QVariant::fromValue<NetworkId>(bufferInfo().networkId());
+    return qVariantFromValue(bufferInfo().networkId());
   case NetworkModel::BufferTypeRole:
     return int(bufferType());
   case NetworkModel::ItemActiveRole:
@@ -132,10 +132,7 @@ void BufferItem::attachIrcChannel(IrcChannel *ircChannel) {
 
 void BufferItem::ircChannelDestroyed() {
   emit dataChanged();
-  for(int i = 0; i < childCount(); i++) {
-    emit childDestroyed(i);
-    removeChild(i);
-  }
+  removeAllChilds();
 }
 
 QString BufferItem::bufferName() const {
@@ -203,6 +200,13 @@ void BufferItem::removeUserFromCategory(IrcUser *ircUser) {
 }
 
 void BufferItem::userModeChanged(IrcUser *ircUser) {
+  Q_ASSERT(_ircChannel);
+    
+  UserCategoryItem *categoryItem;
+  int categoryId = UserCategoryItem::categoryFromModes(_ircChannel->userModes(ircUser));
+  if((categoryItem = qobject_cast<UserCategoryItem *>(childById(qHash(categoryId)))))
+    return; // already in the right category;
+  
   removeUserFromCategory(ircUser);
   addUserToCategory(ircUser);
 }
@@ -220,7 +224,7 @@ NetworkItem::NetworkItem(const NetworkId &netid, AbstractTreeItem *parent)
 QVariant NetworkItem::data(int column, int role) const {
   switch(role) {
   case NetworkModel::NetworkIdRole:
-    return QVariant::fromValue<NetworkId>(_networkId);
+    return qVariantFromValue(_networkId);
   case NetworkModel::ItemTypeRole:
     return NetworkModel::NetworkItemType;
   case NetworkModel::ItemActiveRole:
@@ -319,7 +323,7 @@ UserCategoryItem::UserCategoryItem(int category, AbstractTreeItem *parent)
   : PropertyMapItem(QStringList() << "categoryId", parent),
     _category(category)
 {
-  connect(this, SIGNAL(childDestroyed(int)),
+  connect(this, SIGNAL(childRemoved(int)),
          this, SLOT(checkNoChilds()));
 }