MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / loadList

Method loadList

launcher/InstanceList.cpp:461–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

459}
460
461InstanceList::InstListError InstanceList::loadList()
462{
463 auto existingIds = getIdMapping(m_instances);
464
465 QList<InstancePtr> newList;
466
467 for (auto& id : discoverInstances()) {
468 if (existingIds.contains(id)) {
469 auto instPair = existingIds[id];
470 existingIds.remove(id);
471 qDebug() << "Should keep and soft-reload" << id;
472 } else {
473 InstancePtr instPtr = loadInstance(id);
474 if (instPtr) {
475 newList.append(instPtr);
476 }
477 }
478 }
479
480 // TODO: looks like a general algorithm with a few specifics inserted. Do something about it.
481 if (!existingIds.isEmpty()) {
482 // get the list of removed instances and sort it by their original index, from last to first
483 auto deadList = existingIds.values();
484 auto orderSortPredicate = [](const InstanceLocator& a, const InstanceLocator& b) -> bool { return a.second > b.second; };
485 std::sort(deadList.begin(), deadList.end(), orderSortPredicate);
486 // remove the contiguous ranges of rows
487 int front_bookmark = -1;
488 int back_bookmark = -1;
489 int currentItem = -1;
490 auto removeNow = [&]() {
491 beginRemoveRows(QModelIndex(), front_bookmark, back_bookmark);
492 m_instances.erase(m_instances.begin() + front_bookmark, m_instances.begin() + back_bookmark + 1);
493 endRemoveRows();
494 front_bookmark = -1;
495 back_bookmark = currentItem;
496 };
497 for (auto& removedItem : deadList) {
498 auto instPtr = removedItem.first;
499 instPtr->invalidate();
500 currentItem = removedItem.second;
501 if (back_bookmark == -1) {
502 // no bookmark yet
503 back_bookmark = currentItem;
504 } else if (currentItem == front_bookmark - 1) {
505 // part of contiguous sequence, continue
506 } else {
507 // seam between previous and current item
508 removeNow();
509 }
510 front_bookmark = currentItem;
511 }
512 if (back_bookmark != -1) {
513 removeNow();
514 }
515 }
516 if (newList.size()) {
517 add(newList);
518 }

Callers 1

ApplicationMethod · 0.45

Calls 8

getIdMappingFunction · 0.85
QModelIndexClass · 0.85
appendMethod · 0.80
invalidateMethod · 0.80
containsMethod · 0.45
removeMethod · 0.45
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected