| 236 | } |
| 237 | |
| 238 | void FolderModel::takeUpdatedChildrenInfo(FolderItem *parent, const QModelIndex &parentModelIndex, FolderItem *updated) |
| 239 | { |
| 240 | auto currentChildren = parent->children(); |
| 241 | auto updatedChildren = updated->children(); |
| 242 | |
| 243 | int lenght = currentChildren.size(); |
| 244 | int lenghtUpdated = updatedChildren.size(); |
| 245 | |
| 246 | int m; // index that reflects modifications on the actual model for this parent |
| 247 | int i; // index of the original children before update |
| 248 | int j; // index of the updated children |
| 249 | for (m = 0, i = 0, j = 0; (i < lenght) && (j < lenghtUpdated);) { |
| 250 | auto child = currentChildren[i]; |
| 251 | auto updatedChild = updatedChildren[j]; |
| 252 | |
| 253 | // same folder |
| 254 | auto sameFolderId = child->id == updatedChild->id; // and also same name |
| 255 | if (sameFolderId) { |
| 256 | // 1. check if child data needs to be udpated |
| 257 | if (child->getData() != updatedChild->getData()) { |
| 258 | auto modelIndexToUpdate = index(m, 0, parentModelIndex); |
| 259 | |
| 260 | child->setData(updatedChild->getData()); |
| 261 | |
| 262 | emit dataChanged(modelIndexToUpdate, modelIndexToUpdate); |
| 263 | } |
| 264 | |
| 265 | // 2. update children info |
| 266 | takeUpdatedChildrenInfo(child, index(m, 0, parentModelIndex), updatedChild); |
| 267 | |
| 268 | m++; |
| 269 | i++; |
| 270 | j++; |
| 271 | continue; |
| 272 | } |
| 273 | |
| 274 | auto childName = child->data(Name).toString(); |
| 275 | auto childUpdatedName = updatedChild->data(Name).toString(); |
| 276 | |
| 277 | // folder added |
| 278 | if (!naturalSortLessThanCI(childName, childUpdatedName)) { |
| 279 | beginInsertRows(parentModelIndex, m, m); |
| 280 | |
| 281 | parent->addChild(updatedChild, m); |
| 282 | updated->removeChild(updatedChild); |
| 283 | |
| 284 | endInsertRows(); |
| 285 | |
| 286 | m++; |
| 287 | j++; |
| 288 | continue; |
| 289 | } |
| 290 | |
| 291 | // folder removed |
| 292 | if (naturalSortLessThanCI(childName, childUpdatedName)) { |
| 293 | beginRemoveRows(parentModelIndex, m, m); |
| 294 | |
| 295 | delete parent->child(m); |
nothing calls this directly
no test coverage detected