Skip to content

Commit

Permalink
GH-2819 mod list filter now also looks at descriptions and authors
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed Jan 8, 2020
1 parent 8bdff97 commit 355e5e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/logic/minecraft/mod/ModFolderModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class MULTIMC_LOGIC_EXPORT ModFolderModel : public QAbstractListModel
{
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();
Expand Down
20 changes: 20 additions & 0 deletions application/pages/instance/ModFolderPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ class ModSortProxy : public QSortFilterProxyModel
}

protected:
bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const override {
ModFolderModel *model = qobject_cast<ModFolderModel *>(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<ModFolderModel *>(sourceModel());
Expand Down

0 comments on commit 355e5e2

Please sign in to comment.