GH-2819 mod list filter now also looks at descriptions and authors

This commit is contained in:
Petr Mrázek 2020-01-08 21:12:45 +01:00
parent 8bdff97ac0
commit 355e5e24da
2 changed files with 24 additions and 0 deletions

View File

@ -85,6 +85,10 @@ public:
{ {
return mods[index]; 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. /// Reloads the mod list and returns true if the list changed.
bool update(); bool update();

View File

@ -51,6 +51,26 @@ public:
} }
protected: 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 bool lessThan(const QModelIndex & source_left, const QModelIndex & source_right) const override
{ {
ModFolderModel *model = qobject_cast<ModFolderModel *>(sourceModel()); ModFolderModel *model = qobject_cast<ModFolderModel *>(sourceModel());