diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/filterwidget.cpp | 34 | ||||
| -rw-r--r-- | src/filterwidget.h | 2 | ||||
| -rw-r--r-- | src/modinfodialog.cpp | 13 |
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; |
