void ContactListModel::Private::removeContact(PsiContact *contact) { Q_ASSERT(monitoredContacts.contains(contact)); if (!monitoredContacts.contains(contact)) return; while (monitoredContacts.contains(contact)) { QModelIndex index = monitoredContacts.take(contact); if (!index.isValid()) { continue; } q->beginRemoveRows(index.parent(), index.row(), index.row()); ContactListItem *item = q->toItem(index); ContactListItem *group = item->parent(); delete item; q->endRemoveRows(); index = q->toModelIndex(group); // Delete empty group if (group->isGroup() && !group->childCount()) { q->beginRemoveRows(index.parent(), index.row(), index.row()); delete group; q->endRemoveRows(); } else { // Update group emit q->dataChanged(index, index); } } disconnect(contact, nullptr, this, nullptr); operationQueue.remove(contact); }
void ContactListModel::Private::contactUpdated() { PsiContact *contact = qobject_cast<PsiContact*>(sender()); Q_ASSERT(monitoredContacts.contains(contact)); if (!monitoredContacts.contains(contact)) return; // Check for groups changing // Maybe very difficult and should be simplified? QList<ContactListItem*> groupItems; for (const QPersistentModelIndex &index: monitoredContacts.values(contact)) { ContactListItem *item = q->toItem(index); ContactListItem *parent = item->parent(); if (parent && parent->isGroup()) { groupItems << parent; } } Operation operation = Operation::UpdateContact; ContactListItem::SpecialGroupType specialGroupType = specialGroupFor(contact); if (specialGroupType == ContactListItem::SpecialGroupType::NoneSpecialGroupType) { QStringList groups1; for (ContactListItem *item: groupItems) { groups1 << item->name(); } groups1.sort(); QStringList groups2 = contact->groups(); groups2.sort(); if (groups1 != groups2) { operation = Operation::ContactGroupsChanged; } } else if (groupItems.size() > 1 || (!groupItems.isEmpty() && groupItems.first()->specialGroupType() != specialGroupType)) { operation = Operation::ContactGroupsChanged; } addOperation(contact, operation); }