diff options
Diffstat (limited to 'src/modinfodialogconflicts.cpp')
| -rw-r--r-- | src/modinfodialogconflicts.cpp | 142 |
1 files changed, 89 insertions, 53 deletions
diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index c52f2cb6..377a5638 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -559,12 +559,18 @@ GeneralConflictsTab::GeneralConflictsTab( m_filterOverwrite.setEdit(ui->overwriteLineEdit); m_filterOverwrite.setList(ui->overwriteTree); + m_filterOverwrite.setUseSourceSort(true); + m_filterOverwrite.setUpdateDelay(false); m_filterOverwritten.setEdit(ui->overwrittenLineEdit); m_filterOverwritten.setList(ui->overwrittenTree); + m_filterOverwritten.setUseSourceSort(true); + m_filterOverwritten.setUpdateDelay(false); m_filterNoConflicts.setEdit(ui->noConflictLineEdit); m_filterNoConflicts.setList(ui->noConflictTree); + m_filterNoConflicts.setUseSourceSort(true); + m_filterNoConflicts.setUpdateDelay(false); QObject::connect( ui->overwriteTree, &QTreeView::doubleClicked, @@ -886,9 +892,10 @@ AdvancedConflictsTab::AdvancedConflictsTab( m_tab(tab), ui(pui), m_core(oc), m_model(new AdvancedConflictListModel(ui->conflictsAdvancedList)) { - m_filter.setEdit(ui->conflictsAdvancedFilter); m_filter.setList(ui->conflictsAdvancedList); + m_filter.setUseSourceSort(true); + m_filter.setUpdateDelay(false); // left-elide the overwrites column so that the nearest are visible ui->conflictsAdvancedList->setItemDelegateForColumn( @@ -983,82 +990,111 @@ std::optional<ConflictItem> AdvancedConflictsTab::createItem( std::wstring before, after; + auto currOrigin = m_tab->origin(); + bool isCurrOrigArchive = archive; + if (!alternatives.empty()) { const bool showAllAlts = ui->conflictsAdvancedShowAll->isChecked(); int beforePrio = 0; int afterPrio = std::numeric_limits<int>::max(); - for (const auto& alt : alternatives) - { - const auto& altOrigin = ds.getOriginByID(alt.first); - + if (currOrigin->getID() == fileOrigin) { + // current origin is the active winner, all alternatives go in 'before' + if (showAllAlts) { - // fills 'before' and 'after' with all the alternatives that come - // before and after this mod in terms of priority - - if (altOrigin.getPriority() < m_tab->origin()->getPriority()) { - // add all the mods having a lower priority than this one + for (const auto& alt : alternatives) + { + const auto& altOrigin = ds.getOriginByID(alt.first); if (!before.empty()) { before += L", "; } before += altOrigin.getName(); - } else if (altOrigin.getPriority() > m_tab->origin()->getPriority()) { - // add all the mods having a higher priority than this one - if (!after.empty()) { - after += L", "; - } - - after += altOrigin.getName(); } - } else { - // keep track of the nearest mods that come before and after this one - // in terms of priority + } + else { + // only add nearest, which is the last element of alternatives + const auto& altOrigin = ds.getOriginByID(alternatives.back().first); - if (altOrigin.getPriority() < m_tab->origin()->getPriority()) { - // the alternative has a lower priority than this mod + before += altOrigin.getName(); + } - if (altOrigin.getPriority() > beforePrio) { - // the alternative has a higher priority and therefore is closer - // to this mod, use it - before = altOrigin.getName(); - beforePrio = altOrigin.getPriority(); + } + else { + // current mod is one of the alternatives, find its position + + auto currOrgId = currOrigin->getID(); + + auto currModIter = std::find_if(alternatives.begin(), alternatives.end(), + [&currOrgId](auto const& alt) { + return currOrgId == alt.first; + }); + + if (currModIter == alternatives.end()) { + log::error("Mod {} not found in the list of origins for file {}", currOrigin->getName(), fileName); + return {}; + } + + isCurrOrigArchive = currModIter->second.first.size() > 0; + + if (showAllAlts) { + // fills 'before' and 'after' with all the alternatives that come + // before and after the current mod, trusting the alternatives vector to be + // already sorted correctly + + for (auto iter = alternatives.begin(); iter != alternatives.end(); iter++) { + + const auto& altOrigin = ds.getOriginByID(iter->first); + + if (iter < currModIter) { + // mod comes before current + + if (!before.empty()) { + before += L", "; + } + + before += altOrigin.getName(); } - } + else if (iter > currModIter) { + // mod comes after current - if (altOrigin.getPriority() > m_tab->origin()->getPriority()) { - // the alternative has a higher priority than this mod + if (!after.empty()) { + after += L", "; + } - if (altOrigin.getPriority() < afterPrio) { - // the alternative has a lower priority and there is closer - // to this mod, use it - after = altOrigin.getName(); - afterPrio = altOrigin.getPriority(); + after += altOrigin.getName(); } } - } - } - - // the primary origin is never in the list of alternatives, so it has to - // be handled separately - // - // if 'after' is not empty, it means at least one alternative with a higher - // priority than this mod was found; if the user only wants to see the - // nearest mods, it's not worth checking for the primary origin because it - // will always have a higher priority than the alternatives (or it wouldn't - // be the primary) - if (after.empty() || showAllAlts) { - const FilesOrigin& realOrigin = ds.getOriginByID(fileOrigin); - // if no mods overwrite this file, the primary origin is the same as this - // mod, so ignore that - if (realOrigin.getID() != m_tab->origin()->getID()) { + // also add the active winner origin (the one outside alternatives) to 'after' if (!after.empty()) { after += L", "; } + after += ds.getOriginByID(fileOrigin).getName(); - after += realOrigin.getName(); + + } + else { + // only show nearest origins + + // before + if (currModIter > alternatives.begin()) { + auto previousOrigId = (currModIter-1)->first; + before += ds.getOriginByID(previousOrigId).getName(); + } + + // after + if (currModIter < (alternatives.end() - 1)) { + auto followingOrigId = (currModIter + 1)->first; + after += ds.getOriginByID(followingOrigId).getName(); + } + else { + // current mod is last of alternatives, so closest to the active winner + + after += ds.getOriginByID(fileOrigin).getName(); + } + } } } @@ -1078,5 +1114,5 @@ std::optional<ConflictItem> AdvancedConflictsTab::createItem( return ConflictItem( std::move(beforeQS), std::move(relativeName), std::move(afterQS), - index, std::move(fileName), hasAlts, QString(), archive); + index, std::move(fileName), hasAlts, QString(), isCurrOrigArchive); } |
