summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-05-31 10:54:36 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-05-31 11:54:31 -0400
commit8efab8bf129b6f9928f478a429e20cf018e5e373 (patch)
tree700b51d7d4030c145b535c2bc70b062f41491b58
parent98b3be3e9bbca73640842f6dadaa159dcec04f7b (diff)
FilterWidget takes a predicate to match strings
copied the logic from modlistsortproxy so the basic boolean syntax in filters works
-rw-r--r--src/filterwidget.cpp34
-rw-r--r--src/filterwidget.h2
-rw-r--r--src/modinfodialog.cpp13
3 files changed, 42 insertions, 7 deletions
diff --git a/src/filterwidget.cpp b/src/filterwidget.cpp
index 7c47980e..16a46b0e 100644
--- a/src/filterwidget.cpp
+++ b/src/filterwidget.cpp
@@ -30,9 +30,39 @@ void FilterWidget::clear()
m_edit->clear();
}
-bool FilterWidget::matches(const QString& s) const
+bool FilterWidget::matches(std::function<bool (const QString& what)> pred) const
{
- return s.contains(m_text);
+ const QStringList ORList = [&] {
+ QString filterCopy = QString(m_text);
+ filterCopy.replace("||", ";").replace("OR", ";").replace("|", ";");
+ return filterCopy.split(";", QString::SkipEmptyParts);
+ }();
+
+ if (ORList.isEmpty() || !pred) {
+ return true;
+ }
+
+ // split in ORSegments that internally use AND logic
+ for (auto& ORSegment : ORList) {
+ QStringList ANDKeywords = ORSegment.split(" ", QString::SkipEmptyParts);
+ bool 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 (!pred(currentKeyword)) {
+ segmentGood = false;
+ }
+ }
+
+ if (segmentGood) {
+ // the last AND loop didn't break so the ORSegments is true so mod
+ // matches filter
+ return true;
+ }
+ }
+
+ return false;
}
void FilterWidget::unhook()
diff --git a/src/filterwidget.h b/src/filterwidget.h
index ca731dc1..4fee5983 100644
--- a/src/filterwidget.h
+++ b/src/filterwidget.h
@@ -13,7 +13,7 @@ public:
void set(QLineEdit* edit);
void clear();
- bool matches(const QString& s) const;
+ bool matches(std::function<bool (const QString& what)> pred) const;
private:
QLineEdit* m_edit;
diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp
index 0f18033a..4852150f 100644
--- a/src/modinfodialog.cpp
+++ b/src/modinfodialog.cpp
@@ -874,10 +874,15 @@ QTreeWidgetItem* ModInfoDialog::createAdvancedConflictItem(
}
}
- if (!m_advancedConflictFilter.matches(before) &&
- !m_advancedConflictFilter.matches(relativeName) &&
- !m_advancedConflictFilter.matches(after)) {
- return nullptr;
+ bool matched = m_advancedConflictFilter.matches([&](auto&& what) {
+ return
+ before.contains(what, Qt::CaseInsensitive) ||
+ relativeName.contains(what, Qt::CaseInsensitive) ||
+ after.contains(what, Qt::CaseInsensitive);
+ });
+
+ if (!matched) {
+ return nullptr;
}
QTreeWidgetItem* item = new QTreeWidgetItem;