MCPcopy Create free account
hub / github.com/YACReader/yacreader / takeUpdatedChildrenInfo

Method takeUpdatedChildrenInfo

YACReaderLibrary/db/folder_model.cpp:238–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238void 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);

Callers

nothing calls this directly

Calls 9

naturalSortLessThanCIFunction · 0.85
toStringMethod · 0.80
addChildMethod · 0.80
childrenMethod · 0.45
getDataMethod · 0.45
setDataMethod · 0.45
dataMethod · 0.45
removeChildMethod · 0.45
childMethod · 0.45

Tested by

no test coverage detected