From 0c485304c199841ce8a77f0ba7c5b4c346a3e8a8 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Wed, 28 Oct 2020 20:18:47 +0100 Subject: Fix advanced conflicts tab archive orders. Use the the existing sorting of the alternatives vector instead of relying on priority (archives don't follow priority). --- src/modinfodialogconflicts.cpp | 133 +++++++++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 52 deletions(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 06f0a31c..1a813f7b 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -886,82 +886,111 @@ std::optional AdvancedConflictsTab::createItem( std::wstring before, after; + auto currOrigin = m_tab->origin(); + if (!alternatives.empty()) { const bool showAllAlts = ui->conflictsAdvancedShowAll->isChecked(); int beforePrio = 0; int afterPrio = std::numeric_limits::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 + } + } + else { + // only add nearest, which is the last element of alternatives + const auto& altOrigin = ds.getOriginByID((alternatives.end()-1)->first); + + before += altOrigin.getName(); + } + + } + else { + // current mod is one of the alternatives, find it's 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()) { + + if (showAllAlts) { + // fills 'before' and 'after' with all the alternatives that come + // before and after the current mod, trusting the alternatives vector to be + // alredy 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 (!after.empty()) { + after += L", "; + } + + after += altOrigin.getName(); + } + } + + // also add the active winner origin (the one outsiede alternatives) to 'after' if (!after.empty()) { after += L", "; } + after += ds.getOriginByID(fileOrigin).getName(); - after += altOrigin.getName(); - } - } else { - // keep track of the nearest mods that come before and after this one - // in terms of priority - - if (altOrigin.getPriority() < m_tab->origin()->getPriority()) { - // the alternative has a lower priority than this mod - 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 { + // only show nearest origins - if (altOrigin.getPriority() > m_tab->origin()->getPriority()) { - // the alternative has a higher priority than this mod + // before + if (currModIter > alternatives.begin()) { + auto previousOrigId = (currModIter-1)->first; + before += ds.getOriginByID(previousOrigId).getName(); + } - 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 + 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 - // 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()) { - if (!after.empty()) { - after += L", "; + after += ds.getOriginByID(fileOrigin).getName(); + } + } - after += realOrigin.getName(); + } + else { + log::error("Mod {} not found in the list of origins for file {}", currOrigin->getName(), fileName); + return {}; } } } -- cgit v1.3.1 From 2833f8d61b56a3f4ed6b2a8fafeb679033e6989e Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Fri, 30 Oct 2020 02:15:34 +0100 Subject: Make advanced conflicts tab use italic if current mod file is from archive, instead of using the status of the winning version. --- src/modinfodialogconflicts.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 1a813f7b..751a829e 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -887,6 +887,7 @@ std::optional AdvancedConflictsTab::createItem( std::wstring before, after; auto currOrigin = m_tab->origin(); + bool isCurrOrigArchive = archive; if (!alternatives.empty()) { const bool showAllAlts = ui->conflictsAdvancedShowAll->isChecked(); @@ -927,6 +928,7 @@ std::optional AdvancedConflictsTab::createItem( }); if (currModIter != alternatives.end()) { + isCurrOrigArchive = currModIter->second.first.size() > 0; if (showAllAlts) { // fills 'before' and 'after' with all the alternatives that come @@ -1010,5 +1012,5 @@ std::optional 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); } -- cgit v1.3.1 From db3f257d078eab7b2686f1b49b2213221c9961d6 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Sat, 31 Oct 2020 16:20:12 +0100 Subject: use alternatives.back() instead of iterator shenanigans. --- src/modinfodialogconflicts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 751a829e..9df88421 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -911,7 +911,7 @@ std::optional AdvancedConflictsTab::createItem( } else { // only add nearest, which is the last element of alternatives - const auto& altOrigin = ds.getOriginByID((alternatives.end()-1)->first); + const auto& altOrigin = ds.getOriginByID(alternatives.back().first); before += altOrigin.getName(); } -- cgit v1.3.1 From 6f77c479077e250923fb98bbc56a11ed18987756 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Sat, 31 Oct 2020 16:21:37 +0100 Subject: Fix typos in comments --- src/modinfodialogconflicts.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 9df88421..9dd98751 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -918,7 +918,7 @@ std::optional AdvancedConflictsTab::createItem( } else { - // current mod is one of the alternatives, find it's position + // current mod is one of the alternatives, find its position auto currOrgId = currOrigin->getID(); @@ -933,7 +933,7 @@ std::optional AdvancedConflictsTab::createItem( if (showAllAlts) { // fills 'before' and 'after' with all the alternatives that come // before and after the current mod, trusting the alternatives vector to be - // alredy sorted correctly + // already sorted correctly for (auto iter = alternatives.begin(); iter != alternatives.end(); iter++) { @@ -959,7 +959,7 @@ std::optional AdvancedConflictsTab::createItem( } } - // also add the active winner origin (the one outsiede alternatives) to 'after' + // also add the active winner origin (the one outside alternatives) to 'after' if (!after.empty()) { after += L", "; } -- cgit v1.3.1 From 89d3311aca63ed5d0aa2345f630eb10003bdd9cb Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Sat, 31 Oct 2020 16:24:43 +0100 Subject: Prefer early return in case of error. --- src/modinfodialogconflicts.cpp | 96 +++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 49 deletions(-) (limited to 'src/modinfodialogconflicts.cpp') diff --git a/src/modinfodialogconflicts.cpp b/src/modinfodialogconflicts.cpp index 9dd98751..79ce6ade 100644 --- a/src/modinfodialogconflicts.cpp +++ b/src/modinfodialogconflicts.cpp @@ -927,72 +927,70 @@ std::optional AdvancedConflictsTab::createItem( return currOrgId == alt.first; }); - if (currModIter != alternatives.end()) { - isCurrOrigArchive = currModIter->second.first.size() > 0; + 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 - 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++) { - for (auto iter = alternatives.begin(); iter != alternatives.end(); iter++) { - - const auto& altOrigin = ds.getOriginByID(iter->first); + const auto& altOrigin = ds.getOriginByID(iter->first); - if (iter < currModIter) { - // mod comes before current + if (iter < currModIter) { + // mod comes before current - if (!before.empty()) { - before += L", "; - } - - before += altOrigin.getName(); + if (!before.empty()) { + before += L", "; } - else if (iter > currModIter) { - // mod comes after current - if (!after.empty()) { - after += L", "; - } + before += altOrigin.getName(); + } + else if (iter > currModIter) { + // mod comes after current - after += altOrigin.getName(); + if (!after.empty()) { + after += L", "; } - } - // also add the active winner origin (the one outside alternatives) to 'after' - if (!after.empty()) { - after += L", "; + after += altOrigin.getName(); } - after += ds.getOriginByID(fileOrigin).getName(); - + } + // also add the active winner origin (the one outside alternatives) to 'after' + if (!after.empty()) { + after += L", "; } - else { - // only show nearest origins + after += ds.getOriginByID(fileOrigin).getName(); - // 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 + } + else { + // only show nearest origins - after += ds.getOriginByID(fileOrigin).getName(); - } - + // before + if (currModIter > alternatives.begin()) { + auto previousOrigId = (currModIter-1)->first; + before += ds.getOriginByID(previousOrigId).getName(); } - } - else { - log::error("Mod {} not found in the list of origins for file {}", currOrigin->getName(), fileName); - return {}; + // 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(); + } + } } } -- cgit v1.3.1