From 25d852f07564883f5a225eb0e00e883cae30cbd2 Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Tue, 29 Dec 2020 12:42:13 +0100 Subject: Fix filtering for separators. --- src/modlistsortproxy.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/modlistsortproxy.cpp') diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 422fa044..daa1478d 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -592,23 +592,39 @@ void ModListSortProxy::setOptions( } } -bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex &parent) const +bool ModListSortProxy::filterAcceptsRow(int source_row, const QModelIndex &parent) const { if (m_Profile == nullptr) { return false; } - if (row >= static_cast(m_Profile->numMods())) { - log::warn("invalid row index: {}", row); + if (source_row >= static_cast(m_Profile->numMods())) { + log::warn("invalid row index: {}", source_row); return false; } - QModelIndex idx = sourceModel()->index(row, 0, parent); + QModelIndex idx = sourceModel()->index(source_row, 0, parent); if (!idx.isValid()) { log::debug("invalid mod index"); return false; } + + unsigned int index = ULONG_MAX; + { + bool ok = false; + index = idx.data(ModList::IndexRole).toInt(&ok); + if (!ok) { + index = ULONG_MAX; + } + } + if (sourceModel()->hasChildren(idx)) { + // we need to check the separator itself first + if (index < ModInfo::getNumMods() && ModInfo::getByIndex(index)->isSeparator()) { + if (filterMatchesMod(ModInfo::getByIndex(index), false)) { + return true; + } + } for (int i = 0; i < sourceModel()->rowCount(idx); ++i) { if (filterAcceptsRow(i, idx)) { return true; @@ -617,8 +633,7 @@ bool ModListSortProxy::filterAcceptsRow(int row, const QModelIndex &parent) cons return false; } else { - bool modEnabled = idx.sibling(row, 0).data(Qt::CheckStateRole).toInt() == Qt::Checked; - unsigned int index = idx.data(Qt::UserRole + 1).toInt(); + bool modEnabled = idx.sibling(source_row, 0).data(Qt::CheckStateRole).toInt() == Qt::Checked; return filterMatchesMod(ModInfo::getByIndex(index), modEnabled); } } -- cgit v1.3.1