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/pluginlistsortproxy.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/pluginlistsortproxy.cpp') 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