From 355e5e24da45c69ffa92bfa76c8c40439a107e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 8 Jan 2020 21:12:45 +0100 Subject: [PATCH] GH-2819 mod list filter now also looks at descriptions and authors --- api/logic/minecraft/mod/ModFolderModel.h | 4 ++++ application/pages/instance/ModFolderPage.cpp | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/api/logic/minecraft/mod/ModFolderModel.h b/api/logic/minecraft/mod/ModFolderModel.h index 8394e4053..03c584a97 100644 --- a/api/logic/minecraft/mod/ModFolderModel.h +++ b/api/logic/minecraft/mod/ModFolderModel.h @@ -85,6 +85,10 @@ public: { return mods[index]; } + const Mod &at(size_t index) const + { + return mods.at(index); + } /// Reloads the mod list and returns true if the list changed. bool update(); diff --git a/application/pages/instance/ModFolderPage.cpp b/application/pages/instance/ModFolderPage.cpp index d449f8bfe..ec4bf3c96 100644 --- a/application/pages/instance/ModFolderPage.cpp +++ b/application/pages/instance/ModFolderPage.cpp @@ -51,6 +51,26 @@ public: } protected: + bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override { + ModFolderModel *model = qobject_cast(sourceModel()); + if(!model) { + return false; + } + const auto &mod = model->at(source_row); + if(mod.name().contains(filterRegExp())) { + return true; + } + if(mod.description().contains(filterRegExp())) { + return true; + } + for(auto & author: mod.authors()) { + if (author.contains(filterRegExp())) { + return true; + } + } + return false; + } + bool lessThan(const QModelIndex & source_left, const QModelIndex & source_right) const override { ModFolderModel *model = qobject_cast(sourceModel());