From 864cab8c8afe9afc2a329d8849d2eee336a6898f Mon Sep 17 00:00:00 2001 From: Al Date: Sat, 12 Jan 2019 19:58:56 +0100 Subject: Fixed "check all for updates" not updating for the newly added mods. --- src/modlistsortproxy.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 1a00d764..bff26e8d 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -58,11 +58,18 @@ void ModListSortProxy::updateFilterActive() void ModListSortProxy::setCategoryFilter(const std::vector &categories) { + m_CategoryFilter = categories; + updateFilterActive(); + invalidate(); + + //For better performance we could refresh only if the filter is different or + //categories contains CATEGORY_SPECIAL_UPDATEAVAILABLE + /* if (categories != m_CategoryFilter) { m_CategoryFilter = categories; updateFilterActive(); invalidate(); - } + }*/ } void ModListSortProxy::setContentFilter(const std::vector &content) -- cgit v1.3.1 From 821ca7416683a8ac1e9906bb28a31265f67dbb98 Mon Sep 17 00:00:00 2001 From: Al Date: Sat, 12 Jan 2019 20:24:10 +0100 Subject: Avoid refreshes unless it's specifically the update filter. --- src/modlistsortproxy.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index bff26e8d..94139715 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -58,18 +58,12 @@ void ModListSortProxy::updateFilterActive() void ModListSortProxy::setCategoryFilter(const std::vector &categories) { - m_CategoryFilter = categories; - updateFilterActive(); - invalidate(); - - //For better performance we could refresh only if the filter is different or - //categories contains CATEGORY_SPECIAL_UPDATEAVAILABLE - /* - if (categories != m_CategoryFilter) { + //avoid refreshing the filter unless we are checking all mods for update. + if (categories != m_CategoryFilter || categories.at(0) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { m_CategoryFilter = categories; updateFilterActive(); invalidate(); - }*/ + } } void ModListSortProxy::setContentFilter(const std::vector &content) -- cgit v1.3.1 From 5efba39f86dd1bcd542f53d0839de521ec052fb5 Mon Sep 17 00:00:00 2001 From: Al Date: Sun, 13 Jan 2019 13:42:56 +0100 Subject: Fixed invalid vector access on modInfoDialog closing. --- src/modlistsortproxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 94139715..35e496a0 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -59,7 +59,7 @@ void ModListSortProxy::updateFilterActive() void ModListSortProxy::setCategoryFilter(const std::vector &categories) { //avoid refreshing the filter unless we are checking all mods for update. - if (categories != m_CategoryFilter || categories.at(0) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE) { + if (categories != m_CategoryFilter || (!categories.empty() && categories.at(0) == CategoryFactory::CATEGORY_SPECIAL_UPDATEAVAILABLE)) { m_CategoryFilter = categories; updateFilterActive(); invalidate(); -- cgit v1.3.1 From 0d04ba18737385395d6ebcdfe49fb31bcb539038 Mon Sep 17 00:00:00 2001 From: Al Date: Fri, 18 Jan 2019 01:34:18 +0100 Subject: Added OR and AND based search to modlist and pluginlist. A space now means AND and "OR ; | ||" mean OR. OR always wins. --- src/modlistsortproxy.cpp | 109 ++++++++++++++++++++++++++++---------------- src/pluginlistsortproxy.cpp | 35 +++++++++++++- 2 files changed, 103 insertions(+), 41 deletions(-) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 35e496a0..464f9104 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -357,59 +357,90 @@ bool ModListSortProxy::filterMatchesModOr(ModInfo::Ptr info, bool enabled) const bool ModListSortProxy::filterMatchesMod(ModInfo::Ptr info, bool enabled) const { - bool display = true; if (!m_CurrentFilter.isEmpty()) { - display = false; + bool display = false; + QString filterCopy = QString(m_CurrentFilter); + filterCopy.replace("||", ";").replace("OR", ";").replace("|", ";"); + QStringList ORList = filterCopy.split(";", QString::SkipEmptyParts); + + bool segmentGood = true; + + //split in ORSegments that internally use AND logic + for (auto& ORSegment : ORList) { + QStringList ANDKeywords = ORSegment.split(" ", QString::SkipEmptyParts); + segmentGood = true; + bool foundKeyword = false; + + //check each word in the segment for match, each word needs to be matched but it doesn't matter where. + for (auto& currentKeyword : ANDKeywords) { + foundKeyword = false; + + //search keyword in name + if (m_EnabledColumns[ModList::COL_NAME] && + info->name().contains(currentKeyword, Qt::CaseInsensitive)) { + foundKeyword = true; + } - // Search by name - if (!display && - m_EnabledColumns[ModList::COL_NAME] && - info->name().contains(m_CurrentFilter, Qt::CaseInsensitive)) { - display = true; - } + // Search by notes + if (!foundKeyword && + m_EnabledColumns[ModList::COL_NOTES] && + info->comments().contains(currentKeyword, Qt::CaseInsensitive)) { + foundKeyword = true; + } - // Search by notes - if (!display && - m_EnabledColumns[ModList::COL_NOTES] && - info->comments().contains(m_CurrentFilter, Qt::CaseInsensitive)) { - display = true; - } + // Search by categories + if (!foundKeyword && + m_EnabledColumns[ModList::COL_CATEGORY]) { + for (auto category : info->categories()) { + if (category.contains(currentKeyword, Qt::CaseInsensitive)) { + foundKeyword = true; + break; + } + } + } - // Search by Nexus ID - if (!display && - m_EnabledColumns[ModList::COL_MODID]) { - bool ok; - int filterID = m_CurrentFilter.toInt(&ok); - if (ok) { - int modID = info->getNexusID(); - while (modID > 0) { - if (modID == filterID) { - display = true; - break; + // Search by Nexus ID + if (!foundKeyword && + m_EnabledColumns[ModList::COL_MODID]) { + bool ok; + int filterID = currentKeyword.toInt(&ok); + if (ok) { + int modID = info->getNexusID(); + while (modID > 0) { + if (modID == filterID) { + foundKeyword = true; + break; + } + modID = (int)(modID / 10); + } } - modID = (int)(modID / 10); } - } - } - // Search by categories - if (!display && - m_EnabledColumns[ModList::COL_CATEGORY]) { - for (auto category : info->categories()) { - if (category.contains(m_CurrentFilter, Qt::CaseInsensitive)) { - display = true; + if (!foundKeyword) { + //currentKeword is missing from everything, AND fails and we need to check next ORsegment + segmentGood = false; break; } + + }//for ANDKeywords loop + + if (segmentGood) { + //the last AND loop didn't break so the ORSegments is true so mod matches filter + display = true; + break; } + + }//for ORList loop + + if (!display) { + return false; } - } - if (!display) { - return false; - } + }//if (!m_CurrentFilter.isEmpty()) if (m_FilterMode == FILTER_AND) { return filterMatchesModAnd(info, enabled); - } else { + } + else { return filterMatchesModOr(info, enabled); } } diff --git a/src/pluginlistsortproxy.cpp b/src/pluginlistsortproxy.cpp index 1e131c4d..3d13798e 100644 --- a/src/pluginlistsortproxy.cpp +++ b/src/pluginlistsortproxy.cpp @@ -139,7 +139,38 @@ bool PluginListSortProxy::dropMimeData(const QMimeData *data, Qt::DropAction act bool PluginListSortProxy::filterMatchesPlugin(const QString &plugin) const { - return m_CurrentFilter.isEmpty() || - plugin.contains(m_CurrentFilter, Qt::CaseInsensitive); + if (!m_CurrentFilter.isEmpty()) { + + bool display = false; + QString filterCopy = QString(m_CurrentFilter); + filterCopy.replace("||", ";").replace("OR", ";").replace("|", ";"); + QStringList ORList = filterCopy.split(";", QString::SkipEmptyParts); + + bool segmentGood = true; + + //split in ORSegments that internally use AND logic + for (auto& ORSegment : ORList) { + QStringList ANDKeywords = ORSegment.split(" ", QString::SkipEmptyParts); + segmentGood = true; + + //check each word in the segment for match, each word needs to be matched but it doesn't matter where. + for (auto& currentKeyword : ANDKeywords) { + if (!plugin.contains(currentKeyword, Qt::CaseInsensitive)) { + segmentGood = false; + break; + } + } + + if (segmentGood) { + //the last AND loop didn't break so the ORSegments is true so mod matches filter + return true; + } + + }//for ORList loop + + return false; + } + else + return true; } -- cgit v1.3.1