Changeset 6309 for trunk/qt4-gui/src/contactlist
- Timestamp:
- 06/14/08 23:21:57 (6 months ago)
- Location:
- trunk/qt4-gui/src/contactlist
- Files:
-
- 4 modified
-
contactgroup.cpp (modified) (4 diffs)
-
contactgroup.h (modified) (1 diff)
-
contactlist.cpp (modified) (11 diffs)
-
contactlist.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/qt4-gui/src/contactlist/contactgroup.cpp
r6283 r6309 133 133 void ContactGroup::addUser(ContactUser* user, ContactListModel::SubGroupType subGroup) 134 134 { 135 // Signal that we are about to add a row 136 emit beginInsert(this, rowCount()); 137 135 138 myUsers.append(user); 136 139 if (user->visibility()) … … 139 142 myEvents += user->numEvents(); 140 143 myBars[subGroup]->updateNumEvents(user->numEvents()); 144 145 // Signal that we're done adding 146 emit endInsert(); 147 148 // Update group and bar as counters may have changed 141 149 emit barDataChanged(myBars[subGroup], subGroup); 142 143 150 emit dataChanged(this); 144 151 } … … 146 153 void ContactGroup::removeUser(ContactUser* user, ContactListModel::SubGroupType subGroup) 147 154 { 155 // Signal that we are about to remove a row 156 emit beginRemove(this, indexOf(user)); 157 148 158 myUsers.removeAll(user); 149 159 if (user->visibility()) … … 152 162 myEvents -= user->numEvents(); 153 163 myBars[subGroup]->updateNumEvents(-user->numEvents()); 164 165 // Signal that we're done removing 166 emit endRemove(); 167 168 // Update group and bar as counters may have changed 154 169 emit barDataChanged(myBars[subGroup], subGroup); 155 156 170 emit dataChanged(this); 157 171 } -
trunk/qt4-gui/src/contactlist/contactgroup.h
r6283 r6309 181 181 */ 182 182 void barDataChanged(ContactBar* bar, int row); 183 184 /** 185 * Signal emitted before a user is added 186 * 187 * @param group The affected group (always sent as this) 188 * @param row Row number for the new user 189 */ 190 void beginInsert(ContactGroup* group, int row); 191 192 /** 193 * Signal emitted after a user has been added 194 */ 195 void endInsert(); 196 197 /** 198 * Signal emitted before a user is removed 199 * 200 * @param group The affected group (always sent as this) 201 * @param row Row number for the user to be removed 202 */ 203 void beginRemove(ContactGroup* gorup, int row); 204 205 /** 206 * Segnal emitted after a user has been removed 207 */ 208 void endRemove(); 183 209 184 210 private: -
trunk/qt4-gui/src/contactlist/contactlist.cpp
r6283 r6309 63 63 connect(group, SIGNAL(barDataChanged(ContactBar*, int)), 64 64 SLOT(barDataChanged(ContactBar*, int))); 65 connect(group, SIGNAL(beginInsert(ContactGroup*, int)), 66 SLOT(groupBeginInsert(ContactGroup*, int))); 67 connect(group, SIGNAL(endInsert()), SLOT(groupEndInsert())); 68 connect(group, SIGNAL(beginRemove(ContactGroup*, int)), 69 SLOT(groupBeginRemove(ContactGroup*, int))); 70 connect(group, SIGNAL(endRemove()), SLOT(groupEndRemove())); 65 71 return group; 66 72 } … … 236 242 return; 237 243 238 int groupRow = (group->groupId() < SystemGroupOffset 239 ? myUserGroups.indexOf(group) 240 : myUserGroups.size() + group->groupId() - SystemGroupOffset); 241 242 emit dataChanged(createIndex(groupRow, 0, group), createIndex(groupRow, myColumnCount - 1, group)); 244 int row = groupRow(group); 245 emit dataChanged(createIndex(row, 0, group), createIndex(row, myColumnCount - 1, group)); 243 246 } 244 247 … … 249 252 250 253 emit dataChanged(createIndex(row, 0, bar), createIndex(row, myColumnCount - 1, bar)); 254 } 255 256 void ContactListModel::groupBeginInsert(ContactGroup* group, int row) 257 { 258 beginInsertRows(createIndex(groupRow(group), 0, group), row, row); 259 } 260 261 void ContactListModel::groupEndInsert() 262 { 263 endInsertRows(); 264 } 265 266 void ContactListModel::groupBeginRemove(ContactGroup* group, int row) 267 { 268 beginRemoveRows(createIndex(groupRow(group), 0, group), row, row); 269 } 270 271 void ContactListModel::groupEndRemove() 272 { 273 endRemoveRows(); 251 274 } 252 275 … … 261 284 262 285 // Add all groups 263 beginInsertRows(QModelIndex(), 0, gUserManager.NumGroups() + 1);264 265 286 ContactGroup* newGroup = createGroup(0, tr("Other Users")); 266 287 myUserGroups.append(newGroup); … … 277 298 FOR_EACH_GROUP_END 278 299 279 endInsertRows();280 281 300 // Add all users 282 301 FOR_EACH_USER_START(LOCK_R) … … 299 318 } 300 319 return 0; 320 } 321 322 int ContactListModel::groupRow(ContactGroup* group) const 323 { 324 unsigned short groupId = group->groupId(); 325 326 if (groupId < SystemGroupOffset) 327 return myUserGroups.indexOf(group); 328 else if (groupId <= SystemGroupOffset + NUM_GROUPS_SYSTEM_ALL) 329 return myUserGroups.size() + groupId - SystemGroupOffset; 330 else 331 return -1; 301 332 } 302 333 … … 322 353 bool shouldBeMember = (gid != 0 && licqUser->GetInGroup(GROUPS_USER, gid)) || 323 354 (gid == 0 && licqUser->GetGroups().empty() && !licqUser->IgnoreList()); 324 updateUserGroup(user, group, i,shouldBeMember);355 updateUserGroup(user, group, shouldBeMember); 325 356 } 326 357 … … 328 359 for (unsigned long i = 0; i < NUM_GROUPS_SYSTEM_ALL; ++i) 329 360 { 330 updateUserGroup(user, mySystemGroups[i], myUserGroups.size()+i,licqUser->GetInGroup(GROUPS_SYSTEM, i));331 } 332 } 333 334 void ContactListModel::updateUserGroup(ContactUserData* user, ContactGroup* group, int groupRow,bool shouldBeMember)361 updateUserGroup(user, mySystemGroups[i], licqUser->GetInGroup(GROUPS_SYSTEM, i)); 362 } 363 } 364 365 void ContactListModel::updateUserGroup(ContactUserData* user, ContactGroup* group, bool shouldBeMember) 335 366 { 336 367 ContactUser* member = group->user(user); … … 340 371 return; 341 372 373 // Adding or removing the user is enough here, signals will be sent from group 342 374 if (shouldBeMember) 343 {344 // Add user to group345 beginInsertRows(createIndex(groupRow, 0, group), group->rowCount(), group->rowCount());346 375 new ContactUser(user, group); 347 endInsertRows();348 }349 376 else 350 {351 // Remove user from the group352 int index = group->indexOf(member);353 beginRemoveRows(createIndex(groupRow, 0, group), index, index);354 377 delete member; 355 endRemoveRows();356 }357 378 } 358 379 … … 367 388 ContactGroup* group = u->group(); 368 389 int pos = group->indexOf(u); 369 int groupRow = (group->groupId() < SystemGroupOffset ? myUserGroups.indexOf(group) : myUserGroups.size() + group->groupId() - SystemGroupOffset); 370 beginRemoveRows(createIndex(groupRow, 0, group), pos, pos); 390 beginRemoveRows(createIndex(groupRow(group), 0, group), pos, pos); 371 391 delete u; 372 392 endRemoveRows(); … … 436 456 return QModelIndex(); 437 457 } 438 int groupRow = (group->groupId() < SystemGroupOffset ? myUserGroups.indexOf(group) : myUserGroups.size() + group->groupId() - SystemGroupOffset); 439 return createIndex(groupRow, 0, group); 458 return createIndex(groupRow(group), 0, group); 440 459 } 441 460 -
trunk/qt4-gui/src/contactlist/contactlist.h
r6283 r6309 376 376 377 377 /** 378 * A group is about to add a user 379 * Will send beginInsertRow signal for the user 380 * 381 * @param group The group that's adding the user 382 * @param row The row the new user will have in the group 383 */ 384 void groupBeginInsert(ContactGroup* group, int row); 385 386 /** 387 * A group has finished adding a user 388 * Will send endInsertRow signal 389 */ 390 void groupEndInsert(); 391 392 /** 393 * A group is about to remove a user 394 * Will send beginRemoveRow signal for the user 395 * 396 * @param group The group that's removing the user 397 * @param row The row of the user about to be removed 398 */ 399 void groupBeginRemove(ContactGroup* group, int row); 400 401 /** 402 * A group has finished removing a user 403 * Will send endRemoveRow signal 404 */ 405 void groupEndRemove(); 406 407 /** 378 408 * Update the user membership in all groups 379 409 * This is triggered by the user data object when its group membership (may) have changed … … 408 438 * @param user The user to update 409 439 * @param group The group to check 410 * @param groupRow The row index of the group411 440 * @param shouldBeMember True to add the user if missing or false to remove if member 412 441 */ 413 void updateUserGroup(ContactUserData* user, ContactGroup* group, int groupRow, bool shouldBeMember); 442 void updateUserGroup(ContactUserData* user, ContactGroup* group, bool shouldBeMember); 443 444 /** 445 * Get model row for a group 446 * 447 * @param group A group object 448 * @return Row in model or -1 if not found 449 */ 450 int groupRow(ContactGroup* group) const; 414 451 415 452 QList<ContactGroup*> myUserGroups;
